Classification of Dog, Hot Dog and Dog Food.
- 14,197,122 images, 21841 synsets indexed (2018/12/17)
- 334MB for only compressed image URLs
synset is a short for synonym set.
(information science) A set of one or more synonyms that are interchangeable in some context without changing the truth value of the proposition in which they are embedded.
Class | Description |
---|---|
Dog, domestic dog, Canis familiaris | A member of the genus Canis (probably descended from the common wolf) that has been domesticated by man since prehistoric times; occurs in many breeds; "the dog barked all night" |
Hotdog, hot dog, red hot | A frankfurter served hot on a bun |
Dog food | Food prepared for dogs |
The url of images may be invalid
- Size too small
- HTTP Error: 404 not found
- Timeout
- Invalid url character (not ascii)
- Invalid image (can't be opened as array)
- ValueError: Unknown url type
we'll deal with them in
data_downloader.py
andinvalid_image_deleter.py
- resizeimage -
pip install python-resize-image
Download images from ImageNet
python3 data_downloader.py
Delete some invalid images (which can't open)
not sure why it can't be deleted by the same operation logic in data_downloader.py
python3 invalid_image_deleter.py
Train ResNet50
python3 ResNet50model.py
Train VGG16
python3 VGG16model.py
Training after 10 epoch
ResNet50
- Accuracy: 96.77%
- Loss: 0.0797
########################################################################
# Date: Thu Dec 27 06:07:09 PST 2018
# Job ID: 9374.c009
# User: u22711
# Resources: neednodes=1:ppn=2,nodes=1:ppn=2,walltime=06:00:00
########################################################################
Found 1306 images belonging to 3 classes.
Found 434 images belonging to 3 classes.
Found 1740 images belonging to 3 classes.
Epoch 1/10
55/54 [==============================] - 65s 1s/step - loss: 0.3709 - acc: 0.8823 - val_loss: 0.1635 - val_acc: 0.9470
Epoch 2/10
55/54 [==============================] - 62s 1s/step - loss: 0.1748 - acc: 0.9527 - val_loss: 0.1433 - val_acc: 0.9447
Epoch 3/10
55/54 [==============================] - 61s 1s/step - loss: 0.1391 - acc: 0.9568 - val_loss: 0.1248 - val_acc: 0.9539
Epoch 4/10
55/54 [==============================] - 62s 1s/step - loss: 0.1209 - acc: 0.9644 - val_loss: 0.1030 - val_acc: 0.9677
Epoch 5/10
55/54 [==============================] - 62s 1s/step - loss: 0.1134 - acc: 0.9633 - val_loss: 0.0938 - val_acc: 0.9747
Epoch 6/10
55/54 [==============================] - 61s 1s/step - loss: 0.0966 - acc: 0.9667 - val_loss: 0.0993 - val_acc: 0.9724
Epoch 7/10
55/54 [==============================] - 60s 1s/step - loss: 0.0955 - acc: 0.9691 - val_loss: 0.0887 - val_acc: 0.9677
Epoch 8/10
55/54 [==============================] - 61s 1s/step - loss: 0.1035 - acc: 0.9702 - val_loss: 0.0991 - val_acc: 0.9700
Epoch 9/10
55/54 [==============================] - 61s 1s/step - loss: 0.0864 - acc: 0.9750 - val_loss: 0.0909 - val_acc: 0.9700
Epoch 10/10
55/54 [==============================] - 60s 1s/step - loss: 0.0809 - acc: 0.9750 - val_loss: 0.0948 - val_acc: 0.9770
19/18 [===============================] - 15s 788ms/step
loss : 0.07971909043941355
acc : 0.967741926694246
100/100 [==============================] - 22s 221ms/step
########################################################################
# End of output for job 9374.c009
# Date: Thu Dec 27 06:18:18 PST 2018
########################################################################
VGG16
- Accuracy: 93.55%
- Loss: 0.6773
########################################################################
# Date: Thu Dec 27 06:07:49 PST 2018
# Job ID: 9375.c009
# User: u22711
# Resources: neednodes=1:ppn=2,nodes=1:ppn=2,walltime=06:00:00
########################################################################
Found 1306 images belonging to 3 classes.
Found 434 images belonging to 3 classes.
Found 1740 images belonging to 3 classes.
Epoch 1/10
55/54 [==============================] - 48s 878ms/step - loss: 8.8332 - acc: 0.4459 - val_loss: 8.8761 - val_acc: 0.4493
Epoch 2/10
55/54 [==============================] - 44s 806ms/step - loss: 8.8651 - acc: 0.4500 - val_loss: 8.8761 - val_acc: 0.4493
Epoch 3/10
55/54 [==============================] - 45s 823ms/step - loss: 8.8147 - acc: 0.4531 - val_loss: 8.8761 - val_acc: 0.4493
Epoch 4/10
55/54 [==============================] - 45s 822ms/step - loss: 8.8651 - acc: 0.4500 - val_loss: 8.8761 - val_acc: 0.4493
Epoch 5/10
55/54 [==============================] - 45s 823ms/step - loss: 8.8987 - acc: 0.4479 - val_loss: 8.8761 - val_acc: 0.4493
Epoch 6/10
55/54 [==============================] - 45s 820ms/step - loss: 8.8819 - acc: 0.4489 - val_loss: 8.8761 - val_acc: 0.4493
Epoch 7/10
55/54 [==============================] - 45s 823ms/step - loss: 3.8641 - acc: 0.7441 - val_loss: 1.3152 - val_acc: 0.9124
Epoch 8/10
55/54 [==============================] - 46s 831ms/step - loss: 0.8339 - acc: 0.9285 - val_loss: 0.6211 - val_acc: 0.9470
Epoch 9/10
55/54 [==============================] - 46s 836ms/step - loss: 0.5697 - acc: 0.9509 - val_loss: 2.1983 - val_acc: 0.7765
Epoch 10/10
55/54 [==============================] - 46s 836ms/step - loss: 0.6674 - acc: 0.9447 - val_loss: 0.8443 - val_acc: 0.9263
...
19/18 [===============================] - 12s 624ms/step
loss : 0.6773356663387133
acc : 0.9354838665729294
...
100/100 [==============================] - 3s 30ms/step
########################################################################
# End of output for job 9375.c009
# Date: Thu Dec 27 06:15:50 PST 2018
########################################################################
Download and show an image in python
import urllib
import io
from PIL import Image
a = urllib.request.urlopen('http://static.flickr.com/2611/3680714896_bb5cbc89cb.jpg')
b = io.BytesIO(a.read()) # Seem like this step is redundant, not sure.
c = Image.open(b)
c.show()
Visualize data augmentation
# First make a directory to store the processed data
# mkdir test
# Main
from keras.preprocessing.image import ImageDataGenerator
# Can add more data augmentation trick
gen = ImageDataGenerator(horizontal_flip=True, width_shift_range=0.2, height_shift_range=0.2)
iterator = gen.flow_from_directory('data', save_to_dir='./test')
next(iterator) # Test a batch (default 32)
Other ways to download image from ImageNet
- How to get Images from ImageNet with Python in Google Colaboratory
- xkumiyu/imagenet-downloader
- My First Attempt at ImageNet
Data preprocessing
Keras ImageDataGenerator
- Keras Image Preprocessing
- Tutorial on using Keras flow_from_directory and generators
- Tutorial on Keras flow_from_dataframe
Keras Model
Keras Transfer Learning
Keras Data Augmentation