【发布时间】:2019-10-26 16:04:38
【问题描述】:
我尝试设置一个图像管道,为用于裁剪图像的 Tensorflow 构建图像数据集。 我遵循了tutorial,但我想将文件裁剪为正方形,并且在不保留纵横比的情况下不调整大小。 我不知道如何获得它们的尺寸。
#
from __future__ import absolute_import, division, print_function, unicode_literals
import tensorflow as tf
#
import glob
AUTOTUNE = tf.data.experimental.AUTOTUNE
IMAGE_SIZE = 192
def preprocess_image(path):
img_raw = tf.io.read_file(path)
img_tensor = tf.image.decode_jpeg(img_raw, channels=3)
print("img_tensor")
print(img_tensor)
height = img_tensor.shape[0]
print("height")
print(height)
return img_tensor
files_path = glob.glob('./images/*.jpeg')
image_count = len(files_path)
path_ds = tf.data.Dataset.from_tensor_slices(files_path)
path_ds.map(preprocess_image, num_parallel_calls=AUTOTUNE)
tf.image.decode_jpeg 返回的张量形状为:
Tensor("DecodeJpeg:0", shape=(None, None, 3), dtype=uint8)
如何获取 jpg 图像的大小?
当我以这种方式访问它时,它可以工作:
#
from __future__ import absolute_import, division, print_function, unicode_literals
import tensorflow as tf
#
image = tf.io.read_file('./images/4c34476047bcbbfd10b1fd3342605659.jpeg/')
image = tf.image.decode_jpeg(image, channels=3)
print("image.shape")
print(image.shape)
打印出来:
image.shape
(700, 498, 3)
【问题讨论】:
-
它仍然显示 (None,None,3) 你有什么想法吗/?
标签: python tensorflow