Python 当我转换预测值时,这给了我Indexer错误:标量变量的索引无效

Python 当我转换预测值时,这给了我Indexer错误:标量变量的索引无效,python,pandas,numpy,tensorflow,keras,Python,Pandas,Numpy,Tensorflow,Keras,结果=str(pred_类[0][0][1])#转换为字符串 索引器错误:标量变量的索引无效。 127.0.0.1---[18/Mar/2021 13:10:07]“POST/predict HTTP/1.1”500-如果make_predict=[[0.1.0.0.0.0.]],则尝试访问从pred_class[0][0]获得的整数0的第一个索引,因此通过删除result=str 0(pred_class[0][0][0]中的冗余索引器)并将其更改为result=str(pred_class[

结果=str(pred_类[0][0][1])#转换为字符串 索引器错误:标量变量的索引无效。
127.0.0.1---[18/Mar/2021 13:10:07]“POST/predict HTTP/1.1”500-

如果
make_predict=[[0.1.0.0.0.0.]]
,则尝试访问从
pred_class[0][0]
获得的整数
0
的第一个索引,因此通过删除
result=str 0(pred_class[0][0][0]中的冗余索引器)
并将其更改为
result=str(pred_class[0][0])#Convert to string
应该可以解决这个问题


干杯。

您能提供一个简单的代码,可以独立运行,只重现您面临的问题吗?我的意思是-什么是pred_课程?Thanks@MichaelSidorov简单地说,它显示这个preds[[0.1.0.0.0.0.]]make predict[[0.1.0.0.0.0.][1]-简单地说,这些是print语句[1]表示类的索引将
print(pred_类)的结果添加到您的问题中
语句。您在评论中显示的值很难阅读,而且似乎不相关。您/我们需要找出3级索引的问题所在。是的,它可以工作,但当return语句执行时,它会显示类似数组的结果:[0],因此“0”会显示相关的类索引。如何以字符串形式显示类名
@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