Kevin Qiu
Kevin Qiu

Reputation: 37

Issue with tensorflow shape with b/w images

I'm a tensorflow beginner so please bear with me. Right now I am trying to modifiy an existing python programm for a CNN that creates a superresolution image. The Code can be found here if you're interested: https://github.com/pinae/Superresolution

The input tensor has the shape <5,240,320,3>, 5 being batch size, 240 and 320 the size of the image(s) and 3 being the number of channels (RGB). I want to modify this program for black and white images, so just 1 channel -> <5,240,320,1>

First, I convert the testing and validation images to b/w:

   image = image.convert('L')

The images then get written into an array and this is where my issue starts. The array will have the size of <240,320>. The array of 5 images get written into a list and is handed over to tensorflow.

Tensorflow expects a <5,240,320,1> tensor but the list of images has the shape <5,240,320>, so one dimension is missing. I tried adding a dimension with np.expand_dims and the like but no success.

    input_batches = np.expand_dims(input_batches, axis=-1)

Why does the index of channels of a tensorflow placeholder seem to start at 1 while the index of resolution starts at 0?

I'm sure there will be many more issues down the road like adjusting the filters but this is where I'm stuck now.

Upvotes: 0

Views: 360

Answers (2)

Anton Panchishin
Anton Panchishin

Reputation: 3773

If you have a tensor of shape [5,240,320] you can reshape it to be [5,240,320,1] with this one command

correctSizedTensor = tf.reshape( wrongSizedTensor, [5,240,320,1] )

Upvotes: 1

jkschin
jkschin

Reputation: 5844

You need to understand the code. I believe the problem may be deeper rooted. With the limited information, I assume you are using network.py. In there, we see this in line 16:

    self.inputs = tf.placeholder(
        tf.float32, [batch_size, dimensions[1], dimensions[0], 3], name='input_images'
    )

The depth dimension is already hard coded as 3. You would have to edit that as well, amongst possibly many other things.

As a caveat, most super-resolution CNNs use small patch sizes. Definitely not (240, 320), I suspect it will be hard to converge as the batch size is small.

Upvotes: 0

Related Questions