├── README.md ├── protoio_ClassifyDL ├── 1 - Screen 3.png ├── 2 - Screen 1.png └── 3 - Screen 2.png ├── requirements.txt ├── server.py └── static ├── assets └── background.jpg ├── css └── custom.css ├── index.html ├── js ├── main_system.js └── main_url.js ├── system.html └── url.html /README.md: -------------------------------------------------------------------------------- 1 | # DeepClassifyML 2 | 3 | ## Hasura Internship 2017 4 | 5 | Check out the subsequent [Medium Blog Posts](https://medium.com/@akshaybhatia10/deepclassifyml-week-1-part-1-b1c53e0a7cc). 6 | 7 | ### About 8 | 9 | DeepClassifyML is a webapp to classify images into different categories using a pre-trained model on the Imagenet dataset. ImageNet is a common academic data set in machine learning for training an image recognition system. The basic idea is to allow the user to upload an image from his/her system or through an url and run the Inception model over it to classify in different classes with a confidence(probability) score. The results would be something like this : 10 | 11 | 12 |  13 | -------------------------------------------------------------------------------- /protoio_ClassifyDL/1 - Screen 3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akshaybhatia10/DeepClassifyML/08e08fe3c58a53d7f67443bf8853187ef6b4c88b/protoio_ClassifyDL/1 - Screen 3.png -------------------------------------------------------------------------------- /protoio_ClassifyDL/2 - Screen 1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akshaybhatia10/DeepClassifyML/08e08fe3c58a53d7f67443bf8853187ef6b4c88b/protoio_ClassifyDL/2 - Screen 1.png -------------------------------------------------------------------------------- /protoio_ClassifyDL/3 - Screen 2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akshaybhatia10/DeepClassifyML/08e08fe3c58a53d7f67443bf8853187ef6b4c88b/protoio_ClassifyDL/3 - Screen 2.png -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | alabaster==0.7.9 2 | anaconda-client==1.2.2 3 | appdirs==1.4.3 4 | appnope==0.1.0 5 | args==0.1.0 6 | astroid==1.4.9 7 | Babel==2.3.4 8 | backports.shutil-get-terminal-size==1.0.0 9 | backports.tempfile==1.0rc1 10 | backports.weakref==1.0rc1 11 | beautifulsoup4==4.5.3 12 | bitarray==0.8.1 13 | blaze==0.10.1 14 | blessed==1.14.2 15 | bokeh==0.12.4 16 | boto==2.45.0 17 | botocore==1.5.80 18 | Bottleneck==1.1.0 19 | cement==2.8.2 20 | certifi==2017.4.17 21 | chardet==3.0.4 22 | chest==0.2.3 23 | click==6.7 24 | clint==0.5.1 25 | cloudpickle==0.2.2 26 | clyent==1.2.1 27 | colorama==0.3.7 28 | conda==4.3.16 29 | configobj==5.0.6 30 | contextlib2==0.5.4 31 | cycler==0.10.0 32 | Cython==0.25.2 33 | cytoolz==0.8.2 34 | dask==0.13.0 35 | datashape==0.5.2 36 | decorator==4.0.11 37 | dill==0.2.5 38 | docker-py==1.7.2 39 | dockerpty==0.4.1 40 | docopt==0.6.2 41 | docutils==0.13.1 42 | et-xmlfile==1.0.1 43 | fastcache==1.0.2 44 | Flask==0.12 45 | Flask-Cors==3.0.2 46 | floyd-cli==0.9.5 47 | gevent==1.2.1 48 | greenlet==0.4.11 49 | gunicorn==19.7.1 50 | HeapDict==1.0.0 51 | idna==2.5 52 | imagesize==0.7.1 53 | ipykernel==4.5.2 54 | ipython==5.1.0 55 | ipython-genutils==0.1.0 56 | ipywidgets==5.2.2 57 | isort==4.2.5 58 | itsdangerous==0.24 59 | jdcal==1.3 60 | jedi==0.9.0 61 | Jinja2==2.9.4 62 | jmespath==0.9.3 63 | jsonschema==2.5.1 64 | jupyter==1.0.0 65 | jupyter-client==4.4.0 66 | jupyter-console==5.0.0 67 | jupyter-core==4.2.1 68 | Keras==2.0.4 69 | lazy-object-proxy==1.2.2 70 | locket==0.2.0 71 | lxml==3.7.2 72 | MarkupSafe==0.23 73 | marshmallow==2.13.5 74 | mistune==0.7.3 75 | mpmath==0.19 76 | multipledispatch==0.4.9 77 | nbconvert==4.2.0 78 | nbformat==4.2.0 79 | networkx==1.11 80 | nltk==3.2.4 81 | nose==1.3.7 82 | notebook==5.4.1 83 | numpy==1.12.1 84 | numpydoc==0.6.0 85 | odo==0.5.0 86 | olefile==0.44 87 | opencv-python 88 | openpyxl==2.4.1 89 | pandas==0.19.2 90 | packaging==16.8 91 | partd==0.3.7 92 | pathlib2==2.2.1 93 | pathspec==0.5.0 94 | patsy==0.4.1 95 | pep8==1.7.0 96 | pexpect==4.2.1 97 | pickleshare==0.7.4 98 | Pillow==4.0.0 99 | ply==3.9 100 | prompt-toolkit==1.0.9 101 | protobuf==3.3.0 102 | psutil==5.0.1 103 | ptyprocess==0.5.1 104 | py==1.4.32 105 | pyasn1==0.1.9 106 | pycosat==0.6.1 107 | pycparser==2.17 108 | pyflakes==1.5.0 109 | Pygments==2.1.3 110 | pylint==1.6.4 111 | pyOpenSSL==16.2.0 112 | pyparsing==2.2.0 113 | pytest==3.0.5 114 | python-dateutil==2.6.0 115 | pytz==2017.2 116 | PyYAML==3.12 117 | pyzmq==16.0.2 118 | QtAwesome==0.4.3 119 | qtconsole==4.2.1 120 | QtPy==1.2.1 121 | redis==2.10.5 122 | requests==2.17.3 123 | requests-toolbelt==0.8.0 124 | rope-py3k==0.9.4.post1 125 | scikit-learn==0.18.1 126 | semantic-version==2.5.0 127 | shortuuid==0.5.0 128 | simplegeneric==0.8.1 129 | singledispatch==3.4.0.3 130 | six==1.10.0 131 | snowballstemmer==1.2.1 132 | sockjs-tornado==1.0.3 133 | Sphinx==1.5.1 134 | SQLAlchemy==1.1.5 135 | sympy==1.0 136 | tensorflow==1.0.0 137 | termcolor==1.1.0 138 | terminado==0.6 139 | toolz==0.8.2 140 | tornado==4.4.2 141 | traitlets==4.3.1 142 | unicodecsv==0.14.1 143 | urllib3==1.21.1 144 | virtualenv==15.1.0 145 | wcwidth==0.1.7 146 | websocket-client==0.44.0 147 | Werkzeug==0.12.2 148 | widgetsnbextension==1.2.6 149 | wordcloud==1.3.1 150 | wrapt==1.10.8 151 | xlrd==1.0.0 152 | XlsxWriter==0.9.6 153 | -------------------------------------------------------------------------------- /server.py: -------------------------------------------------------------------------------- 1 | from keras.applications import inception_v3,imagenet_utils 2 | import cv2 3 | import numpy as np 4 | from flask import Flask, request, make_response,jsonify 5 | import numpy as np 6 | import json 7 | import urllib.request 8 | from urllib.request import Request, urlopen 9 | import base64 10 | import numpy as np 11 | from flask import Flask, render_template, request, redirect, url_for, send_from_directory 12 | import logging 13 | 14 | model = None 15 | app = Flask(__name__,static_url_path='') 16 | 17 | 18 | def preprocess_img(img,target_size=(299,299)): 19 | if (img.shape[2] == 4): 20 | img = cv2.cvtColor(img, cv2.COLOR_BGRA2BGR) 21 | img = cv2.resize(img,target_size) 22 | img = np.divide(img,255.) 23 | img = np.subtract(img,0.5) 24 | img = np.multiply(img,2.) 25 | return img 26 | 27 | def load_im_from_url(url): 28 | requested_url = urlopen(Request(url,headers={'User-Agent': 'Mozilla/5.0'})) 29 | image_array = np.asarray(bytearray(requested_url.read()), dtype=np.uint8) 30 | print (image_array.shape) 31 | print (image_array) 32 | image_array = cv2.imdecode(image_array, -1) 33 | print (image_array.shape) 34 | return image_array 35 | 36 | def load_im_from_system(url): 37 | image_url = url.split(',')[1] 38 | image_url = image_url.replace(" ", "+") 39 | image_array = base64.b64decode(image_url) 40 | #image_array = np.asarray(bytearray(image_array), dtype=np.uint8) 41 | image_array = np.fromstring(image_array, np.uint8) 42 | image_array = cv2.imdecode(image_array, -1) 43 | return image_array 44 | 45 | def predict(img): 46 | img=preprocess_img(img) 47 | print (img.shape) 48 | global model 49 | if model is None: 50 | model =inception_v3.InceptionV3() 51 | model.compile(optimizer='adam', loss='categorical_crossentropy') 52 | preds = model.predict(np.array([img])) 53 | return imagenet_utils.decode_predictions(preds) 54 | 55 | 56 | 57 | @app.route('/classify_system', methods=['GET']) 58 | def classify_system(): 59 | image_url = request.args.get('imageurl') 60 | image_array = load_im_from_system(image_url) 61 | resp = predict(image_array) 62 | result = [] 63 | for r in resp[0]: 64 | result.append({"class_name":r[1],"score":float(r[2])}) 65 | return jsonify({'results':result}) 66 | 67 | @app.route('/classify_url', methods=['GET']) 68 | def classify_url(): 69 | image_url = request.args.get('imageurl') 70 | image_array = load_im_from_url(image_url) 71 | resp = predict(image_array) 72 | result = [] 73 | for r in resp[0]: 74 | result.append({"class_name":r[1],"score":float(r[2])}) 75 | return jsonify({'results':result}) 76 | 77 | 78 | 79 | @app.route('/classify-system', methods=['GET']) 80 | def do_system(): 81 | return app.send_static_file('system.html') 82 | 83 | @app.route('/classify-url', methods=['GET']) 84 | def do_url(): 85 | return app.send_static_file('url.html') 86 | 87 | @app.route('/', methods=['GET']) 88 | def root(): 89 | return app.send_static_file('index.html') 90 | 91 | if __name__ == '__main__': 92 | app.run(host='0.0.0.0', port=8080, debug=True) 93 | 94 | -------------------------------------------------------------------------------- /static/assets/background.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akshaybhatia10/DeepClassifyML/08e08fe3c58a53d7f67443bf8853187ef6b4c88b/static/assets/background.jpg -------------------------------------------------------------------------------- /static/css/custom.css: -------------------------------------------------------------------------------- 1 | footer { 2 | position: absolute; 3 | width: 100%; 4 | bottom: 30; 5 | } 6 | 7 | 8 | body { 9 | height: 100%; 10 | width: 100%; 11 | margin: 0; 12 | padding: 0; 13 | } 14 | 15 | .fixed-background { 16 | position: absolute; 17 | top: 0; 18 | left: 0; 19 | height: 100%; 20 | width: 100%; 21 | overflow: hidden; 22 | } 23 | 24 | img { 25 | position: relative; 26 | width: 100%; /* for IE 6 */ 27 | } 28 | 29 | .over { 30 | position: absolute; 31 | top: 200px; 32 | left: 0; 33 | width: 100%; 34 | } 35 | 36 | .over { 37 | position: absolute; 38 | width: 800px; 39 | height: 500px; 40 | top: 50%; 41 | left: 50%; 42 | margin: -200px -100px 100px -100px; 43 | color: white; 44 | 45 | } 46 | 47 | #top { 48 | padding: 2px 2px 5px; 49 | } 50 | 51 | #middle { 52 | padding: 2px 2px 5px; 53 | } 54 | 55 | #last { 56 | padding: 2px 2px 5px; 57 | 58 | } 59 | 60 | h2{ 61 | font-family: 'PT Sans', sans-serif; 62 | } 63 | 64 | h4{ 65 | font-family: 'PT Sans', sans-serif; 66 | } 67 | 68 | h1{ 69 | font-family: 'PT Sans', sans-serif; 70 | } -------------------------------------------------------------------------------- /static/index.html: -------------------------------------------------------------------------------- 1 | 2 |
3 | 4 | 5 | 6 | 7 | 8 |