Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type error during fitting #5

Open
nfurth opened this issue Mar 2, 2022 · 3 comments
Open

Type error during fitting #5

nfurth opened this issue Mar 2, 2022 · 3 comments

Comments

@nfurth
Copy link

nfurth commented Mar 2, 2022

When I fit the model, I received this 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'.
which can be traced back to the warning TypeError: not all arguments converted during string formatting during the train generator,
is there any fix for this?

Thank you

@Luca96
Copy link
Owner

Luca96 commented Mar 3, 2022

Hi, without the full traceback is a little bit difficult to understand where the error is, could you provide it?

@nfurth
Copy link
Author

nfurth commented Mar 7, 2022

/usr/local/lib/python3.7/dist-packages/ipykernel_launcher.py:13: UserWarning: Model.fit_generator is deprecated and will be removed in a future version. Please use Model.fit, which supports generators.
del sys.path[0]
Epoch 1/12

TypeError Traceback (most recent call last)
in ()
11 shuffle=True,
12 callbacks=[checkpoint],
---> 13 verbose=1
14 )

2 frames
/usr/local/lib/python3.7/dist-packages/tensorflow/python/framework/func_graph.py in autograph_handler(*args, **kwargs)
1145 except Exception as e: # pylint:disable=broad-except
1146 if hasattr(e, "ag_error_metadata"):
-> 1147 raise e.ag_error_metadata.to_exception(e)
1148 else:
1149 raise

TypeError: in user code:

File "/usr/local/lib/python3.7/dist-packages/keras/engine/training.py", line 1021, in train_function  *
    return step_function(self, iterator)
File "/usr/local/lib/python3.7/dist-packages/keras/engine/training.py", line 1010, in step_function  **
    outputs = model.distribute_strategy.run(run_step, args=(data,))
File "/usr/local/lib/python3.7/dist-packages/keras/engine/training.py", line 1000, in run_step  **
    outputs = model.train_step(data)
File "/usr/local/lib/python3.7/dist-packages/keras/engine/training.py", line 860, in train_step
    loss = self.compute_loss(x, y, y_pred, sample_weight)
File "/usr/local/lib/python3.7/dist-packages/keras/engine/training.py", line 919, in compute_loss
    y, y_pred, sample_weight, regularization_losses=self.losses)
File "/usr/local/lib/python3.7/dist-packages/keras/engine/compile_utils.py", line 201, in __call__
    loss_value = loss_obj(y_t, y_p, sample_weight=sw)
File "/usr/local/lib/python3.7/dist-packages/keras/losses.py", line 141, in __call__
    losses = call_fn(y_true, y_pred)
File "/usr/local/lib/python3.7/dist-packages/keras/losses.py", line 245, in call  **
    return ag_fn(y_true, y_pred, **self._fn_kwargs)
File "/usr/local/lib/python3.7/dist-packages/keras/losses.py", line 2199, in cosine_similarity
    y_true = tf.linalg.l2_normalize(y_true, axis=axis)

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 are the library versions I am using:
OpenCV 4.1.2
Keras 2.8.0
Pandas 1.3.5
Numpy 1.21.5

If it helps a link to the notebook https://colab.research.google.com/drive/1eFgQqA6KC1acSCXbzc8ru5ffea5Oim7Q#scrollTo=dlfjYC2DrXhI

Thank you

@Luca96
Copy link
Owner

Luca96 commented Mar 7, 2022

Hi, you can try a couple of things:

  • Change the loss function to binary_crossentropy.
  • And/or replace all the keras related imports with tensorflow.keras, instead.

Let me know if the issue persists

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants