在进行一些更改后,我成功地将图像保存到本地驱动器。尽管如此,警告信息仍然会出现(我认为这是我的设置的问题)。请在下面找到解决方案。
import tensorflow as tf
filepath = "<Some filepath>"
filename = "<Some image filename>"
tensors = []
# decode image to RGB format
image_decoded = tf.image.decode_jpeg(tf.read_file(filepath + filename), channels=3)
# crop a random patch from the image of size 512*512
random_patch = tf.random_crop(image_decoded, [512,512,3])
# append the tensor to the list of rest of the tensors
tensors.append(random_patch)
# encode the random patch into JPEG format and then write the file to the local drive
enc = tf.image.encode_jpeg(random_patch)
# write the new cropped file at the directory random_patches created
image = filepath + "random_patches/" + filename
cropped_file = tf.constant(image)
fwrite = tf.write_file(cropped_file, enc)
sess = tf.Session()
result = sess.run(fwrite)