我正在建立一个图像分类模型,但首先我需要读取用于训练的图像,并且我有105392张图像,因此我读取了我用cv2.imread_grayscale下载的本地图像并将图像的大小调整为100x100
train_images = []
img_array = cv2.imread(os.path.join(path,str(train_data.filename[idx])), cv2.IMREAD_GRAYSCALE)
new_array = cv2.resize(img_array,(img_size,img_size))
train_images.append(new_array)
然后我将图像数据添加到列表中,然后将它们转换为nparray并尝试将它们展平为1维,以便我可以保存到文本文件中以便于处理
ndarray = np.array(train_images)
ndarray2 = np.ndarray(ndarray)
flattenarray = ndarray2.flatten(order='C')
flattenarray.tofile('train_images_bitmap.txt')
但我收到此错误
Traceback (most recent call last):
File "comp2.py", line 36, in <module>
ndarray2 = np.ndarray(ndarray)
ValueError: maximum supported dimension for an ndarray is 32, found 105392
感谢您的帮助!
答案 0 :(得分:0)
您的ndarray数组的形状为(105392,100,100)以使该数组变平。
flatten_array = ndarray.reshape(1,105392*100*100)