DEFINE FUNCTION predict(filename): |
#Step 1 |
SET my_image TO plt.imread(os.path.join(‘uploads’, filename)) |
#Step 2 |
SET my_image_read TO resize(my_image (224,224,1)) |
#Step 3 |
CALL #F with graph.as_default(): |
CALL #F set_session(sess) |
SET #Fmodel TO tf.keras.models.load_model(“model_name.h5”) |
CALL #F model.compile(optimizer = tf.keras.optimizers.Adam(learning_rate =),#‘adam’, |
loss = ‘categorical_cross-entropy’, |
metrics = [‘accuracy’]) |
SET #F probabilities TO model.predict(np.array([my_image_read])) [0,:] |
CALL #F OUTPUT(probabilities) |
#Step 4 |
SET number_to_class TO [‘fifty’, ‘five’, ‘hundred’, ‘ten’, ‘twohundred’] |
SET #F index TO np.argsort(probabilities) |
SET predictions TO {“class1”: number_to_class[index [3]], |
“class2”:number_to_class[index [2]], |
“class3”:number_to_class[index [1]], |
“prob1”:probabilities[index [3]], |
“prob2”:probabilities[index [2]], |
“prob3”:probabilities[index [1]]} |
#Step 5 |
CALL #F RETURN render template(‘predict.html’, predictions = predictions) |