简体   繁体   中英

tensorflow: CNN for non square image

tensorflow version 1.5.0rc1 python version:3.5

When reshape a rectangular image to [height,width] by using tf.reshape(x,[-1,x,y,1])

eg. tf.reshape(x,[-1,14,56,1]) run conv2d returns: InvalidArgumentError (see above for traceback): Input to reshape is a tensor with 358400 values, but the requested shape requires a multiple of 3136 [[Node: Reshape_1 = Reshape[T=DT_FLOAT, Tshape=DT_INT32, _device="/job:localhost/replica:0/task:0/device:GPU:0"](MaxPool_1, Reshape_1/shape)]]

which 3136 is the square of 56. the tensor treats the reshape as 56x56 instead of 14*56 matrix.

Is there a way to get rid of it and set my CNN to a non square image?

Thanks

I don't exactly agree with reshaping a rectangular picture as you destroy the relationship between neighbour pixels. Instead, you have several options to apply CNNs on a non-quadratic image:

1.) Use padding. During preprocessing, you could fill in pixels to get a quadratic image. Through this you can apply the quadratic filter.

2.) Use different quadratic windows of that image for training. For example, create a quadratic window and run it over the image to get a number of sub-pictures.

3.) You could use different strides for the dimensions of your picture.

4.) You could stretch the picture in the needed direction, although I'm not exactly sure how this affects the performance later on. I would only try this as a last resort solution.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM