Spaces:
Sleeping
Sleeping
Commit
·
3632e62
1
Parent(s):
ec5678b
Update app.py
Browse files
app.py
CHANGED
@@ -44,6 +44,30 @@ def load_image_model():
|
|
44 |
|
45 |
|
46 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
47 |
word_input = Input(shape=(MAX_CAPTION_LEN), name="words")
|
48 |
embed_x = Embedding(VOCAB_SIZE, ATTENTION_DIM)(word_input)
|
49 |
|
@@ -89,28 +113,10 @@ decoder_pred_model = tf.keras.Model(
|
|
89 |
inputs=[word_input, gru_state_input, encoder_output],
|
90 |
outputs=[decoder_output, gru_state],
|
91 |
)
|
|
|
92 |
|
93 |
-
|
94 |
-
|
95 |
-
# @st.cache_resource()
|
96 |
-
# def load_encoder_model():
|
97 |
-
# encoder=tf.keras.models.load_model('./encoder_model.h5')
|
98 |
-
# return encoder
|
99 |
|
100 |
|
101 |
-
@st.cache_resource()
|
102 |
-
def feature_extractor():
|
103 |
-
FEATURE_EXTRACTOR=tf.keras.models.load_model('./feature_extractor.h5')
|
104 |
-
return FEATURE_EXTRACTOR
|
105 |
-
|
106 |
-
|
107 |
-
FEATURE_EXTRACTOR = feature_extractor()
|
108 |
-
FEATURE_EXTRACTOR.trainable = False
|
109 |
-
image_input = Input(shape=(IMG_HEIGHT, IMG_WIDTH, IMG_CHANNELS))
|
110 |
-
image_features = FEATURE_EXTRACTOR(image_input)
|
111 |
-
x = Reshape((FEATURES_SHAPE[0] * FEATURES_SHAPE[1], FEATURES_SHAPE[2]))(image_features)
|
112 |
-
encoder_output = Dense(ATTENTION_DIM, activation="relu")(x)
|
113 |
-
encoder = tf.keras.Model(inputs=image_input, outputs=encoder_output)
|
114 |
|
115 |
st.title(":blue[Nishant Guvvada's] :red[AI Journey] Image Caption Generation")
|
116 |
image = Image.open('./title.jpg')
|
|
|
44 |
|
45 |
|
46 |
|
47 |
+
|
48 |
+
|
49 |
+
# @st.cache_resource()
|
50 |
+
# def load_encoder_model():
|
51 |
+
# encoder=tf.keras.models.load_model('./encoder_model.h5')
|
52 |
+
# return encoder
|
53 |
+
|
54 |
+
|
55 |
+
@st.cache_resource()
|
56 |
+
def feature_extractor():
|
57 |
+
FEATURE_EXTRACTOR=tf.keras.models.load_model('./feature_extractor.h5')
|
58 |
+
return FEATURE_EXTRACTOR
|
59 |
+
|
60 |
+
|
61 |
+
FEATURE_EXTRACTOR = feature_extractor()
|
62 |
+
FEATURE_EXTRACTOR.trainable = False
|
63 |
+
image_input = Input(shape=(IMG_HEIGHT, IMG_WIDTH, IMG_CHANNELS))
|
64 |
+
image_features = FEATURE_EXTRACTOR(image_input)
|
65 |
+
x = Reshape((FEATURES_SHAPE[0] * FEATURES_SHAPE[1], FEATURES_SHAPE[2]))(image_features)
|
66 |
+
encoder_output = Dense(ATTENTION_DIM, activation="relu")(x)
|
67 |
+
encoder = tf.keras.Model(inputs=image_input, outputs=encoder_output)
|
68 |
+
|
69 |
+
|
70 |
+
#****
|
71 |
word_input = Input(shape=(MAX_CAPTION_LEN), name="words")
|
72 |
embed_x = Embedding(VOCAB_SIZE, ATTENTION_DIM)(word_input)
|
73 |
|
|
|
113 |
inputs=[word_input, gru_state_input, encoder_output],
|
114 |
outputs=[decoder_output, gru_state],
|
115 |
)
|
116 |
+
# ****
|
117 |
|
|
|
|
|
|
|
|
|
|
|
|
|
118 |
|
119 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
120 |
|
121 |
st.title(":blue[Nishant Guvvada's] :red[AI Journey] Image Caption Generation")
|
122 |
image = Image.open('./title.jpg')
|