I'm running TF 2.7 (I need it in that version). I'm trying to use the Keras.losses.CosineSimilarity
loss function to train a Keras model (Stellargraph GCN model). But everytime a strange error stops the training process. I can confirm that it is related to using CosineSimilarity.
The error:=
TypeError: Expected int64 passed to parameter 'y' of op 'Maximum', got 1e-12 of type 'float' instead. Error: Expected int64, but got 1e-12 of type 'float'.
Here is the code :=
from tensorflow.keras import layers, optimizers, losses, metrics, Model
from tensorflow.keras.metrics import Precision
from tensorflow.keras.callbacks import EarlyStopping
model = Model(inputs=x_inp, outputs=predictions)
similarity = losses.CosineSimilarity()
model.compile(
optimizer=optimizers.Adam(learning_rate = 0.001),
loss = similarity,
metrics= [Precision],
)
es_callback = EarlyStopping(monitor="val_F1", patience=50, restore_best_weights=True)
history = model.fit(
train_gen,
epochs=500,
validation_data=val_gen,
verbose=2,
shuffle=False,
callbacks=[es_callback],
)
I can confirm that all of my training & validation data are of the integer type.
similarity = losses.CosineSimilarity()
withsimilarity = losses.MeanSquaredError()
it works fine?