【发布时间】:2020-12-17 21:57:34
【问题描述】:
我有一个被映射到生成器的增强函数;但是,由于某种原因,tfa.image.rotate 函数导致了错误。
def customGenerator(input_file_paths, dims, data_type):
for i, file_path in enumerate(input_file_paths):
if data_type.decode("utf-8") in ["png" or "tif"]:
img = plt.imread((file_path.decode("utf-8")))
elif data_type.decode("utf-8") == "npy":
img = np.load(file_path.decode("utf-8"))
x = resize(img[:,:,:3], dims)
yield x, x
def augment(image,label) :
print('image', image)
print('shape', image.shape)
print('type', type(image))
#angle = random.uniform(0, tf.constant(np.pi))
image = tfa.image.rotate(image, tf.constant(np.pi)
train_dataset = tf.data.Dataset.from_generator(generator=customGenerator,
output_types=(np.float32, np.float32),
output_shapes=(dims, dims),
args=[X_train_paths, dims, "png"])
train_dataset = train_dataset.map(augment, num_parallel_calls=AUTOTUNE)
我查看了其他人使用的tfa.image.rotate 的实现,他们的工作正常。我尝试在增强函数中打印image 变量。结果是:
print('image', image) # these lines is in the augment function, result below
print('type', type(image))
image Tensor("args_0:0", shape=(256, 256, 3), dtype=float32)
type <class 'tensorflow.python.framework.ops.Tensor'>
相比之下,当我去其他用户的实现并打印他们的图像时,它没有映射到数据集中。他们的print(image) 和print(type(image)) 打印出来:
image tf.Tensor(
[[[1. 1. 1.]
[1. 1. 1.]
[1. 1. 1.]
...
[1. 1. 1.]
[1. 1. 1.]
[1. 1. 1.]]
...
[[1. 1. 1.]
[1. 1. 1.]
[1. 1. 1.]
...
[1. 1. 1.]
[1. 1. 1.]
[1. 1. 1.]]], shape=(256, 256, 3), dtype=float32)
type <class 'tensorflow.python.framework.ops.EagerTensor'>
当我在 augment 函数中打印 image 时,我希望这会被打印出来。所以我不确定发生了什么。所以有几个问题。
此外,tf.executing_eagerly() 的结果为 True
"args_0:0" 到底是什么意思?
augment 函数中的图像应该是<class 'tensorflow.python.framework.ops.EagerTensor'> 类型而不是普通张量吗?
有没有什么方法可以让"args_0:0" 变成我希望打印数字数组的格式?因为我相信这会修复旋转功能
最后,如果没有,是否有更好的方法通过随机旋转来增强图像?
感谢您的时间和帮助。
【问题讨论】:
-
可以分享
tf.executing_eagerly()的结果吗? -
tf.executing_eagerly() 的结果为真
-
什么是 dims 参数和使用的 resize 函数?
标签: python tensorflow tensorflow-datasets image-rotation data-augmentation