Ошибка ОС: невозможно определить файл образа - PullRequest
0 голосов
/ 11 апреля 2019

Я получаю ошибку. Я перепробовал все предыдущие решения в интернете, но они не работают. Я полагаю, проблема в image = Image.open(myvar), но не в получении.

def get_model():global model
     model = load_model('Plant_Village.h5')
     print(" * Model loaded!")
def preprocess_image(image,target_size):
    image = image.resize(target_size)
    image = img_to_array(image)
    image = np.expand_dims(image,axis=0)
return image
print(" * Loading Keras model...")
get_model()
@app.route("/predict",methods=['GET','POST'])
def predict():
   message = request.get_json(force=True)
   encoded = message['image']
   decoded = base64.b64decode(encoded)
   myvar=io.BytesIO(decoded)
   print(myvar)
   image = Image.open(myvar)
   processed_image = preprocess_image(image, target_size=(256,256))
   #print("image returned")
   prediction = model.predict(processed_image).tolist()
   print("hello")
   respons={
    'prediction':{
        'Pepper__bell___Bacterial_spot':prediction[1][0][0][0][0][0][0][0][0][0][0][0][0][0][0],
        'Pepper__bell___healthy':prediction[0][1][0][0][0][0][0][0][0][0][0][0][0][0][0],
        'Potato___Early_blight':prediction[0][0][1][0][0][0][0][0][0][0][0][0][0][0][0],
        'Potato___healthy':prediction[0][0][0][1][0][0][0][0][0][0][0][0][0][0][0],
        'Potato___Late_blight':prediction[0][0][0][0][1][0][0][0][0][0][0][0][0][0][0],
        'Tomato__Target_Spot':prediction[0][0][0][0][0][1][0][0][0][0][0][0][0][0][0],
        'Tomato__Tomato_mosaic_virus':prediction[0][0][0][0][0][0][1][0][0][0][0][0][0][0][0],
        'Tomato__Tomato_YellowLeaf__Curl_Virus':prediction[0][0][0][0][0][0][0][1][0][0][0][0][0][0][0],
        'Tomato_Bacterial_spot':prediction[0][0][0][0][0][0][0][0][1][0][0][0][0][0][0],
        'Tomato_Early_blight':prediction[0][0][0][0][0][0][0][0][0][1][0][0][0][0][0],
        'Tomato_healthy':prediction[0][0][0][0][0][0][0][0][0][0][1][0][0][0][0],
        'Tomato_Late_blight':prediction[0][0][0][0][0][0][0][0][0][0][0][1][0][0][0],
        'Tomato_Leaf_Mold':prediction[0][0][0][0][0][0][0][0][0][0][0][0][1][0][0],
        'Tomato_Septoria_leaf_spot':prediction[0][0][0][0][0][0][0][0][0][0][0][0][0][1][0],
        'Tomato_Spider_mites_Two_spotted_spider_mite':prediction[0][0][0][0][0][0][0][0][0][0][0][0][0][0][1]
    }
}
response=json.stringfy(respons)
return jsonify(response)

enter image description here

enter image description here

...