Skip to content

Commit c92381e

Browse files
committed
get vgg16 to work
1 parent cb08a87 commit c92381e

File tree

5 files changed

+56
-7
lines changed

5 files changed

+56
-7
lines changed

README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,27 @@
11
# keras-image-classifier-web-api
22

33
This provides keras DCNN-based image classifiers codes with flask as the web api server for the image classifiers.
4+
5+
# Usage
6+
7+
Run the following command to install the keras, flask and other dependency modules:
8+
9+
```bash
10+
sudo pip install -r requirements.txt
11+
```
12+
13+
Goto keras_image_classifier_web directory and run the following command:
14+
15+
```bash
16+
python flaskr.py
17+
```
18+
19+
Now navigate your browser to http://localhost:5000 and you can try out various predictors built with the following
20+
trained classifiers:
21+
22+
* binary classifier on "cats vs dogs" data
23+
* multi-class DCNN classifier trained with CIFAR-10 data
24+
* multi-class VGG16 classifier trained with ImageNet data
25+
26+
27+
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
from keras.models import Model
2+
from keras.applications.vgg16 import VGG16, preprocess_input, decode_predictions
3+
from keras.optimizers import SGD
4+
from PIL import Image
5+
from keras.preprocessing.image import img_to_array
6+
import numpy as np
7+
8+
model = VGG16(include_top=True, weights='imagenet')
9+
model.compile(optimizer=SGD(), loss='categorical_crossentropy', metrics=['accuracy'])
10+
11+
12+
def predict(filename):
13+
img = Image.open(filename)
14+
img = img.resize((224, 224), Image.ANTIALIAS)
15+
input = img_to_array(img)
16+
input = np.expand_dims(input, axis=0)
17+
input = preprocess_input(input)
18+
output = decode_predictions(model.predict(input), top=3)
19+
print(output)
20+
21+
22+
for i in range(100):
23+
predict('bi_classifier_data/training/cat/cat.' + str(i) + '.jpg')
24+
predict('bi_classifier_data/training/dog/dog.' + str(i) + '.jpg')

keras_image_classifier_web/schema.sql

Lines changed: 0 additions & 7 deletions
This file was deleted.

requirements.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Flask == 0.12.2
2+
gevent
3+
keras
4+
numpy
5+
h5py
6+
pillow
7+
https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.11.0-cp27-none-linux_x86_64.whl

setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
include_package_data=True,
77
install_requires=[
88
'flask',
9+
'keras',
910
],
1011
setup_requires=[
1112
'pytest-runner',

0 commit comments

Comments
 (0)