Keras gives ZeroDivisionError

I’m trying to run the cat’s versus dog’s example. I’ve finally gotten keras to install on a machine, but now Keras gives ZeroDivisionError. I don’t know enough of what I am doing yet to fix this myself. Thank you

Data from: https://www.kaggle.com/c/dogs-vs-cats/data
Source from: https://github.com/llSourcell/how_to_make_an_image_classifier/blob/master/demo.ipynb

Ubuntu 16.04
iPython 3.5 (because that’s what conda + pip supports for tensorflow-gpu)
Jupyter Notebook

Error Code:
model.fit_generator(
train_generator,
samples_per_epoch=nb_train_samples,
nb_epoch=nb_epoch,
validation_data=validation_generator,
nb_val_samples=nb_validation_samples)

Error:
/home/tensor/.local/lib/python3.5/site-packages/ipykernel_launcher.py:6: UserWarning: Update your fit_generator call to the Keras 2 API: fit_generator(<keras.pre..., steps_per_epoch=128, epochs=30, validation_data=<keras.pre..., validation_steps=832)

Epoch 1/30

Exception in thread Thread-4:
Traceback (most recent call last):
  File "/home/tensor/anaconda3/envs/dlkeras/lib/python3.5/threading.py", line 914, in _bootstrap_inner
    self.run()
  File "/home/tensor/anaconda3/envs/dlkeras/lib/python3.5/threading.py", line 862, in run
    self._target(*self._args, **self._kwargs)
  File "/home/tensor/.local/lib/python3.5/site-packages/keras/engine/training.py", line 612, in data_generator_task
    generator_output = next(self._generator)
  File "/home/tensor/.local/lib/python3.5/site-packages/keras/preprocessing/image.py", line 727, in __next__
    return self.next(*args, **kwargs)
  File "/home/tensor/.local/lib/python3.5/site-packages/keras/preprocessing/image.py", line 950, in next
    index_array, current_index, current_batch_size = next(self.index_generator)
  File "/home/tensor/.local/lib/python3.5/site-packages/keras/preprocessing/image.py", line 710, in _flow_index
    current_index = (self.batch_index * batch_size) % n
ZeroDivisionError: integer division or modulo by zero

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-14-3d4698a556a2> in <module>()
      4         nb_epoch=nb_epoch,
      5         validation_data=validation_generator,
----> 6         nb_val_samples=nb_validation_samples)

/home/tensor/.local/lib/python3.5/site-packages/keras/legacy/interfaces.py in wrapper(*args, **kwargs)
     86                 warnings.warn('Update your `' + object_name +
     87                               '` call to the Keras 2 API: ' + signature, stacklevel=2)
---> 88             return func(*args, **kwargs)
     89         wrapper._legacy_support_signature = inspect.getargspec(func)
     90         return wrapper

/home/tensor/.local/lib/python3.5/site-packages/keras/models.py in fit_generator(self, generator, steps_per_epoch, epochs, verbose, callbacks, validation_data, validation_steps, class_weight, max_q_size, workers, pickle_safe, initial_epoch)
   1108                                         workers=workers,
   1109                                         pickle_safe=pickle_safe,
-> 1110                                         initial_epoch=initial_epoch)
   1111 
   1112     @interfaces.legacy_generator_methods_support

/home/tensor/.local/lib/python3.5/site-packages/keras/legacy/interfaces.py in wrapper(*args, **kwargs)
     86                 warnings.warn('Update your `' + object_name +
     87                               '` call to the Keras 2 API: ' + signature, stacklevel=2)
---> 88             return func(*args, **kwargs)
     89         wrapper._legacy_support_signature = inspect.getargspec(func)
     90         return wrapper

/home/tensor/.local/lib/python3.5/site-packages/keras/engine/training.py in fit_generator(self, generator, steps_per_epoch, epochs, verbose, callbacks, validation_data, validation_steps, class_weight, max_q_size, workers, pickle_safe, initial_epoch)
   1863                                          'a tuple `(x, y, sample_weight)` '
   1864                                          'or `(x, y)`. Found: ' +
-> 1865                                          str(generator_output))
   1866                     if len(generator_output) == 2:
   1867                         x, y = generator_output

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

The first error is a warning. The notebook is written in keras 1.x while it seems you have version 2.0 installed. That is not the problem here though.

Some of the variables you are passing are 0, check that all the previous code is run before you call fit.
If that doesnt fix it. inspect the variables you are passing on to keras and check if there is anything weird.

How can I specify keras 1 in conda or pip etc? Can I make a new conda-source (vm? What are these actually called??) and then install specifically keras1?

conda install ‘package name’='version’
pip install ‘package name’=‘version’

Thank you @mmusket. There was a stray 0. many images, 0 image categories.

The package specification is helpful too.

Is the notebook issue (written for keras 1, not 2.0) the reason why it only updates output when the code is finished, rather than as it is running? For example, keras only gives output at the end of each epoch, not during.