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

Fix for #7225: CIFAR-10 eval fails with error TypeError: Input 'predictions' of 'InTopKV2' Op has type float16 that contributed by mattmann. #7227

Merged
merged 1 commit into from
Jul 18, 2019

Conversation

chrismattmann
Copy link
Contributor

No description provided.

…put 'predictions' of 'InTopKV2' Op has type float16 that contributed by mattmann.
@chrismattmann
Copy link
Contributor Author

chrismattmann commented Jul 17, 2019

@sherrym and @shlens can you take a look? Thank you!

@tfboyd tfboyd self-requested a review July 18, 2019 20:13
Copy link
Member

@tfboyd tfboyd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

I did not test this; but I am going to trust the community. It seems silly or me to block a PR, that seems legit and looks to address the issue in the github issue.

Thank you for the contribution.

@tfboyd tfboyd merged commit 63605b9 into tensorflow:master Jul 18, 2019
@puneetjindal
Copy link

@tfboyd I am getting the same error when i am trying to train with TPU v2-8 with my GCE VM 16.04 LTS. My error and code respectively is as follows:

I0310 18:53:33.341825 139964930656000 resnet50.py:195] Compiling model.
Traceback (most recent call last):
File "/home/puneet_jindal/.local/lib/python3.5/site-packages/tensorflow_core/python/framework/op_def_library.py", line 468, in _a
pply_op_helper
preferred_dtype=default_dtype)
File "/home/puneet_jindal/.local/lib/python3.5/site-packages/tensorflow_core/python/framework/ops.py", line 1290, in convert_to_t
ensor
(dtype.name, value.dtype.name, value))
ValueError: Tensor conversion requested dtype float32 for Tensor with dtype int32: <tf.Tensor 'metrics/sparse_top_k_categorical_acc
uracy/Cast:0' shape=(None,) dtype=int32>

`def sparse_top_k_categorical_accuracy(y_true, y_pred, k=5):
"""TPU version of sparse_top_k_categorical_accuracy."""
y_pred_rank = tensorflow.convert_to_tensor(y_pred).get_shape().ndims
y_true_rank = tensorflow.convert_to_tensor(y_true).get_shape().ndims

if ((y_true_rank is not None) and
(y_pred_rank is not None) and
(len(tensorflow.keras.backend.int_shape(y_true)) == len(tensorflow.keras.backend.int_shape(y_pred)))):
y_true = tensorflow.squeeze(y_true, [-1])

y_true = tensorflow.cast(y_true, 'int32')
#y_pred = tensorflow.cast(y_pred, 'float32')
return tensorflow.nn.in_top_k(y_pred, y_true, k)
`
This code is taken from https://github.com/tensorflow/tpu/blob/master/models/experimental/resnet50_keras/resnet50.py

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

Successfully merging this pull request may close these issues.

4 participants