Keras: ValueError: output of generator should be a tuple (x, y, sample_weight) or (x, y). Found: None

Created on 26 Jan 2017  Â·  9Comments  Â·  Source: keras-team/keras

Please suggest how to fix this?

mona@pascal:~/computer_vision/VPilot$ python train.py 
Using TensorFlow backend.
I tensorflow/stream_executor/dso_loader.cc:111] successfully opened CUDA library libcublas.so.8.0 locally
I tensorflow/stream_executor/dso_loader.cc:111] successfully opened CUDA library libcudnn.so.5.0 locally
I tensorflow/stream_executor/dso_loader.cc:111] successfully opened CUDA library libcufft.so.8.0 locally
I tensorflow/stream_executor/dso_loader.cc:111] successfully opened CUDA library libcuda.so.1 locally
I tensorflow/stream_executor/dso_loader.cc:111] successfully opened CUDA library libcurand.so.8.0 locally
/usr/local/lib/python2.7/dist-packages/keras/backend/tensorflow_backend.py:1938: UserWarning: Expected no kwargs, you passed 1
kwargs passed to function are ignored with Tensorflow backend
  warnings.warn('\n'.join(msg))
Epoch 1/1000
Exception in thread Thread-1:
Traceback (most recent call last):
  File "/usr/lib/python2.7/threading.py", line 810, in __bootstrap_inner
    self.run()
  File "/usr/lib/python2.7/threading.py", line 763, in run
    self.__target(*self.__args, **self.__kwargs)
  File "/usr/local/lib/python2.7/dist-packages/keras/engine/training.py", line 429, in data_generator_task
    generator_output = next(self._generator)
  File "/home/mona/computer_vision/VPilot/model.py", line 61, in dataGenerator
    x[batchCount, frameIndex, :, :, :] = cv2.imread(frameFile, mode).astype('float32')
AttributeError: 'NoneType' object has no attribute 'astype'

Traceback (most recent call last):
  File "train.py", line 56, in <module>
    callbacks=[ckp_callback]
  File "/usr/local/lib/python2.7/dist-packages/keras/models.py", line 935, in fit_generator
    initial_epoch=initial_epoch)
  File "/usr/local/lib/python2.7/dist-packages/keras/engine/training.py", line 1528, in fit_generator
    str(generator_output))
ValueError: output of generator should be a tuple (x, y, sample_weight) or (x, y). Found: None

code is: https://github.com/ai-tor/VPilot/blob/master/train.py

stale

Most helpful comment

Your generator yielded None, or nothing. It could be caused either by the generator not being in a loop and running out of data to yield, or the generator itself might cause an Exception which would give this error.

Sent from my Verizon, Samsung Galaxy smartphone
-------- Original message --------From: shyam1992atri notifications@github.com Date: 6/26/17 10:54 AM (GMT-08:00) To: fchollet/keras keras@noreply.github.com Cc: Pat York pat.york@nevada.unr.edu, Comment comment@noreply.github.com Subject: Re: [fchollet/keras] ValueError: output of generator should be a tuple (x, y, sample_weight) or (x, y). Found: None (#5196)
can someone help me how to solve this error

—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub, or mute the thread.

{"api_version":"1.0","publisher":{"api_key":"05dde50f1d1a384dd78767c55493e4bb","name":"GitHub"},"entity":{"external_key":"github/fchollet/keras","title":"fchollet/keras","subtitle":"GitHub repository","main_image_url":"https://cloud.githubusercontent.com/assets/143418/17495839/a5054eac-5d88-11e6-95fc-7290892c7bb5.png","avatar_image_url":"https://cloud.githubusercontent.com/assets/143418/15842166/7c72db34-2c0b-11e6-9aed-b52498112777.png","action":{"name":"Open in GitHub","url":"https://github.com/fchollet/keras"}},"updates":{"snippets":[{"icon":"PERSON","message":"@shyam1992atri in #5196: can someone help me how to solve this error\r\n"}],"action":{"name":"View Issue","url":"https://github.com/fchollet/keras/issues/5196#issuecomment-311133455"}}}

All 9 comments

Your generator threw an exception:

Exception in thread Thread-1:
Traceback (most recent call last):
  File "/usr/lib/python2.7/threading.py", line 810, in __bootstrap_inner
    self.run()
  File "/usr/lib/python2.7/threading.py", line 763, in run
    self.__target(*self.__args, **self.__kwargs)
  File "/usr/local/lib/python2.7/dist-packages/keras/engine/training.py", line 429, in data_generator_task
    generator_output = next(self._generator)
  File "/home/mona/computer_vision/VPilot/model.py", line 61, in dataGenerator
    x[batchCount, frameIndex, :, :, :] = cv2.imread(frameFile, mode).astype('float32')
AttributeError: 'NoneType' object has no attribute 'astype'

cv2.imread() returned None, meaning, I guess, that it couldn't open the file that was specified.



If your issue is an implementation question, please ask your question on StackOverflow or join the Keras Slack channel and ask there instead of filing a GitHub issue.

Traceback (most recent call last):
File "model.py", line 163, in
main()
File "model.py", line 159, in main
train_model(model, args, *data)
File "model.py", line 120, in train_model
verbose=1)
File "/home/shyam/anaconda3/envs/car-behavioral-cloning/lib/python3.5/site-packages/keras/models.py", line 924, in fit_generator
pickle_safe=pickle_safe)
File "/home/shyam/anaconda3/envs/car-behavioral-cloning/lib/python3.5/site-packages/keras/engine/training.py", line 1481, in fit_generator
str(generator_output))
ValueError: output of generator should be a tuple (x, y, sample_weight) or (x, y). Found: None

