出现错误,此行“ res = res / 255.0” TypeError:/不支持的操作数类型:“ NoneType”和“ float”

问题描述 投票:0回答:1

我正在尝试重塑图像,然后发送模型以预测它使用的是Tensorflow(v-2.0)和python(v-3.6)是哪个数字,但收到错误“ TypeError:/不支持的操作数类型:' NoneType'和'float'“。

   path=cv2.imread('home/farhana/Desktop/image processing/code/7.jpg')
     img = cv2.imread(path,cv2.IMREAD_GRAYSCALE)
     res=img
     res = res / 255.0
     res = res.resize(28,28)
     res = res.reshape((len(img), 28, 28,1))
     res = res.reshape(28,28,1)
python-3.x tensorflow image-processing conv-neural-network tensorflow-datasets
1个回答
0
投票

file是输入jpg的路径字符串(类似于Windows上的'D:/folder/test.jpg',请尝试

import cv2
import numpy as np

img = cv2.imread(file, cv2.IMREAD_GRAYSCALE).astype(np.float64)
res = img/255
res = cv2.resize(res, (28, 28)).reshape(28, 28, 1)
© www.soinside.com 2019 - 2024. All rights reserved.