我需要将图像调整到一定大小并将其保存到文件中,所以我选择了tf.image.resize_image_with_crop_or_pad函数:
import tensorflow as tf
image_decoded = tf.image.decode_jpeg(tf.read_file('1.jpg'), channels=3)
cropped = tf.image.resize_image_with_crop_or_pad(image_decoded, 200, 200)
tf.write_file('2.jpg', cropped)
Run Code Online (Sandbox Code Playgroud)
错误失败:
Traceback (most recent call last):
File "/home/test/anaconda3/lib/python3.5/site-packages/tensorflow/python/framework/op_def_library.py", line 490, in apply_op
preferred_dtype=default_dtype)
File "/home/test/anaconda3/lib/python3.5/site-packages/tensorflow/python/framework/ops.py", line 669, in convert_to_tensor
ret = conversion_func(value, dtype=dtype, name=name, as_ref=as_ref)
File "/home/test/anaconda3/lib/python3.5/site-packages/tensorflow/python/framework/ops.py", line 583, in _TensorTensorConversionFunction
% (dtype.name, t.dtype.name, str(t)))
ValueError: Tensor conversion requested dtype string for Tensor with dtype uint8: 'Tensor("control_dependency_3:0", shape=(200, 200, 3), dtype=uint8)'
During handling of the above exception, another exception occurred:
Traceback (most recent call …Run Code Online (Sandbox Code Playgroud)