我正在使用一个同学为我制作的现有Keras模型,并尝试实现CNN,但是我一直收到此错误
ValueError: Error when checking model input: expected convolution2d_input_9 to have 4 dimensions, but got array with shape (3938, 4, 42)
Here is the log
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)
I am unfamiliar with Keras and not sure how to correct this.
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)
我所见过的其他解决方案我无法理解或无法使用。 我对Keras / TensorFlow不熟悉,因此不胜感激。