Spaces:
Sleeping
Sleeping
nishantguvvada
commited on
Commit
·
bc96fd4
1
Parent(s):
bb611c9
Update app.py
Browse files
app.py
CHANGED
@@ -23,6 +23,14 @@ from tensorflow.keras.layers import (
|
|
23 |
TextVectorization,
|
24 |
)
|
25 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
26 |
@st.cache_resource()
|
27 |
def load_image_model():
|
28 |
image_model=tf.keras.models.load_model('./image_caption_model.h5')
|
@@ -37,6 +45,15 @@ def load_decoder_model():
|
|
37 |
def load_encoder_model():
|
38 |
encoder=tf.keras.models.load_model('./encoder_model.h5')
|
39 |
return encoder
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
40 |
|
41 |
st.title(":blue[Nishant Guvvada's] :red[AI Journey] Image Caption Generation")
|
42 |
image = Image.open('./title.jpg')
|
@@ -48,13 +65,7 @@ st.write("""
|
|
48 |
|
49 |
file = st.file_uploader("Upload any image and the model will try to provide a caption to it!", type= ['png', 'jpg'])
|
50 |
|
51 |
-
|
52 |
-
MINIMUM_SENTENCE_LENGTH = 5
|
53 |
-
IMG_HEIGHT = 299
|
54 |
-
IMG_WIDTH = 299
|
55 |
-
IMG_CHANNELS = 3
|
56 |
-
ATTENTION_DIM = 512 # size of dense layer in Attention
|
57 |
-
VOCAB_SIZE = 20000
|
58 |
|
59 |
# We will override the default standardization of TextVectorization to preserve
|
60 |
# "<>" characters, so we preserve the tokens for the <start> and <end>.
|
|
|
23 |
TextVectorization,
|
24 |
)
|
25 |
|
26 |
+
MAX_CAPTION_LEN = 64
|
27 |
+
MINIMUM_SENTENCE_LENGTH = 5
|
28 |
+
IMG_HEIGHT = 299
|
29 |
+
IMG_WIDTH = 299
|
30 |
+
IMG_CHANNELS = 3
|
31 |
+
ATTENTION_DIM = 512 # size of dense layer in Attention
|
32 |
+
VOCAB_SIZE = 20000
|
33 |
+
|
34 |
@st.cache_resource()
|
35 |
def load_image_model():
|
36 |
image_model=tf.keras.models.load_model('./image_caption_model.h5')
|
|
|
45 |
def load_encoder_model():
|
46 |
encoder=tf.keras.models.load_model('./encoder_model.h5')
|
47 |
return encoder
|
48 |
+
|
49 |
+
|
50 |
+
FEATURE_EXTRACTOR = tf.keras.applications.inception_resnet_v2.InceptionResNetV2(include_top=False, weights="imagenet")
|
51 |
+
FEATURE_EXTRACTOR.trainable = False
|
52 |
+
image_input = Input(shape=(IMG_HEIGHT, IMG_WIDTH, IMG_CHANNELS))
|
53 |
+
image_features = FEATURE_EXTRACTOR(image_input)
|
54 |
+
x = Reshape((FEATURES_SHAPE[0] * FEATURES_SHAPE[1], FEATURES_SHAPE[2]))(image_features)
|
55 |
+
encoder_output = Dense(ATTENTION_DIM, activation="relu")(x)
|
56 |
+
encoder = tf.keras.Model(inputs=image_input, outputs=encoder_output)
|
57 |
|
58 |
st.title(":blue[Nishant Guvvada's] :red[AI Journey] Image Caption Generation")
|
59 |
image = Image.open('./title.jpg')
|
|
|
65 |
|
66 |
file = st.file_uploader("Upload any image and the model will try to provide a caption to it!", type= ['png', 'jpg'])
|
67 |
|
68 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
69 |
|
70 |
# We will override the default standardization of TextVectorization to preserve
|
71 |
# "<>" characters, so we preserve the tokens for the <start> and <end>.
|