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

UnboundLocalError: local variable 'epoch_logs' referenced before assignment #17

Open
jangdoohwan opened this issue Feb 16, 2017 · 5 comments

Comments

@jangdoohwan
Copy link

jangdoohwan commented Feb 16, 2017

boss_train.py errors have occurred.

/Users/icent/Documents/BossSensor/data/boss/dummy.jpg
X_train shape: (0, 64, 64, 3)
0 train samples
0 valid samples
1 test samples
~~
Total params: 6489634


Using real-time data augmentation.
Epoch 1/10
Traceback (most recent call last):
File "/Users/icent/Documents/BossSensor/boss_train.py", line 181, in
model.train(dataset, nb_epoch=10)
File "/Users/icent/Documents/BossSensor/boss_train.py", line 146, in train
validation_data=(dataset.X_valid, dataset.Y_valid))
File "/anaconda/envs/boss/lib/python3.5/site-packages/keras/models.py", line 874, in fit_generator
pickle_safe=pickle_safe)
File "/anaconda/envs/boss/lib/python3.5/site-packages/keras/engine/training.py", line 1485, in fit_generator
callbacks.on_epoch_end(epoch, epoch_logs)

UnboundLocalError: local variable 'epoch_logs' referenced before assignment

Help me!

@OnlyBelter
Copy link

OnlyBelter commented Feb 26, 2017

I have the same error:

Total params: 6,489,634
Trainable params: 6,489,634
Non-trainable params: 0
____________________________________________________________________________________________________
Using real-time data augmentation.
Epoch 1/10
Exception in thread Thread-1:
Traceback (most recent call last):
  File "D:\tools\Anaconda3\envs\bossSensor\lib\threading.py", line 914, in _bootstrap_inner
    self.run()
  File "D:\tools\Anaconda3\envs\bossSensor\lib\threading.py", line 862, in run
    self._target(*self._args, **self._kwargs)
  File "D:\tools\Anaconda3\envs\bossSensor\lib\site-packages\keras\engine\training.py", line 429, in data_generator_task
    generator_output = next(self._generator)
  File "D:\tools\Anaconda3\envs\bossSensor\lib\site-packages\keras\preprocessing\image.py", line 662, in __next__
    return self.next(*args, **kwargs)
  File "D:\tools\Anaconda3\envs\bossSensor\lib\site-packages\keras\preprocessing\image.py", line 708, in next
    index_array, current_index, current_batch_size = next(self.index_generator)
  File "D:\tools\Anaconda3\envs\bossSensor\lib\site-packages\keras\preprocessing\image.py", line 645, in _flow_index
    current_index = (self.batch_index * batch_size) % n
ZeroDivisionError: integer division or modulo by zero

Traceback (most recent call last):
  File "D:/tools/PyCharm-Project/BossSensor/boss_train.py", line 178, in <module>
    model.train(dataset, nb_epoch=10)
  File "D:/tools/PyCharm-Project/BossSensor/boss_train.py", line 143, in train
    validation_data=(dataset.X_valid, dataset.Y_valid))
  File "D:\tools\Anaconda3\envs\bossSensor\lib\site-packages\keras\models.py", line 935, in fit_generator
    initial_epoch=initial_epoch)
  File "D:\tools\Anaconda3\envs\bossSensor\lib\site-packages\keras\engine\training.py", line 1600, in fit_generator
    callbacks.on_epoch_end(epoch, epoch_logs)
UnboundLocalError: local variable 'epoch_logs' referenced before assignment

How can I fix it??

-----------------------------------update-------------------------------------------------

It's my problem, I gave wrong photos's format *.png instead of *.jpg, so I saw this after read all photos:

X_train shape: (0, 64, 64, 3)
0 train samples
0 valid samples
0 test samples

When I changed all the extension of photos, It can work.

@darrylsepeda
Copy link

Me too... get the same error:

Total params: 6,489,634
Trainable params: 6,489,634
Non-trainable params: 0
_________________________________________________________________
Using real-time data augmentation.
boss_train.py:143: UserWarning: Update your `fit_generator` call to the Keras 2 API: `fit_generator(<keras.pre..., epochs=10, steps_per_epoch=0, validation_data=(array([[[...)`
  validation_data=(dataset.X_valid, dataset.Y_valid))
Epoch 1/10
Traceback (most recent call last):
  File "boss_train.py", line 175, in <module>
    model.train(dataset, nb_epoch=10)
  File "boss_train.py", line 143, in train
    validation_data=(dataset.X_valid, dataset.Y_valid))
  File "/Users/darryl/Applications/miniconda2/envs/venv/lib/python3.5/site-packages/keras/legacy/interfaces.py", line 88, in wrapper
    return func(*args, **kwargs)
  File "/Users/darryl/Applications/miniconda2/envs/venv/lib/python3.5/site-packages/keras/models.py", line 1107, in fit_generator
    initial_epoch=initial_epoch)
  File "/Users/darryl/Applications/miniconda2/envs/venv/lib/python3.5/site-packages/keras/legacy/interfaces.py", line 88, in wrapper
    return func(*args, **kwargs)
  File "/Users/darryl/Applications/miniconda2/envs/venv/lib/python3.5/site-packages/keras/engine/training.py", line 1914, in fit_generator
    callbacks.on_epoch_end(epoch, epoch_logs)
UnboundLocalError: local variable 'epoch_logs' referenced before assignment

eventhough already have the proper images as the resource

X_train shape: (4, 64, 64, 3)
4 train samples
3 valid samples
3 test samples

Can anyone explain what had happened?

@luis-i-reyes-castro
Copy link

Hello! I wanted to report that I got this error too, and I've found that in my case it was (at least partially) caused by having steps_per_epoch = 0. In this case line 1852 of "training.py" fails to enter the while loop which defines 'epochs_log'.
epochs_log_error_cause

@hlnull
Copy link

hlnull commented Dec 21, 2017

check this issue: keras-team/keras#450 for more details. The root cause is that steps_per_epoch = 0, as mentioned in #17 (comment).

@hlnull
Copy link

hlnull commented Dec 22, 2017

BTW, this issue has been fixed by keras-team/keras#8854. Use the latest codes of keras shall fix this issue.

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

5 participants