Spaces:
Running
Running
new model added
Browse files
app.py
CHANGED
@@ -2,7 +2,6 @@ import io
|
|
2 |
import os
|
3 |
import streamlit as st
|
4 |
import requests
|
5 |
-
import numpy as np
|
6 |
from PIL import Image
|
7 |
from model import get_caption_model, generate_caption
|
8 |
|
@@ -37,16 +36,15 @@ if (img_url != "") and (img_url != None):
|
|
37 |
img = img.convert('RGB')
|
38 |
st.image(img)
|
39 |
img.save('tmp.jpg')
|
40 |
-
st.image(img)
|
41 |
predict()
|
42 |
os.remove('tmp.jpg')
|
43 |
|
44 |
|
45 |
st.markdown('<center style="opacity: 70%">OR</center>', unsafe_allow_html=True)
|
46 |
-
|
47 |
|
48 |
-
if
|
49 |
-
img =
|
50 |
img = Image.open(io.BytesIO(img))
|
51 |
img = img.convert('RGB')
|
52 |
img.save('tmp.jpg')
|
|
|
2 |
import os
|
3 |
import streamlit as st
|
4 |
import requests
|
|
|
5 |
from PIL import Image
|
6 |
from model import get_caption_model, generate_caption
|
7 |
|
|
|
36 |
img = img.convert('RGB')
|
37 |
st.image(img)
|
38 |
img.save('tmp.jpg')
|
|
|
39 |
predict()
|
40 |
os.remove('tmp.jpg')
|
41 |
|
42 |
|
43 |
st.markdown('<center style="opacity: 70%">OR</center>', unsafe_allow_html=True)
|
44 |
+
img_upload = st.file_uploader(label='Upload Image', type=['jpg', 'png'])
|
45 |
|
46 |
+
if img_upload != None:
|
47 |
+
img = img_upload.read()
|
48 |
img = Image.open(io.BytesIO(img))
|
49 |
img = img.convert('RGB')
|
50 |
img.save('tmp.jpg')
|
model.py
CHANGED
@@ -14,7 +14,7 @@ UNITS = 512
|
|
14 |
|
15 |
|
16 |
# LOADING DATA
|
17 |
-
vocab = pickle.load(open('saved_vocabulary/
|
18 |
|
19 |
tokenizer = tf.keras.layers.TextVectorization(
|
20 |
# max_tokens=VOCABULARY_SIZE,
|
@@ -36,7 +36,6 @@ def CNN_Encoder():
|
|
36 |
include_top=False,
|
37 |
weights='imagenet'
|
38 |
)
|
39 |
-
inception_v3.trainable = False
|
40 |
|
41 |
output = inception_v3.output
|
42 |
output = tf.keras.layers.Reshape(
|
@@ -264,7 +263,7 @@ def load_image_from_path(img_path):
|
|
264 |
img = tf.io.read_file(img_path)
|
265 |
img = tf.io.decode_jpeg(img, channels=3)
|
266 |
img = tf.keras.layers.Resizing(299, 299)(img)
|
267 |
-
img = img
|
268 |
return img
|
269 |
|
270 |
|
@@ -322,8 +321,8 @@ def get_caption_model():
|
|
322 |
caption_model.decoder(sample_y, sample_enc_out, training=False)
|
323 |
|
324 |
try:
|
325 |
-
caption_model.load_weights('saved_models/
|
326 |
except FileNotFoundError:
|
327 |
-
caption_model.load_weights('Image-Captioning/saved_models/
|
328 |
|
329 |
return caption_model
|
|
|
14 |
|
15 |
|
16 |
# LOADING DATA
|
17 |
+
vocab = pickle.load(open('saved_vocabulary/vocab_coco.file', 'rb'))
|
18 |
|
19 |
tokenizer = tf.keras.layers.TextVectorization(
|
20 |
# max_tokens=VOCABULARY_SIZE,
|
|
|
36 |
include_top=False,
|
37 |
weights='imagenet'
|
38 |
)
|
|
|
39 |
|
40 |
output = inception_v3.output
|
41 |
output = tf.keras.layers.Reshape(
|
|
|
263 |
img = tf.io.read_file(img_path)
|
264 |
img = tf.io.decode_jpeg(img, channels=3)
|
265 |
img = tf.keras.layers.Resizing(299, 299)(img)
|
266 |
+
img = tf.keras.applications.inception_v3.preprocess_input(img)
|
267 |
return img
|
268 |
|
269 |
|
|
|
321 |
caption_model.decoder(sample_y, sample_enc_out, training=False)
|
322 |
|
323 |
try:
|
324 |
+
caption_model.load_weights('saved_models/image_captioning_coco_weights.h5')
|
325 |
except FileNotFoundError:
|
326 |
+
caption_model.load_weights('Image-Captioning/saved_models/image_captioning_coco_weights.h5')
|
327 |
|
328 |
return caption_model
|
saved_models/{image_captioning_transformer_weights_1.h5 β image_captioning_coco_weights.h5}
RENAMED
@@ -1,3 +1,3 @@
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:
|
3 |
-
size
|
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:1e84cba7f9b81e113d6cf938f1c03eff9be2f91932edf36ba1d43a14a63eeb23
|
3 |
+
size 214197308
|
saved_models/image_captioning_transformer_weights_3.h5
DELETED
@@ -1,3 +0,0 @@
|
|
1 |
-
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:61d25373a21ccddf8bf24f67b2a1bb2037d565f8e88c85e20e7f5ef8527a90d9
|
3 |
-
size 247484996
|
|
|
|
|
|
|
|
saved_vocabulary/{vocab_2.file β vocab_coco.file}
RENAMED
@@ -1,3 +1,3 @@
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:
|
3 |
-
size
|
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:41e68329402249568d75664e814571ccfb8471da72894cffca32cb534a9ef1ea
|
3 |
+
size 1153949
|