TypeError 在 /image/ 处发生:期望字符串或Unicode对象,发现InMemoryUploadedFile

我已经构建了一个图像处理分类器,并且在这段代码中,我正在创建一个API,它接受键为’test_image’的输入图像,并预测图像的类别,但cv2.imread()出现了这个错误

TypeError 在 /image/ 处发生:期望字符串或Unicode对象,发现InMemoryUploadedFile

我知道cv2.imread只能接受图像的URL,但我不知道如何解决这个问题。

我的代码:

def classify_image(request):    if request.method == 'POST' and request.FILES['test_image']:        test_image = request.FILES['test_image']        test_image = cv2.imread(test_image)        test_image = cv2.resize(test_image, (128, 128))        test_image = np.array(test_image)        test_image = test_image.astype('float32')        test_image /= 255        print(test_image.shape)        test_image = np.expand_dims(test_image, axis=0)        pred = model.predict_classes(test_image)        print(pred)   return JsonResponse(pred, safe=False)

回答:

我找到了答案,imread 只接受文件路径。

Related Posts

L1-L2正则化的不同系数

我想对网络的权重同时应用L1和L2正则化。然而,我找不…

使用scikit-learn的无监督方法将列表分类成不同组别,有没有办法?

我有一系列实例,每个实例都有一份列表,代表它所遵循的不…

f1_score metric in lightgbm

我想使用自定义指标f1_score来训练一个lgb模型…

通过相关系数矩阵进行特征选择

我在测试不同的算法时,如逻辑回归、高斯朴素贝叶斯、随机…

可以将机器学习库用于流式输入和输出吗?

已关闭。此问题需要更加聚焦。目前不接受回答。 想要改进…

在TensorFlow中,queue.dequeue_up_to()方法的用途是什么?

我对这个方法感到非常困惑,特别是当我发现这个令人费解的…

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注