File tree Expand file tree Collapse file tree 5 files changed +56
-7
lines changed
keras_image_classifier_web Expand file tree Collapse file tree 5 files changed +56
-7
lines changed Original file line number Diff line number Diff line change 11# keras-image-classifier-web-api
22
33This 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+
Original file line number Diff line number Diff line change 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' )
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 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
Original file line number Diff line number Diff line change 66 include_package_data = True ,
77 install_requires = [
88 'flask' ,
9+ 'keras' ,
910 ],
1011 setup_requires = [
1112 'pytest-runner' ,
You can’t perform that action at this time.
0 commit comments