Home > database >  Tensorflow-Keras vector normalise output layer
Tensorflow-Keras vector normalise output layer

Time:08-10

My model outputs a direction vector in 3d space so I do not care about the magnitude of the vector. How can I vector normalise the output layer so that the loss function doesn't care about the magnitude either?

Model:

model = keras.Sequential(
    [
        keras.Input(shape=(17,), dtype=np.float64),
        layers.Dense(9, activation="relu"),
        layers.Dense(9, activation="relu"),
        layers.Dense(9, activation="relu"),
        layers.Dense(9, activation="relu"),
        layers.Dense(3) # output layer I want to vector normalise
    ]
)

Alternatively would it be possible to specify for the loss function to only consider the angle between the vectors as loss?

Thank you.

CodePudding user response:

I found what I was looking for:

tf.keras.losses.CosineSimilarity
  • Related