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

Tried to convert 'y' to a tensor and failed. Error: None values not supported. #32646

Closed
BrikerMan opened this issue Sep 19, 2019 · 9 comments
Closed
Assignees
Labels
comp:keras Keras related issues stat:awaiting response Status - Awaiting response from author TF 2.0 Issues relating to TensorFlow 2.0 type:bug Bug

Comments

@BrikerMan
Copy link

BrikerMan commented Sep 19, 2019

System information

  • Have I written custom code (as opposed to using a stock example script provided in TensorFlow): Yes
  • OS Platform and Distribution (e.g., Linux Ubuntu 16.04): Colab
  • TensorFlow installed from (source or binary): binary
  • TensorFlow version (use command below): 2.0.0rc1

Describe the current behavior

Crash when fit. It works just fine in 1.14.0, 2.0.0b0 & 2.0.0b1.

Describe the expected behavior

Not to crash when fit.

Code to reproduce the issue

import numpy as np
import tensorflow as tf
from tensorflow.python.keras.layers import Dense
from tensorflow.python.keras.models import Sequential
from tensorflow.python.keras.optimizers import Adam

model = Sequential([
    Dense(24, input_dim=4, activation='relu'),
    Dense(24, activation='relu'),
    Dense(2, activation='linear')
])
model.compile(loss='mse', optimizer=Adam(lr=0.001))

x = np.array([[-0.08623559, -0.79897248,  0.03606475,  1.09068178]])
y = np.array([[ 1.0449973,  -0.14471795]])
model.fit(x, y)

Here is the colab link

Other info / logs

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
/usr/local/lib/python3.6/dist-packages/tensorflow_core/python/framework/op_def_library.py in _apply_op_helper(self, op_type_name, name, **keywords)
    526                 as_ref=input_arg.is_ref,
--> 527                 preferred_dtype=default_dtype)
    528           except TypeError as err:

22 frames
ValueError: None values not supported.

During handling of the above exception, another exception occurred:

ValueError                                Traceback (most recent call last)
ValueError: None values not supported.

During handling of the above exception, another exception occurred:

ValueError                                Traceback (most recent call last)
/usr/local/lib/python3.6/dist-packages/tensorflow_core/python/framework/op_def_library.py in _apply_op_helper(self, op_type_name, name, **keywords)
    543               raise ValueError(
    544                   "Tried to convert '%s' to a tensor and failed. Error: %s" %
--> 545                   (input_name, err))
    546             prefix = ("Input '%s' of '%s' Op has type %s that does not match" %
    547                       (input_name, op_type_name, observed))

ValueError: Tried to convert 'y' to a tensor and failed. Error: None values not supported.
@gadagashwini-zz gadagashwini-zz self-assigned this Sep 19, 2019
@gadagashwini-zz
Copy link
Contributor

It works fine with TF 1.15.0.rc0.
I could reproduce the issue with Tensorflow 2.0.0.rc1. Please see the colab gist. Thanks!

@bermeitinger-b
Copy link

This also happens in 2.0.0.rc0.
A "workaround" is not using the class for the optimizer but using the name as string, of course, then you can't adjust the learning rate.

Instead of:
model.compile(optimizer=keras.optimizers.SGD(), loss='mse')
you would write:
model.compile(optimizer='sgd', loss='mse')

@ymodak
Copy link
Contributor

ymodak commented Sep 19, 2019

Changing your imports can help resolve this issue. Tested in '2.0.0-rc1'

import numpy as np
import tensorflow as tf
from tensorflow.keras.layers import Dense
from tensorflow.keras.models import Sequential
from tensorflow.keras.optimizers import Adam

model = Sequential([
    Dense(24, input_dim=4, activation='relu'),
    Dense(24, activation='relu'),
    Dense(2, activation='linear')
])
model.compile(loss='mse', optimizer=Adam(lr=0.001))

x = np.array([[-0.08623559, -0.79897248,  0.03606475,  1.09068178]])
y = np.array([[ 1.0449973,  -0.14471795]])
model.fit(x, y)

output:

Train on 1 samples
1/1 [==============================] - 0s 239ms/sample - loss: 0.5793
<tensorflow.python.keras.callbacks.History at 0x7fa54c4f6630>

@ymodak ymodak added the stat:awaiting response Status - Awaiting response from author label Sep 19, 2019
@ymodak ymodak closed this as completed Sep 19, 2019
@tensorflow-bot
Copy link

Are you satisfied with the resolution of your issue?
Yes
No

@Times125
Copy link

I have this problem ,too. my code works well in 2.0b1, not work in tf 2.0rc1

@fengwang
Copy link

Changing your imports can help resolve this issue. Tested in '2.0.0-rc1'

what is the difference between tensorflow.python.keras and tensorflow.keras? Why this trick works?

@LiutongZhou
Copy link

from tensorflow.keras.optimizers import Adam
in place of
from tensorflow.python.keras.optimizers import Adam
helps

@dsryu0822
Copy link

from tensorflow.keras.optimizers import Adam
in place of
from tensorflow.python.keras.optimizers import Adam
helps

It works for me

@jawadSajid
Copy link

Worked for me!

from tensorflow.keras.optimizers import Adam
in place of
from tensorflow.python.keras.optimizers import Adam
helps

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
comp:keras Keras related issues stat:awaiting response Status - Awaiting response from author TF 2.0 Issues relating to TensorFlow 2.0 type:bug Bug
Projects
None yet
Development

No branches or pull requests

10 participants