Example #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': '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'})
Example #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 = Image.open(request.files['file'])
        img = torch.FloatTensor([process_image(img)])
        pred = get_prediction(img)
        return jsonify(pred)
        # except:
        # return jsonify({'error': 'error during prediction'})

    return jsonify({'result': 1})
Example #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)})   
Example #4
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:
            image_bytes = file.read()
            image_tensor = tranform_image(image_bytes)
            prediction = get_prediction(image_tensor)
            data = {
                "prediction": prediction.item(),
                "class_name": str(prediction.item())
            }
            return jsonify(data)
        except:
            return jsonify({"error": "error during prediction"})
Example #5
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"))