tf.clip_by_value 数据增强报错,无法继续
来源:5-2 Cifar10数据读取与数据增强

Jackeroo
2019-09-09
数据增强这步,就出错了:
distorted_image = tf.random_crop(img_batch, [batch_size, 28, 28, 3])
distorted_image = tf.image.random_contrast(distorted_image, lower=0.5, upper=1.5)
distorted_image = tf.image.random_hue(distorted_image, max_delta=0.2)
distorted_image = tf.image.random_saturation(distorted_image, lower=0.5, upper=1.5)
img_batch = tf.clip_by_value(distorted_image, 0, 255)
错误信息如下:
File “/Volumes/Data@SSD/code/python/tf-py3/read_cifar10.py”, line 34, in get_enhanced_img_batch
img_batch = tf.clip_by_value(distorted_image, 0, 255)
File “/Users/jackeroo/.pyenv/versions/tf-py3/lib/python3.7/site-packages/tensorflow/python/util/dispatch.py”, line 180, in wrapper
return target(*args, **kwargs)
File “/Users/jackeroo/.pyenv/versions/tf-py3/lib/python3.7/site-packages/tensorflow/python/ops/clip_ops.py”, line 72, in clip_by_value
t_min = math_ops.minimum(values, clip_value_max)
File “/Users/jackeroo/.pyenv/versions/tf-py3/lib/python3.7/site-packages/tensorflow/python/ops/gen_math_ops.py”, line 6345, in minimum
"Minimum", x=x, y=y, name=name)
File “/Users/jackeroo/.pyenv/versions/tf-py3/lib/python3.7/site-packages/tensorflow/python/framework/op_def_library.py”, line 626, in _apply_op_helper
param_name=input_name)
File “/Users/jackeroo/.pyenv/versions/tf-py3/lib/python3.7/site-packages/tensorflow/python/framework/op_def_library.py”, line 60, in _SatisfiesTypeConstraint
", ".join(dtypes.as_dtype(x).name for x in allowed_list)))
TypeError: Value passed to parameter ‘x’ has DataType uint8 not in list of allowed values: bfloat16, float16, float32, float64, int32, int64
1回答
-
会写代码的好厨师
2019-09-09
Value passed to parameter ‘x’ has DataType uint8
将img_batch使用tf.cast类型转换为float32 再看一下是否可以.
012019-09-09
相似问题