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

loss functions should infer dtype from predictions #13640

Closed
pavithrasv opened this issue Dec 18, 2019 · 2 comments
Closed

loss functions should infer dtype from predictions #13640

pavithrasv opened this issue Dec 18, 2019 · 2 comments

Comments

@pavithrasv
Copy link
Contributor

Please make sure that this is a Bug or a Feature Request and provide all applicable information asked by the template.
If your issue is an implementation question, please ask your question on StackOverflow or on the Keras Slack channel instead of opening a GitHub issue.

System information

  • Have I written custom code (as opposed to using example directory):
  • OS Platform and Distribution (e.g., Linux Ubuntu 16.04):
  • TensorFlow backend (yes / no):
  • TensorFlow version:
  • Keras version:
  • Python version:
  • CUDA/cuDNN version:
  • GPU model and memory:

You can obtain the TensorFlow version with:
python -c "import tensorflow as tf; print(tf.GIT_VERSION, tf.VERSION)"
You can obtain the Keras version with:
python -c 'import keras as k; print(k.version)'

Describe the current behavior
def mean_squared_error(y_true, y_pred):
if not K.is_tensor(y_pred):
y_pred = K.constant(y_pred)
y_true = K.cast(y_true, y_pred.dtype)
return K.mean(K.square(y_pred - y_true), axis=-1)

y_pred is always converted to float32 because of K.constant call.

Describe the expected behavior
pass dtype to the K.constant call

Code to reproduce the issue
Provide a reproducible test case that is the bare minimum necessary to generate the problem.

Other info / logs
Include any logs or source code that would be helpful to diagnose the problem. If including tracebacks, please include the full traceback. Large logs and files should be attached.

@pavithrasv pavithrasv self-assigned this Dec 18, 2019
@pavithrasv pavithrasv changed the title loss functions converting predictions to tensor should infer dtype from predictions loss functions should infer dtype from predictions Dec 18, 2019
@sushreebarsa sushreebarsa self-assigned this Jul 28, 2021
@sushreebarsa
Copy link
Contributor

@pavithrasv Could you please refer to this link and let us know if it helps ?
In order to expedite the trouble-shooting process, please provide a code snippet to reproduce the issue reported here. Thanks!

@sushreebarsa
Copy link
Contributor

Closing this issue due to lack of recent activity & assuming this issue as resolved .Please feel free to reopen if you still have concern .Thanks!

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

No branches or pull requests

4 participants