0

I am a starter for the CNN DL. During CNN code I faced this error:

Negative dimension size caused by subtracting 3 from 1 for 'conv2d_3/convolution' (op: 'Conv2D') with input shapes: [?,19,1,64], [3,3,64,64]

My image data show 300(w), 855(h) pixels size.

For the np array transformation, I applied below.

(width,height = 28)->>
img = cv2.resize(img, None, fx = img_width/img.shape[0], fy = img_height/img.shape[1])
                x.append(img/256)
                y.append(label)

And then, I tried CNN by using this:

model.add(Convolution2D(16,(3,3), border_mode='same', activation='relu', input_shape=x_train.shape[1:]))

x_train.shape[1:] = (80,10,3)

Please help to fix this error. Thank you for read.

Dhia Djobbi
  • 1,176
  • 2
  • 15
  • 35
ksj
  • 1

1 Answers1

0

you have an input with the shape (19x1x64) where 64 is the number of channels. That's why your 3x3 convolution operation cannot be performed. What probably is happening:
- you are resizing your image in a wrong way (hence the 19x1x64 dimension as opposed to the 28x28x3 you potentially intended to achieve).
How to solve this? check out your resizing again and print your image shape after resize, see if this is what you aimed for.

TheEngineer
  • 792
  • 6
  • 18
  • #TheEngineer Thank you for the ans. As follow your ans, I think that ma major problem is resize. Before the consideration of it, I have one more Q. At first, i gave input_shape (80,10,3). It means 80,10 size and 3 channels. But you commented 64 in error sentence is # of channels. Can you answer the details of it? Thank you for reading. – ksj Jun 01 '20 at 04:01
  • #TheEngineer Also, I don't know how (19x1x64) happened at the error sentence. If it is possible, please give ans. Thank you. – ksj Jun 01 '20 at 04:04
  • Let's try something. Comment out your code for anything else beside the resizing. Try to load your image, resize and print it's shape. That would be a good first step to see what kind of image shape we are getting after the resize. – TheEngineer Jun 01 '20 at 17:29
  • Finally, I solved this problem. The resized value depend on the size of original image data. So I had to consider the size of original data before decision of resized value. Thank you for your help. Have a nice day! – ksj Jun 06 '20 at 05:22
  • I am glad it worked out. FYI, if the answer provided was helpful, please accept it as correct answer so that the question is marked as closed. – TheEngineer Jun 07 '20 at 03:16