【发布时间】:2021-06-15 14:20:07
【问题描述】:
@app.route('/predict', methods=['GET', 'POST'])
def upload():
if request.method == 'POST':
# Get the file from post request
f = request.files['file']
# Save the file to ./uploads
basepath = os.path.dirname(__file__)
file_path = os.path.join(
basepath, 'uploads', secure_filename(f.filename))
f.save(file_path)
# Make prediction
preds = model_predict(file_path, model)
print('make predict', preds)
# Process your result for human
pred_class = preds.argmax(axis=-1) # Simple argmax
print(pred_class)
# pred_class = decode_predictions(preds, top=1) # ImageNet Decode
result = str(pred_class[0][0][1]) # Convert to string
return result
return None
result = str(pred_class[0][0][1]) # 转换为字符串 IndexError:标量变量的索引无效。 127.0.0.1 - - [18/Mar/2021 13:10:07] “POST /predict HTTP/1.1”500 -
【问题讨论】:
-
您能否提供一个可以独立运行的简单代码,它只重现您面临的问题?我的意思是 - pred_class 是什么?谢谢
-
@MichaelSidorov 只是它显示了这个预测 [[0. 1. 0. 0. 0. 0. 0.]] 预测 [[0. 1. 0. 0. 0. 0. 0.]] [1] - 这些只是打印语句 [1] 表示类的索引
-
将
print(pred_class)语句的结果添加到您的问题中。您在评论中显示的值很难阅读,并且似乎不相关。您/我们需要弄清楚 3 级索引有什么问题。
标签: python pandas numpy tensorflow keras