1
我想在keras的幫助下創建自己的圖像識別程序,但是我遇到了問題。我正在試圖帶圖片的文件夾並創建要使用的model.fit()
的數據集。我知道fit_generator()
,但試圖知道發電機與圖像做什麼。這就是爲什麼我試圖從圖像創建一個數組/數據集。在Keras創建可讀的圖像數據集培訓
我使用的模型是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()
可讀數據集/陣列?
你看過我的回答嗎? –