harvitronix / five-video-classification-methods

Code that accompanies my blog post outlining five video classification methods in Keras and TensorFlow
https://medium.com/@harvitronix/five-video-classification-methods-implemented-in-keras-and-tensorflow-99cad29cc0b5
MIT License
1.18k stars 478 forks source link

train_cnn.py #112

Open drewgash opened 6 years ago

drewgash commented 6 years ago

Hi Matt,

I have tried all my best to debug this but I'm defeated. This is the error I get when I run train_cnn.py

Found 42937 images belonging to 1 classes.
Found 42937 images belonging to 1 classes.
Loading network from ImageNet weights.
Epoch 1/10
Traceback (most recent call last):
  File "train_cnn.py", line 142, in <module>
    main(weights_file)
  File "train_cnn.py", line 130, in main
    model = train_model(model, 10, generators)
  File "train_cnn.py", line 118, in train_model
    callbacks=callbacks)
  File "C:\Users\drewgash\AppData\Local\Programs\Python\Python35\lib\site-packages\keras\legacy\interfaces.py", line 91, in wrapper
    return func(*args, **kwargs)
  File "C:\Users\drewgash\AppData\Local\Programs\Python\Python35\lib\site-packages\keras\engine\training.py", line 1415, in fit_generator
    initial_epoch=initial_epoch)
  File "C:\Users\drewgash\AppData\Local\Programs\Python\Python35\lib\site-packages\keras\engine\training_generator.py", line 213, in fit_generator
    class_weight=class_weight)
  File "C:\Users\drewgash\AppData\Local\Programs\Python\Python35\lib\site-packages\keras\engine\training.py", line 1209, in train_on_batch
    class_weight=class_weight)
  File "C:\Users\drewgash\AppData\Local\Programs\Python\Python35\lib\site-packages\keras\engine\training.py", line 807, in _standardize_user_data
    y, self._feed_loss_fns, feed_output_shapes)
  File "C:\Users\drewgash\AppData\Local\Programs\Python\Python35\lib\site-packages\keras\engine\training_utils.py", line 272, in check_loss_and_target_compatibility
    ' while using as loss `categorical_crossentropy`. '
ValueError: You are passing a target array of shape (32, 1) while using as loss `categorical_crossentropy`. `categorical_crossentropy` expects targets to be binary matrices (1s and 0s) of shape (samples, classes). If your targets are integer classes, you can convert them to the expected format via:

from keras.utils import to_categorical
y_binary = to_categorical(y_int)

Alternatively, you can use the loss function `sparse_categorical_crossentropy` instead, which does expect integer targets.
yiminking commented 5 years ago

@drewgash Try change your class_limit in class DataSet() from 1 to 2.