【发布时间】:2018-08-15 12:08:16
【问题描述】:
mypath='/Users/sachal/Desktop/data_raw/normal_1/images'
onlyfiles = [ f for f in listdir(mypath) if isfile(join(mypath,f)) ]
images = np.asarray(np.empty(len(onlyfiles), dtype=object))
for n in range(0, len(onlyfiles)):
images[n] = cv2.imread( join(mypath,onlyfiles[n]) )
#--------------------------------------------------------------------------------
resized = np.asarray(np.empty(len(onlyfiles), dtype=object))
img_f = np.asarray(np.empty(len(onlyfiles), dtype=object))
for n in range(0, len(onlyfiles)):
resized[n] = cv2.resize(images[n],(101,101))
img_f[n] = cv2.cvtColor(resized[n], cv2.COLOR_BGR2YUV)
train_img = np.asarray(img_f)
#--------------------------------------------------------------------------------
在上面的代码中,我首先使用 opencv 加载图像,然后在第二个块中调整大小并更改它们的颜色空间。
我的批量大小是6408,图像尺寸是101*101*3
当我做train_img.shape 时,我得到(6408,) 和train_img[i].shape 我得到101*101*3,因此我无法训练我的神经网络模型,我想要的尺寸是6408*101*101*3
我尝试用这个train_img.resize(6408,101,101,3) 重塑我得到这个ValueError: cannot resize an array that references or is referenced
by another array in this way. Use the resize function
在拟合我的模型时,我收到了这个错误Error when checking input: expected conv2d_3_input to have 4 dimensions, but got array with shape (6408, 1)
我想知道是否可以使用当前加载图像的方法更改输入的尺寸。
【问题讨论】:
-
请尝试提供一个没有本地数据链接的工作示例。嵌入一个带有值的小矩阵以显示您的意思。
-
我想要的是
[1 1 1 1]这种类型的矩阵,但我得到的是首先是 6408 个元素的列表,然后每个元素是 [1 1 1]
标签: python arrays numpy opencv