Skip to content

Commit

Permalink
upgraded to tensorflow v2.x
Browse files Browse the repository at this point in the history
  • Loading branch information
anuragjoshi3519 committed Apr 2, 2020
1 parent 625861d commit f5bffa9
Show file tree
Hide file tree
Showing 22 changed files with 66 additions and 103 deletions.
27 changes: 10 additions & 17 deletions .ipynb_checkpoints/Data Preprocessing-checkpoint.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,10 @@
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"Using TensorFlow backend.\n"
]
}
],
"outputs": [],
"source": [
"import numpy as np\n",
"import pandas as pd\n",
"import matplotlib.pyplot as plt\n",
"import nltk\n",
"import json\n",
Expand All @@ -24,18 +17,18 @@
"import os\n",
"import cv2\n",
"import gensim\n",
"from keras.applications.resnet50 import ResNet50,preprocess_input,decode_predictions\n",
"from keras.preprocessing import image\n",
"from keras.preprocessing.sequence import pad_sequences\n",
"from keras.layers import Dense,Flatten,Embedding,Dropout,Input,LSTM,add\n",
"from keras.models import Model,load_model\n",
"from keras.utils.np_utils import to_categorical \n",
"from tensorflow.keras.applications.resnet50 import ResNet50,preprocess_input,decode_predictions\n",
"from tensorflow.keras.preprocessing import image\n",
"from tensorflow.keras.preprocessing.sequence import pad_sequences\n",
"from tensorflow.keras.layers import Dense,Flatten,Embedding,Dropout,Input,LSTM,add\n",
"from tensorflow.keras.models import Model,load_model\n",
"from tensorflow.keras.utils import to_categorical\n",
"#%xmode verbose"
]
},
{
"cell_type": "code",
"execution_count": 27,
"execution_count": 5,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -66,7 +59,7 @@
},
{
"cell_type": "code",
"execution_count": 28,
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
Expand Down
27 changes: 10 additions & 17 deletions .ipynb_checkpoints/Model Architecture and Training-checkpoint.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,9 @@
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"execution_count": 5,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"Using TensorFlow backend.\n"
]
}
],
"outputs": [],
"source": [
"import numpy as np\n",
"import matplotlib.pyplot as plt\n",
Expand All @@ -24,12 +16,13 @@
"import os\n",
"import cv2\n",
"import gensim\n",
"from keras.applications.resnet50 import ResNet50,preprocess_input,decode_predictions\n",
"from keras.preprocessing import image\n",
"from keras.preprocessing.sequence import pad_sequences\n",
"from keras.layers import Dense,Flatten,Embedding,Dropout,Input,LSTM,add\n",
"from keras.models import Model,load_model\n",
"from keras.utils.np_utils import to_categorical \n",
"import tensorflow as tf\n",
"from tensorflow.keras.applications.resnet50 import ResNet50,preprocess_input,decode_predictions\n",
"from tensorflow.keras.preprocessing import image\n",
"from tensorflow.keras.preprocessing.sequence import pad_sequences\n",
"from tensorflow.keras.layers import Dense,Flatten,Embedding,Dropout,Input,LSTM,add\n",
"from tensorflow.keras.models import Model,load_model\n",
"from tensorflow.keras.utils import to_categorical \n",
"#%xmode verbose "
]
},
Expand Down Expand Up @@ -121,7 +114,7 @@
" photo = encoded_train[img+\".jpg\"]\n",
" for cap in cap_list:\n",
" seq = [word2idx[word] for word in cap.split() if word in word2idx]\n",
" print(seq)\n",
" #print(seq)\n",
" for i in range(1,len(seq)):\n",
" xi = seq[:i]\n",
" yi = seq[i]\n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,17 @@
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"Using TensorFlow backend.\n"
]
}
],
"outputs": [],
"source": [
"import numpy as np\n",
"import json\n",
"import pickle\n",
"import pathlib\n",
"import matplotlib.pyplot as plt\n",
"from keras.models import load_model\n",
"from keras.preprocessing import image\n",
"from keras.applications.resnet50 import preprocess_input\n",
"from keras.preprocessing.sequence import pad_sequences\n",
"from tensorflow.keras.models import load_model\n",
"from tensorflow.keras.preprocessing import image\n",
"from tensorflow.keras.applications.resnet50 import preprocess_input\n",
"from tensorflow.keras.preprocessing.sequence import pad_sequences\n",
"\n",
"import warnings\n",
"warnings.filterwarnings('ignore')"
Expand Down
27 changes: 10 additions & 17 deletions Data Preprocessing.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,10 @@
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"Using TensorFlow backend.\n"
]
}
],
"outputs": [],
"source": [
"import numpy as np\n",
"import pandas as pd\n",
"import matplotlib.pyplot as plt\n",
"import nltk\n",
"import json\n",
Expand All @@ -24,18 +17,18 @@
"import os\n",
"import cv2\n",
"import gensim\n",
"from keras.applications.resnet50 import ResNet50,preprocess_input,decode_predictions\n",
"from keras.preprocessing import image\n",
"from keras.preprocessing.sequence import pad_sequences\n",
"from keras.layers import Dense,Flatten,Embedding,Dropout,Input,LSTM,add\n",
"from keras.models import Model,load_model\n",
"from keras.utils.np_utils import to_categorical \n",
"from tensorflow.keras.applications.resnet50 import ResNet50,preprocess_input,decode_predictions\n",
"from tensorflow.keras.preprocessing import image\n",
"from tensorflow.keras.preprocessing.sequence import pad_sequences\n",
"from tensorflow.keras.layers import Dense,Flatten,Embedding,Dropout,Input,LSTM,add\n",
"from tensorflow.keras.models import Model,load_model\n",
"from tensorflow.keras.utils import to_categorical\n",
"#%xmode verbose"
]
},
{
"cell_type": "code",
"execution_count": 27,
"execution_count": 5,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -66,7 +59,7 @@
},
{
"cell_type": "code",
"execution_count": 28,
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
Expand Down
25 changes: 9 additions & 16 deletions Model Architecture and Training.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,9 @@
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"execution_count": 5,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"Using TensorFlow backend.\n"
]
}
],
"outputs": [],
"source": [
"import numpy as np\n",
"import matplotlib.pyplot as plt\n",
Expand All @@ -24,12 +16,13 @@
"import os\n",
"import cv2\n",
"import gensim\n",
"from keras.applications.resnet50 import ResNet50,preprocess_input,decode_predictions\n",
"from keras.preprocessing import image\n",
"from keras.preprocessing.sequence import pad_sequences\n",
"from keras.layers import Dense,Flatten,Embedding,Dropout,Input,LSTM,add\n",
"from keras.models import Model,load_model\n",
"from keras.utils.np_utils import to_categorical \n",
"import tensorflow as tf\n",
"from tensorflow.keras.applications.resnet50 import ResNet50,preprocess_input,decode_predictions\n",
"from tensorflow.keras.preprocessing import image\n",
"from tensorflow.keras.preprocessing.sequence import pad_sequences\n",
"from tensorflow.keras.layers import Dense,Flatten,Embedding,Dropout,Input,LSTM,add\n",
"from tensorflow.keras.models import Model,load_model\n",
"from tensorflow.keras.utils import to_categorical \n",
"#%xmode verbose "
]
},
Expand Down
18 changes: 5 additions & 13 deletions Predicting-Captions-for-Random-Images.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,17 @@
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"Using TensorFlow backend.\n"
]
}
],
"outputs": [],
"source": [
"import numpy as np\n",
"import json\n",
"import pickle\n",
"import pathlib\n",
"import matplotlib.pyplot as plt\n",
"from keras.models import load_model\n",
"from keras.preprocessing import image\n",
"from keras.applications.resnet50 import preprocess_input\n",
"from keras.preprocessing.sequence import pad_sequences\n",
"from tensorflow.keras.models import load_model\n",
"from tensorflow.keras.preprocessing import image\n",
"from tensorflow.keras.applications.resnet50 import preprocess_input\n",
"from tensorflow.keras.preprocessing.sequence import pad_sequences\n",
"\n",
"import warnings\n",
"warnings.filterwarnings('ignore')"
Expand Down
3 changes: 3 additions & 0 deletions WebApp/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"python.pythonPath": "env/bin/python3.7"
}
12 changes: 6 additions & 6 deletions WebApp/CaptionIt.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import numpy as np
import pickle
from keras.models import load_model
from keras.preprocessing import image
from keras.applications.resnet50 import preprocess_input
from keras.preprocessing.sequence import pad_sequences
from tensorflow.keras.models import load_model
from tensorflow.keras.preprocessing import image
from tensorflow.keras.applications.resnet50 import preprocess_input
from tensorflow.keras.preprocessing.sequence import pad_sequences

