【发布时间】:2017-04-06 03:40:14
【问题描述】:
我正在尝试借助 keras 创建自己的图像识别程序,但遇到了问题。我正在尝试获取带有图片的文件夹并创建一个数据集供model.fit() 使用。我知道fit_generator(),但想知道生成器对图像做了什么。这就是为什么我要手动尝试从图像中创建一个数字数组/数据集。
我使用的模型是 VGG16,所以这是该模型的结束和开始:
model = Sequential()
model.add(ZeroPadding2D((1, 1), input_shape=(256, 256, 3)))
model.add(Convolution2D(64, 3, 3, activation='relu'))
model.add(ZeroPadding2D((1, 1)))
...
model.add(Dense(4096, activation='relu'))
model.add(Dropout(0.5))
model.add(Dense(3, activation='softmax'))
编译器:
sgd = SGD(lr=0.1, decay=1e-6, momentum=0.9, nesterov=True)
model.compile(optimizer=sgd, loss='categorical_crossentropy')
适合:
model.fit(test_x, 1, batch_size=32, nb_epoch=10, verbose=1, callbacks=None, validation_split=0.1)
数组生成器:
path_temp = %PATH%
list = os.listdir(path_temp)
array_list = []
for file in list:
img = imread(path_temp + '\\' + file, flatten=True)
img = np.arange(1 * 3 * 256 * 256).reshape((-1, 256, 256, 3))
img = img.astype('float32')
array_list.append(img)
test_x = np.stack(array_list)
test_x /= 255.0
错误:
ValueError: Error when checking model input: expected zeropadding2d_input_1 to have 4 dimensions, but got array with shape (990, 1, 256, 256, 3)
这就是我所拥有的,但有什么方法可以从这里为fit() 创建一个可读的数据集/数组吗?
【问题讨论】:
-
你看过我的回答了吗?
标签: dataset deep-learning keras