1

I am facing the following issue with tf.image.central_crop()

def preprocessor(image):
    image = tf.reshape(image, (IMAGE_HEIGHT, IMAGE_WIDTH, IMAGE_CHANNELS))
    print(image.get_shape())
    image = tf.image.central_crop(image,0.8)
    print(image.get_shape())
    return image

which outputs

(384, 384, 3)  and (?, ?, 3)

the central_crop() function seems to lose information about the height and the width of the image tensor. Why does this happen?

Tensorflow version:  tensorflow 1.0.0, tensorflow-gpu 1.0.1
Sekar Raj
  • 113
  • 1
  • 1
  • 11
user3142067
  • 1,222
  • 3
  • 13
  • 26

1 Answers1

1

You are correct. Not able to retrieve the shape of tensor unless its evaluated. You could use "tf.shape(image)" if you wants to use it for next operations.

TF cropped the image but not able get its shape. If you want to just check if it is doing it or not, follow this (run session):

import tensorflow as tf
import numpy as np
IMAGE_HEIGHT = 384
IMAGE_WIDTH = 384
IMAGE_CHANNELS = 3

def preprocessor(image):
    image = tf.reshape(image, (IMAGE_HEIGHT, IMAGE_WIDTH, IMAGE_CHANNELS))
    image = tf.image.central_crop(image,0.8)
    shape = tf.shape(image)
    return image,shape

image = tf.random_normal([IMAGE_HEIGHT,IMAGE_WIDTH,IMAGE_CHANNELS])
image_cropped,shape = preprocessor(image)

sess = tf.Session()
im_v,im_crop_v,shape_v = sess.run([image,image_cropped,shape])
print(im_v.shape)
print(im_crop_v.shape)
print(shape_v)

Output:

(384, 384, 3)
(308, 308, 3)
[308 308   3]
Harsha Pokkalla
  • 1,792
  • 1
  • 12
  • 17
  • Thanks for the answer. I pass several images to the preprocessor and later want to stack them to one tensor along the image channels. for this I need to reshape the image from for example **(2,100,100,3)** to **(100,100,6)** for two images. For this i need the height and width **(100,100)** how can I get them with `tf.shape`? I tried `shape=tf.shape(..)` and `shape[1]`, `shape[2]`. – user3142067 May 23 '17 at 09:17
  • You can follow building Queues - preprocess images (data augmentation) and send them to model : follow this framework https://github.com/tensorflow/models/blob/master/inception/inception/image_processing.py – Harsha Pokkalla May 23 '17 at 14:41