Reputation:
Yesterday I created my first convolutional neural network in keras but I forgot to add labels and it trained ... somehow, and I have no idea how. Can someone explain how the heck it trained without any labels given?
Jupyter Notebook: http://nbviewer.jupyter.org/github/getrasa/Jupyter-Notebook-Share/blob/master/Untitled.ipynb
Folder structure files/ train/ dogs/ dog.0.jpg ... cats/ cat.0.jpg ... files/ validation/ dogs/ dog.1301.jpg ... cats/ cat.1301.jpg files/test/ (1-13images).jpg
Upvotes: 1
Views: 139
Reputation: 11377
No magic here. From the docs:
flow_from_directory(directory): Takes the path to a directory, and generates batches of augmented/normalized data. Yields batches indefinitely, in an infinite loop.
Arguments:
directory: path to the target directory. It should contain one subdirectory per class. Any PNG, JPG or BMP images inside each of the subdirectories directory tree will be included in the generator
As long as your data is split into subdirectories that correspond to your classes, ImageDataGenerator
will produce labels out of these. For instance, take this directory structure:
train/
cat/
dog/
eel/
The flow_from_directory
will by default take these as categorical and use one-hot encoding in the background. That's how you get labels.
One final note: since you have only two classes, you can consider changing class_mode
to binary
.
Upvotes: 1