Пример #1
0
def predictResNet50():
    if request.method == 'POST':
        file_path = get_file_path_and_save(request)

        img = image.load_img(file_path, target_size=(224, 224))

        # Preprocessing the image
        x = image.img_to_array(img)
        # x = np.true_divide(x, 255)
        x = np.expand_dims(x, axis=0)

        # Be careful how your trained model deals with the input
        # otherwise, it won't make correct prediction!
        x = preprocess_input_resNet50(x, mode='caffe')
        # Make prediction
        preds = modelResNet50.predict(x)

        # Process your result for human
        # pred_class = preds.argmax(axis=-1)            # Simple argmax
        pred_class = decode_predictions_resNet50(preds,
                                                 top=3)  # ImageNet Decode

        result1 = pred_class[0][0]
        f1 = "{0:.2f}".format(round(result1[2] * 100, 2))
        a = result1[1] + "    " + str(f1)
        # print(a)

        result2 = pred_class[0][1]
        f2 = "{0:.2f}".format(round(result2[2] * 100, 2))
        b = result2[1] + "    " + str(f2)
        # print(b)

        result3 = pred_class[0][2]
        f3 = "{0:.2f}".format(round(result3[2] * 100, 2))
        c = result3[1] + "    " + str(f3)
        # print(c)

        result = a + "\n" + b + "\n" + c
        #print(result)
        return result
    return None
Пример #2
0
def predictResNet50():
    if request.method == 'POST':
        file_path = get_file_path_and_save(request)

        img = image.load_img(file_path, target_size=(224, 224))

        # Preprocessing the image
        x = image.img_to_array(img)
        # x = np.true_divide(x, 255)
        x = np.expand_dims(x, axis=0)

        # Be careful how your trained model deals with the input
        # otherwise, it won't make correct prediction!
        x = preprocess_input_resNet50(x, mode='caffe')
        # Make prediction
        preds = modelResNet50.predict(x)

        # Process your result for human
        # pred_class = preds.argmax(axis=-1)            # Simple argmax
        pred_class = decode_predictions_resNet50(preds,
                                                 top=1)  # ImageNet Decode
        result = str(pred_class[0][0][1])  # Convert to string
        return result
    return None
Пример #3
0
from __future__ import division, print_function