Update main.py
Browse files
main.py
CHANGED
@@ -1,4 +1,3 @@
|
|
1 |
-
import os
|
2 |
import io
|
3 |
from flask import Flask, request, jsonify
|
4 |
import base64
|
@@ -9,12 +8,9 @@ from keras.applications.xception import Xception #to get pre-trained model Xcept
|
|
9 |
from keras.models import load_model
|
10 |
from keras.preprocessing.sequence import pad_sequences
|
11 |
|
12 |
-
os.environ["TF_ENABLE_ONEDNN_OPTS"] = "0"
|
13 |
-
|
14 |
app = Flask(__name__)
|
15 |
|
16 |
-
|
17 |
-
MAX_LENGTH = 38
|
18 |
|
19 |
def extract_features(image_data, model):
|
20 |
try:
|
@@ -65,16 +61,12 @@ def generate_desc(model, tokenizer, photo, max_length):
|
|
65 |
def generate_caption():
|
66 |
try:
|
67 |
base64_image_data = request.form['image']
|
68 |
-
# return jsonify({'caption': base64_image_data}), 200
|
69 |
-
# Replace spaces with "+" characters to handle cases where "+" characters are missing
|
70 |
-
# base64_image_data = base64_image_data.replace(" ", "+")
|
71 |
|
72 |
# Decode the Base64 string into binary image data
|
73 |
image_data = base64.b64decode(base64_image_data)
|
74 |
|
75 |
tokenizer = load(open("tokenizer.p","rb"))
|
76 |
-
|
77 |
-
model = load_model('models/model_9.keras')
|
78 |
|
79 |
xception_model = Xception(include_top=False, pooling="avg")
|
80 |
photo = extract_features(image_data, xception_model)
|
|
|
|
|
1 |
import io
|
2 |
from flask import Flask, request, jsonify
|
3 |
import base64
|
|
|
8 |
from keras.models import load_model
|
9 |
from keras.preprocessing.sequence import pad_sequences
|
10 |
|
|
|
|
|
11 |
app = Flask(__name__)
|
12 |
|
13 |
+
MAX_LENGTH = 34
|
|
|
14 |
|
15 |
def extract_features(image_data, model):
|
16 |
try:
|
|
|
61 |
def generate_caption():
|
62 |
try:
|
63 |
base64_image_data = request.form['image']
|
|
|
|
|
|
|
64 |
|
65 |
# Decode the Base64 string into binary image data
|
66 |
image_data = base64.b64decode(base64_image_data)
|
67 |
|
68 |
tokenizer = load(open("tokenizer.p","rb"))
|
69 |
+
model = load_model('model_9.h5')
|
|
|
70 |
|
71 |
xception_model = Xception(include_top=False, pooling="avg")
|
72 |
photo = extract_features(image_data, xception_model)
|