├── README.md ├── Untitled.ipynb ├── app.py ├── images ├── 1.jpg ├── 589c80e564b351149f22a81f.png └── turtle_PNG69.png ├── static ├── css │ └── main.css └── js │ └── main.js ├── templates ├── base.html └── index.html └── uploads ├── 1.jpg ├── 589c80e564b351149f22a81f.png ├── Peacock-3-650x425.jpg └── turtle_PNG69.png /README.md: -------------------------------------------------------------------------------- 1 | # DL-Project-For-Beginner -------------------------------------------------------------------------------- /Untitled.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 1, 6 | "metadata": {}, 7 | "outputs": [], 8 | "source": [ 9 | "# Keras\n", 10 | "from tensorflow.keras.applications.imagenet_utils import preprocess_input, decode_predictions\n", 11 | "from tensorflow.keras.models import load_model\n", 12 | "from tensorflow.keras.preprocessing import image" 13 | ] 14 | }, 15 | { 16 | "cell_type": "code", 17 | "execution_count": 2, 18 | "metadata": {}, 19 | "outputs": [], 20 | "source": [ 21 | "from tensorflow.keras.applications.vgg19 import VGG19" 22 | ] 23 | }, 24 | { 25 | "cell_type": "code", 26 | "execution_count": 3, 27 | "metadata": {}, 28 | "outputs": [ 29 | { 30 | "name": "stdout", 31 | "output_type": "stream", 32 | "text": [ 33 | "Downloading data from https://storage.googleapis.com/tensorflow/keras-applications/vgg19/vgg19_weights_tf_dim_ordering_tf_kernels.h5\n", 34 | "574717952/574710816 [==============================] - 777s 1us/step\n" 35 | ] 36 | } 37 | ], 38 | "source": [ 39 | "model=VGG19(weights=\"imagenet\")" 40 | ] 41 | }, 42 | { 43 | "cell_type": "code", 44 | "execution_count": 4, 45 | "metadata": {}, 46 | "outputs": [], 47 | "source": [ 48 | "model.save('vgg19.h5')" 49 | ] 50 | }, 51 | { 52 | "cell_type": "code", 53 | "execution_count": null, 54 | "metadata": {}, 55 | "outputs": [], 56 | "source": [] 57 | } 58 | ], 59 | "metadata": { 60 | "kernelspec": { 61 | "display_name": "Python 3", 62 | "language": "python", 63 | "name": "python3" 64 | }, 65 | "language_info": { 66 | "codemirror_mode": { 67 | "name": "ipython", 68 | "version": 3 69 | }, 70 | "file_extension": ".py", 71 | "mimetype": "text/x-python", 72 | "name": "python", 73 | "nbconvert_exporter": "python", 74 | "pygments_lexer": "ipython3", 75 | "version": "3.6.9" 76 | } 77 | }, 78 | "nbformat": 4, 79 | "nbformat_minor": 4 80 | } 81 | -------------------------------------------------------------------------------- /app.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | Created on Thu Jun 11 22:34:20 2020 4 | 5 | @author: Krish Naik 6 | """ 7 | 8 | from __future__ import division, print_function 9 | # coding=utf-8 10 | import sys 11 | import os 12 | import glob 13 | import re 14 | import numpy as np 15 | 16 | # Keras 17 | from tensorflow.keras.applications.imagenet_utils import preprocess_input, decode_predictions 18 | from tensorflow.keras.models import load_model 19 | from tensorflow.keras.preprocessing import image 20 | 21 | # Flask utils 22 | from flask import Flask, redirect, url_for, request, render_template 23 | from werkzeug.utils import secure_filename 24 | from gevent.pywsgi import WSGIServer 25 | 26 | # Define a flask app 27 | app = Flask(__name__) 28 | 29 | # Model saved with Keras model.save() 30 | MODEL_PATH = 'vgg19.h5' 31 | 32 | # Load your trained model 33 | model = load_model(MODEL_PATH) 34 | model._make_predict_function() # Necessary 35 | 36 | 37 | 38 | def model_predict(img_path, model): 39 | img = image.load_img(img_path, target_size=(224, 224)) 40 | 41 | # Preprocessing the image 42 | x = image.img_to_array(img) 43 | # x = np.true_divide(x, 255) 44 | x = np.expand_dims(x, axis=0) 45 | 46 | # Be careful how your trained model deals with the input 47 | # otherwise, it won't make correct prediction! 48 | x = preprocess_input(x) 49 | 50 | preds = model.predict(x) 51 | return preds 52 | 53 | 54 | @app.route('/', methods=['GET']) 55 | def index(): 56 | # Main page 57 | return render_template('index.html') 58 | 59 | 60 | @app.route('/predict', methods=['GET', 'POST']) 61 | def upload(): 62 | if request.method == 'POST': 63 | # Get the file from post request 64 | f = request.files['file'] 65 | 66 | # Save the file to ./uploads 67 | basepath = os.path.dirname(__file__) 68 | file_path = os.path.join( 69 | basepath, 'uploads', secure_filename(f.filename)) 70 | f.save(file_path) 71 | 72 | # Make prediction 73 | preds = model_predict(file_path, model) 74 | 75 | # Process your result for human 76 | # pred_class = preds.argmax(axis=-1) # Simple argmax 77 | pred_class = decode_predictions(preds, top=1) # ImageNet Decode 78 | result = str(pred_class[0][0][1]) # Convert to string 79 | return result 80 | return None 81 | 82 | 83 | if __name__ == '__main__': 84 | app.run(debug=True) 85 | -------------------------------------------------------------------------------- /images/1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/krishnaik06/DL-Project-For-Beginner/616a670b3da9ee43f3e4080afe5b3f7b338862d0/images/1.jpg -------------------------------------------------------------------------------- /images/589c80e564b351149f22a81f.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/krishnaik06/DL-Project-For-Beginner/616a670b3da9ee43f3e4080afe5b3f7b338862d0/images/589c80e564b351149f22a81f.png -------------------------------------------------------------------------------- /images/turtle_PNG69.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/krishnaik06/DL-Project-For-Beginner/616a670b3da9ee43f3e4080afe5b3f7b338862d0/images/turtle_PNG69.png -------------------------------------------------------------------------------- /static/css/main.css: -------------------------------------------------------------------------------- 1 | .img-preview { 2 | width: 256px; 3 | height: 256px; 4 | position: relative; 5 | border: 5px solid #F8F8F8; 6 | box-shadow: 0px 2px 4px 0px rgba(0, 0, 0, 0.1); 7 | margin-top: 1em; 8 | margin-bottom: 1em; 9 | } 10 | 11 | .img-preview>div { 12 | width: 100%; 13 | height: 100%; 14 | background-size: 256px 256px; 15 | background-repeat: no-repeat; 16 | background-position: center; 17 | } 18 | 19 | input[type="file"] { 20 | display: none; 21 | } 22 | 23 | .upload-label{ 24 | display: inline-block; 25 | padding: 12px 30px; 26 | background: #39D2B4; 27 | color: #fff; 28 | font-size: 1em; 29 | transition: all .4s; 30 | cursor: pointer; 31 | } 32 | 33 | .upload-label:hover{ 34 | background: #34495E; 35 | color: #39D2B4; 36 | } 37 | 38 | .loader { 39 | border: 8px solid #f3f3f3; /* Light grey */ 40 | border-top: 8px solid #3498db; /* Blue */ 41 | border-radius: 50%; 42 | width: 50px; 43 | height: 50px; 44 | animation: spin 1s linear infinite; 45 | } 46 | 47 | @keyframes spin { 48 | 0% { transform: rotate(0deg); } 49 | 100% { transform: rotate(360deg); } 50 | } -------------------------------------------------------------------------------- /static/js/main.js: -------------------------------------------------------------------------------- 1 | $(document).ready(function () { 2 | // Init 3 | $('.image-section').hide(); 4 | $('.loader').hide(); 5 | $('#result').hide(); 6 | 7 | // Upload Preview 8 | function readURL(input) { 9 | if (input.files && input.files[0]) { 10 | var reader = new FileReader(); 11 | reader.onload = function (e) { 12 | $('#imagePreview').css('background-image', 'url(' + e.target.result + ')'); 13 | $('#imagePreview').hide(); 14 | $('#imagePreview').fadeIn(650); 15 | } 16 | reader.readAsDataURL(input.files[0]); 17 | } 18 | } 19 | $("#imageUpload").change(function () { 20 | $('.image-section').show(); 21 | $('#btn-predict').show(); 22 | $('#result').text(''); 23 | $('#result').hide(); 24 | readURL(this); 25 | }); 26 | 27 | // Predict 28 | $('#btn-predict').click(function () { 29 | var form_data = new FormData($('#upload-file')[0]); 30 | 31 | // Show loading animation 32 | $(this).hide(); 33 | $('.loader').show(); 34 | 35 | // Make prediction by calling api /predict 36 | $.ajax({ 37 | type: 'POST', 38 | url: '/predict', 39 | data: form_data, 40 | contentType: false, 41 | cache: false, 42 | processData: false, 43 | async: true, 44 | success: function (data) { 45 | // Get and display the result 46 | $('.loader').hide(); 47 | $('#result').fadeIn(600); 48 | $('#result').text(' Result: ' + data); 49 | console.log('Success!'); 50 | }, 51 | }); 52 | }); 53 | 54 | }); 55 | -------------------------------------------------------------------------------- /templates/base.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | AI Demo 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 22 |
23 |
{% block content %}{% endblock %}
24 |
25 | 26 | 27 | 30 | 31 | -------------------------------------------------------------------------------- /templates/index.html: -------------------------------------------------------------------------------- 1 | {% extends "base.html" %} {% block content %} 2 | 3 |

Image Classifier

4 | 5 |
6 |
7 | 10 | 11 |
12 | 13 | 22 | 23 | 24 | 25 |

26 | 27 |

28 | 29 |
30 | 31 | {% endblock %} -------------------------------------------------------------------------------- /uploads/1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/krishnaik06/DL-Project-For-Beginner/616a670b3da9ee43f3e4080afe5b3f7b338862d0/uploads/1.jpg -------------------------------------------------------------------------------- /uploads/589c80e564b351149f22a81f.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/krishnaik06/DL-Project-For-Beginner/616a670b3da9ee43f3e4080afe5b3f7b338862d0/uploads/589c80e564b351149f22a81f.png -------------------------------------------------------------------------------- /uploads/Peacock-3-650x425.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/krishnaik06/DL-Project-For-Beginner/616a670b3da9ee43f3e4080afe5b3f7b338862d0/uploads/Peacock-3-650x425.jpg -------------------------------------------------------------------------------- /uploads/turtle_PNG69.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/krishnaik06/DL-Project-For-Beginner/616a670b3da9ee43f3e4080afe5b3f7b338862d0/uploads/turtle_PNG69.png --------------------------------------------------------------------------------