【发布时间】:2018-08-23 20:07:18
【问题描述】:
嘿,伙计们从 ML 开始,并训练了我的第一个分类器。 使用带有狗/猫图像的 Microsoft 数据集。
我正在尝试将图像 > 数组 > 操作返回到图像文件。 我尝试了很多事情,但无法做到。
我有图像(500x500,jpg),我正在使用 cv2.imread 读取这些图像并将值保存在列表中。 IMG_SIZE = 100
img_array = cv2.imread(os.path.join(path, img), cv2.IMREAD_GRAYSCALE)
new_array = cv2.resize(img_array, (IMG_SIZE, IMG_SIZE))
test_data.append([new_array, class_num])
X_test = []
y_test = []
for features, label in test_data:
X_test.append(features)
y_test.append(label)
X_test = np.array(X_test).reshape(-1, IMG_SIZE, IMG_SIZE, 1)
X_test = X_test / 255
我尝试的只是撤消操作。
img_orig = X_test[:]
img_orig = img_orig * 255
img_orig.astype(int)
img_orig = PIL.Image.fromarray(np.uint8(img_orig))
出现以下错误
File "xxx\lib\site-packages\PIL\Image.py", line 2460, in fromarray
mode, rawmode = _fromarray_typemap[typekey]
KeyError: ((1, 1, 1), '|u1')
File "xxx\CatDog_predict.py", line 78, in <module>
img_orig = PIL.Image.fromarray(np.uint8(img_orig))
File "xxx\site-packages\PIL\Image.py", line 2463, in fromarray
raise TypeError("Cannot handle this data type")
TypeError: Cannot handle this data type
我错过了什么?
谢谢
【问题讨论】:
-
我认为您只需要更改这一行代码:
img_orig = img_orig.astype(int),然后如果您只想查看图片。
标签: python arrays image numpy reverse