DrowsyDriverDetection
DrowsyDriverDetection copied to clipboard
Negative dimension size caused by subtracting 3 from 1 for 'conv2d_2/convolution'
I m building eyesCNN.py
but there are some error in build time. do you know how to fix it? is there any version problem with my tf version?? (tf version : 1.1.0) (python ver : 3.6)
/home/rainman/anaconda3/bin/python /home/rainman/src_python/DrowsyDriverDetection/eyesCNN.py
Using TensorFlow backend.
here
Training set (3876, 24, 24, 1) (3876, 1)
Test set (970, 24, 24, 1) (970, 1)
3876 train samples, 24 channel, 1x24
970 test samples, 24 channel, 1x24
/home/rainman/src_python/DrowsyDriverDetection/eyesCNN.py:63: UserWarning: Update your Conv2D
call to the Keras 2 API: Conv2D(32, (3, 3), input_shape=(1, 24, 24..., padding="same")
input_shape=(img_channels, img_rows, img_cols)))
/home/rainman/src_python/DrowsyDriverDetection/eyesCNN.py:65: UserWarning: Update your Conv2D
call to the Keras 2 API: Conv2D(24, (3, 3))
model.add(Convolution2D(24, 3, 3))
Traceback (most recent call last):
File "/home/rainman/anaconda3/lib/python3.6/site-packages/tensorflow/python/framework/common_shapes.py", line 671, in _call_cpp_shape_fn_impl
input_tensors_as_shapes, status)
File "/home/rainman/anaconda3/lib/python3.6/contextlib.py", line 89, in exit
next(self.gen)
File "/home/rainman/anaconda3/lib/python3.6/site-packages/tensorflow/python/framework/errors_impl.py", line 466, in raise_exception_on_not_ok_status
pywrap_tensorflow.TF_GetCode(status))
tensorflow.python.framework.errors_impl.InvalidArgumentError: Negative dimension size caused by subtracting 3 from 1 for 'conv2d_2/convolution' (op: 'Conv2D') with input shapes: [?,1,24,32], [3,3,32,24].
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/rainman/src_python/DrowsyDriverDetection/eyesCNN.py", line 65, in
Process finished with exit code 1
I encountered a similar problem when I tried the execution with both tensorflow and theano backends.
An easy fix that worked for implementations backed by either of tensorflow or theano was a simple modification of the keras config file that exists as .keras/keras.json
, change your input image_data_format
field from channels_last to channels_first
after the change the file should look something like:
{ "epsilon": 1e-07, "floatx": "float32", "image_data_format": "channels_first", "backend": "theano" }
I get similar error:
model :
model = Sequential()
print 'input_shape', input_shape
num_classes = 2
model.add(Conv2D(32, (5, 5),
padding='same',
data_format='channels_last',
input_shape=input_shape))
model.add(BatchNormalization())
model.add(Activation('relu'))
model.add(Conv2D(32, (3, 3)))
model.add(BatchNormalization())
model.add(Activation('relu'))
model.add(MaxPooling2D(pool_size=(3, 3)))
model.add(Dropout(0.25))
model.add(Conv2D(64, (3, 3), padding='same'))
model.add(BatchNormalization())
model.add(Activation('relu'))
model.add(Conv2D(64, (3, 3)))
model.add(Activation('relu'))
model.add(MaxPooling2D(pool_size=(3, 3)))
model.add(Dropout(0.25))
model.add(Flatten())
model.add(Dense(512))
model.add(Activation('relu'))
model.add(Dropout(0.5))
model.add(Dense(num_classes))
model.add(Activation('softmax'))
input_shape (20, 10, 1).
Please help I get error :
I also faced this issue
check my pull request, the code needed update
or you go in this way,change the way reshape X_train = train_dataset X_train = X_train.reshape((X_train.shape[0], X_train.shape[1],X_train.shape[2],X_train.shape[3])) Y_train = train_labels
X_test = test_dataset X_test = X_test.reshape((X_test.shape[0], X_test.shape[1],X_test.shape[2],X_test.shape[3])) Y_test = test_labels