Skip to content

Commit 69fa104

Browse files
committed
🎨 Use pre-trained ResNet50
1 parent b0e2be4 commit 69fa104

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

app.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,18 @@
2020
app = Flask(__name__)
2121

2222
# Model saved with Keras model.save()
23-
MODEL_PATH = 'models/densenet121.h5'
23+
MODEL_PATH = 'models/your_model.h5'
2424

25-
# Load model
26-
model = load_model(MODEL_PATH)
27-
model._make_predict_function() # Necessary
28-
print('Model loaded.')
25+
# Load your trained model
26+
# model = load_model(MODEL_PATH)
27+
# model._make_predict_function() # Necessary
28+
# print('Model loaded. Start serving...')
2929

3030
# You can also use pretrained model from Keras
31-
# https://keras.io/applications/
32-
# from keras.applications.resnet50 import ResNet50
33-
# model = ResNet50(weights='imagenet')
31+
# Check https://keras.io/applications/
32+
from keras.applications.resnet50 import ResNet50
33+
model = ResNet50(weights='imagenet')
34+
print('Model loaded. Check http://127.0.0.1:5000/')
3435

3536

3637
def model_predict(img_path, model):
@@ -42,8 +43,8 @@ def model_predict(img_path, model):
4243
x = np.expand_dims(x, axis=0)
4344

4445
# Be careful how your trained model deals with the input
45-
# otherwise, it won't make correct prediction
46-
x = preprocess_input(x, mode='torch')
46+
# otherwise, it won't make correct prediction!
47+
x = preprocess_input(x, mode='caffe')
4748

4849
preds = model.predict(x)
4950
return preds
@@ -71,7 +72,7 @@ def upload():
7172
preds = model_predict(file_path, model)
7273

7374
# Process your result for human
74-
# pre_class = preds.argmax(axis=-1) # Simple argmax
75+
# pred_class = preds.argmax(axis=-1) # Simple argmax
7576
pred_class = decode_predictions(preds, top=1) # ImageNet Decode
7677
result = str(pred_class[0][0][1]) # Convert to string
7778
return result

0 commit comments

Comments
 (0)