import warnings
warnings.filterwarnings('ignore')
Expand All @@ -19,9 +19,9 @@

maxlen = 40
model = load_model('./models_weights/model.h5')
model._make_predict_function()
#model._make_predict_function()
featureExtract_model = load_model("./resources/resNet50.h5")
featureExtract_model._make_predict_function()
#featureExtract_model._make_predict_function()

def preprocess_image(img_path):
img = image.load_img(img_path,target_size=(224,224))
Expand Down
Binary file modified WebApp/__pycache__/CaptionIt.cpython-37.pyc
Binary file not shown.
10 changes: 7 additions & 3 deletions WebApp/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@

app = Flask(__name__)

@app.route('/',methods=['GET','POST'])
@app.route('/home',methods=['GET','POST'])
@app.route('/')
@app.route('/home')
def home():
return render_template('index.html',title='CaptionIt')

@app.route('/upload',methods=['POST'])
def upload():
path=None
caption="sd"
caption=None
if request.method=='POST':
if request.files.get('imgFile'):
image = request.files['imgFile']
Expand Down
Binary file added WebApp/static/images/2084217208_7bd9bc85e5.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added WebApp/static/images/2162564553_96de62c7e6.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added WebApp/static/images/2206960564_325ed0c7ae.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added WebApp/static/images/2594042571_2e4666507e.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added WebApp/static/images/2774430374_fee1d793e7.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added WebApp/static/images/2991575785_bd4868e215.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added WebApp/static/images/3701291852_373ea46bb6.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added WebApp/static/images/506367606_7cca2bba9b.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added WebApp/static/images/509778093_21236bb64d.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added WebApp/static/images/AI-and-Analytics-for-DT.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion WebApp/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<p>Image Captioning Bot</p>
</div>
<div class="form-div">
<form class="ui form" enctype="multipart/form-data" action="/home" method="POST">
<form class="ui form" enctype="multipart/form-data" action="/upload" method="POST">
<div class="input-div">
<div>
<input type="file" name='imgFile' placeholder="No file selected"/>
Expand Down

0 comments on commit f5bffa9

Please sign in to comment.