1

我面临以下问题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

哪个输出

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

central_crop()函数似乎丢失了有关图像张量的高度宽度的信息。为什么会这样?

Tensorflow version:  tensorflow 1.0.0, tensorflow-gpu 1.0.1
4

1 回答 1

1

你是对的。除非对其进行评估,否则无法检索张量的形状。如果您想将它用于下一个操作,您可以使用“tf.shape(image)”。

TF 裁剪了图像,但无法获得其形状。如果您只想检查它是否正在执行,请按照以下步骤操作(运行会话):

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)

输出:

(384, 384, 3)
(308, 308, 3)
[308 308   3]
于 2017-05-19T15:55:13.283 回答