Я использую существующую модель Keras, которую сделал мой сокурсник, и пытаюсь внедрить CNN, но я продолжаю получать эту ошибку
ValueError: Error when checking model input: expected convolution2d_input_9 to have 4 dimensions, but got array with shape (3938, 4, 42)
Вот лог
runfile('C:/Users/a_phi/Downloads/hand-pred-20190324T215735Z-001/hand-pred/model_lstmAshwin-train.py', wdir='C:/Users/a_phi/Downloads/hand-pred-20190324T215735Z-001/hand-pred')
Reloaded modules: myFileHandler
x_train (3938, 4, 42)
y_train (3938, 6)
saving scaler object to Scaler.sav
Compilation Time : 0.026177644729614258
____________________________________________________________________________________________________
Layer (type) Output Shape Param # Connected to
====================================================================================================
convolution2d_24 (Convolution2D) (None, 26, 26, 32) 320 convolution2d_input_11[0][0]
____________________________________________________________________________________________________
activation_10 (Activation) (None, 26, 26, 32) 0 convolution2d_24[0][0]
____________________________________________________________________________________________________
convolution2d_25 (Convolution2D) (None, 24, 24, 64) 18496 activation_10[0][0]
____________________________________________________________________________________________________
maxpooling2d_12 (MaxPooling2D) (None, 12, 12, 64) 0 convolution2d_25[0][0]
____________________________________________________________________________________________________
dropout_22 (Dropout) (None, 12, 12, 64) 0 maxpooling2d_12[0][0]
____________________________________________________________________________________________________
flatten_10 (Flatten) (None, 9216) 0 dropout_22[0][0]
____________________________________________________________________________________________________
dense_20 (Dense) (None, 128) 1179776 flatten_10[0][0]
____________________________________________________________________________________________________
dropout_23 (Dropout) (None, 128) 0 dense_20[0][0]
____________________________________________________________________________________________________
dense_21 (Dense) (None, 10) 1290 dropout_23[0][0]
====================================================================================================
Total params: 1,199,882
Trainable params: 1,199,882
Non-trainable params: 0
____________________________________________________________________________________________________
Now to train the model using the fit() method
Traceback (most recent call last):
File "<ipython-input-19-d0bd53cbab62>", line 1, in <module>
runfile('C:/Users/a_phi/Downloads/hand-pred-20190324T215735Z-001/hand-pred/model_lstmAshwin-train.py', wdir='C:/Users/a_phi/Downloads/hand-pred-20190324T215735Z-001/hand-pred')
File "C:\Users\a_phi\Anaconda3\envs\cpr_lstm07\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 668, in runfile
execfile(filename, namespace)
File "C:\Users\a_phi\Anaconda3\envs\cpr_lstm07\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 108, in execfile
exec(compile(f.read(), filename, 'exec'), namespace)
File "C:/Users/a_phi/Downloads/hand-pred-20190324T215735Z-001/hand-pred/model_lstmAshwin-train.py", line 627, in <module>
verbose=2)
File "C:\Users\a_phi\Anaconda3\envs\cpr_lstm07\lib\site-packages\keras\models.py", line 672, in fit
initial_epoch=initial_epoch)
File "C:\Users\a_phi\Anaconda3\envs\cpr_lstm07\lib\site-packages\keras\engine\training.py", line 1116, in fit
batch_size=batch_size)
File "C:\Users\a_phi\Anaconda3\envs\cpr_lstm07\lib\site-packages\keras\engine\training.py", line 1029, in _standardize_user_data
exception_prefix='model input')
File "C:\Users\a_phi\Anaconda3\envs\cpr_lstm07\lib\site-packages\keras\engine\training.py", line 112, in standardize_input_data
str(array.shape))
ValueError: Error when checking model input: expected convolution2d_input_11 to have 4 dimensions, but got array with shape (3938, 4, 42)
Я незнаком с Керасом и не уверен, как это исправить.
def build_model2(dataIn, timeWindow, layerOut, outputs, activation,
optimizer):
layerOut = 84
layerOutExpand = 100
dataIn = 42
timeWindow = 20
outputs = 6
# Takes feature data matrix row size as input = 42
# Returns vector of size 20 (timeWindow) as output
num_classes = 10
model = Sequential()
model.add(Convolution2D(32, 3, 3, input_shape=(28, 28, 1)))
model.add(Activation('relu'))
model.add(Conv2D(64,3,3))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Dropout(0.25))
model.add(Flatten())
model.add(Dense(128, activation='relu'))
model.add(Dropout(0.5))
model.add(Dense(num_classes, activation='softmax'))
# Compile the model and time how long it takes
start = time.time()
#optimizer = SGD(lr=0.3, momentum=0.9)
model.compile(loss="mse", optimizer=optimizer, metrics=[coeffDetermination, 'accuracy'])
print("Compilation Time : ", time.time() - start)
# Let's see the model details too, and create an image file of the
# network structure
model.summary()
return model
Другие решения, которые я видел, я не мог понять или заставить их работать.
Я не знаком с Keras / TensorFlow, поэтому любая помощь будет принята.