Beispiel #1
0
def predict():
    if (request.method == 'POST'):
        file = request.files.get('file')
        if file is None or file.filename == "":
            return jsonify({'error': 'no file'})

        if not allowed_file(file.filename):
            return jsonify({'error': 'not supported'})

        try:
            img_bytes = file.read()
            tensor = transform_image(img_bytes)
            prediction = get_predication(tensor)

            data = {
                'prediction': prediction.item(),
                'class_name': str(prediction.item())
            }

            return jsonify(data)

        except Exception as e:
            print(e)
            return jsonify({'error': 'Error during Predictions'})
    # 1. Load the image

    # 2. image -> tensor
    # 3. predication
    # 4. return json
    return jsonify({'result': 1})
Beispiel #2
0
def predict():
    if request.method == 'POST':
        file = request.files.get('file')
        if file is None or file.filename == "":
            return jsonify({'error': 'no file'})
        if not allowed_file(file.filename):
            return jsonify({'error': 'format not supported'})

        try:
            img_bytes = file.read()
            tensor = transform_image(img_bytes)
            prediction = get_prediction(tensor)
            data = {'prediction': prediction.item(), 'class_name': str(prediction.item())}
            return jsonify(data)
        except:
            return jsonify({'error': 'error during prediction'})
Beispiel #3
0
def predick():
    if request.method in ['POST', 'PUT']:
        file = request.files.get('file')
        if file is None or file.filename == "":
            return jsonify({'error': 'no file'})
        if not allowed_file(file.filename):
            return jsonify({'error': 'format not supported'})
        try:
            img_bytes = file.read()
            tensor = transform_image(img_bytes)
            prediction = get_prediction(tensor)

            probability = "{:.2%}".format(prediction[1].item())

            data = {'prediction_id': prediction[0].item(), 'class_name': str(classes[prediction[0].item()]), 'probability': probability}
            return jsonify(data)
        except Exception as e:
            return jsonify({'error': str(e)})   
Beispiel #4
0
def main_post():
    file = request.files.get("image")
    print("=" * 80)
    print(request.headers)
    print(list(request.files.keys()))
    print(list(request.form.keys()))
    if file is None or file.filename == "":
        return jsonify(dict(error="no file"))
    if not allowed_file(file.filename):
        return jsonify(dict(error="format not supported"))
    try:
        image_bytes = file.read()
        image_tensor = transform_image(image_bytes)
        probability, prediction = get_prediction(image_tensor)
        data = dict(
            probability=probability.item(), prediction=labels[str(prediction.item())]
        )
        print(data)
        return jsonify(data)
    except:
        return jsonify(dict(error="error during prediction"))