can someone help me how to solve this error

Your generator yielded None, or nothing. It could be caused either by the generator not being in a loop and running out of data to yield, or the generator itself might cause an Exception which would give this error.

Sent from my Verizon, Samsung Galaxy smartphone
-------- Original message --------From: shyam1992atri notifications@github.com Date: 6/26/17 10:54 AM (GMT-08:00) To: fchollet/keras keras@noreply.github.com Cc: Pat York pat.york@nevada.unr.edu, Comment comment@noreply.github.com Subject: Re: [fchollet/keras] ValueError: output of generator should be a tuple (x, y, sample_weight) or (x, y). Found: None (#5196)
can someone help me how to solve this error

—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub, or mute the thread.

{"api_version":"1.0","publisher":{"api_key":"05dde50f1d1a384dd78767c55493e4bb","name":"GitHub"},"entity":{"external_key":"github/fchollet/keras","title":"fchollet/keras","subtitle":"GitHub repository","main_image_url":"https://cloud.githubusercontent.com/assets/143418/17495839/a5054eac-5d88-11e6-95fc-7290892c7bb5.png","avatar_image_url":"https://cloud.githubusercontent.com/assets/143418/15842166/7c72db34-2c0b-11e6-9aed-b52498112777.png","action":{"name":"Open in GitHub","url":"https://github.com/fchollet/keras"}},"updates":{"snippets":[{"icon":"PERSON","message":"@shyam1992atri in #5196: can someone help me how to solve this error\r\n"}],"action":{"name":"View Issue","url":"https://github.com/fchollet/keras/issues/5196#issuecomment-311133455"}}}

Thank you for your reply.
I got it fixed from here
https://github.com/llSourcell/How_to_simulate_a_self_driving_car/issues/7

My fix was making sure batch size was int, not float when passing to flow from directory.

I got the same error and traceback as follow:

Traceback (most recent call last):
File "c:\Users\asojasingarayar.vscode\extensions\ms-python.python-2019.1.0\pythonFiles\ptvsd_launcher.py", line 45, in
main(ptvsdArgs)
File "c:\Users\asojasingarayar.vscode\extensions\ms-python.python-2019.1.0\pythonFiles\lib\python\ptvsd__main__.py", line 348, in main
run()
File "c:\Users\asojasingarayar.vscode\extensions\ms-python.python-2019.1.0\pythonFiles\lib\python\ptvsd__main__.py", line 253, in run_file
runpy.run_path(target, run_name='__main__')
File "C:\Users\asojasingarayar\AppData\Local\Continuum\anaconda3\envs\car-behavioral-cloning\lib\runpy.py", line 254, in run_path
pkg_name=pkg_name, script_name=fname)
File "C:\Users\asojasingarayar\AppData\Local\Continuum\anaconda3\envs\car-behavioral-cloning\lib\runpy.py", line 96, in _run_module_code
mod_name, mod_spec, pkg_name, script_name)
File "C:\Users\asojasingarayar\AppData\Local\Continuum\anaconda3\envs\car-behavioral-cloning\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "d:\MyProjects\finding-lanes\Simulate-Self-driving-Car\model.py", line 174, in
main()
File "d:\MyProjects\finding-lanes\Simulate-Self-driving-Car\model.py", line 170, in main
train_model(model, args, *data)
File "d:\MyProjects\finding-lanes\Simulate-Self-driving-Car\model.py", line 131, in train_model
verbose=1)
File "C:\Users\asojasingarayar\AppData\Local\Continuum\anaconda3\envs\car-behavioral-cloning\lib\site-packages\keras\models.py", line 924, in fit_generator
pickle_safe=pickle_safe)
File "C:\Users\asojasingarayar\AppData\Local\Continuum\anaconda3\envs\car-behavioral-cloning\lib\site-packages\kerasengine\training.py", line 1481, in fit_generator
str(generator_output))
ValueError: output of generator should be a tuple (x, y, sample_weight) or (x, y). Found: None

Model train script is available here

I solve this problem.
I think that 'segmentation_models' is implemented using 'keras' not 'tf.keras'.

Error version(for using segmentation models)
import tensorflow Class Datagenerator('tf.keras.utils.Sequence')

Revised Version
import keras class Datagenerator('keras.utils.Sequence')

and it worked. I hope you guys get help. thanks

validation_data should be a tuple (val_x, val_y, val_sample_weight) or `(val_x, val_y)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

somewacko picture somewacko  Â·  3Comments

snakeztc picture snakeztc  Â·  3Comments

farizrahman4u picture farizrahman4u  Â·  3Comments

fredtcaroli picture fredtcaroli  Â·  3Comments

NancyZxll picture NancyZxll  Â·  3Comments