我设法使用以下代码显示图像:
import os
import tensorflow as tf
from tensorflow.python.framework import ops
from tensorflow.python.framework import dtypes
import numpy as np
import glob
import fnmatch
import matplotlib.pyplot as plt
from PIL import Image
def test1(path):
filename_queue = tf.train.string_input_producer(tf.train.match_filenames_once(path))
image_reader = tf.WholeFileReader()
label, image_file = image_reader.read(filename_queue)
image = tf.image.decode_jpeg(image_file,3)
print(image)
with tf.Session() as sess:
tf.global_variables_initializer().run()
coord = tf.train.Coordinator()
threads = tf.train.start_queue_runners(coord=coord)
for i in range(1):
img = image.eval()
Image.fromarray(np.asarray(img)).show()
coord.request_stop()
coord.join(threads)
sess.close()
if __name__== "__main__":
test1("./data/test1/1099.jpg")
然而,当我使用以下代码调整图像大小时:
import os
import tensorflow as tf
from tensorflow.python.framework import ops
from tensorflow.python.framework import dtypes
import numpy as np
import glob
import fnmatch
import matplotlib.pyplot as plt
from PIL import Image
def test1(path):
filename_queue = tf.train.string_input_producer(tf.train.match_filenames_once(path))
image_reader = tf.WholeFileReader()
label, image_file = image_reader.read(filename_queue)
image = tf.image.decode_jpeg(image_file,3)
print(image)
image = tf.image.resize_images(image, [224 , 224])
print(image)
with tf.Session() as sess:
tf.global_variables_initializer().run()
coord = tf.train.Coordinator()
threads = tf.train.start_queue_runners(coord=coord)
for i in range(1):
img = image.eval()
Image.fromarray(np.asarray(img)).show()
coord.request_stop()
coord.join(threads)
sess.close()
if __name__== "__main__":
test1("./data/test1/1099.jpg")
它会显示以下错误消息:
引发TypeError(“无法处理此数据类型”) TypeError:无法处理此数据类型
由于
答案 0 :(得分:0)
管理以解决问题
import os
import tensorflow as tf
from tensorflow.python.framework import ops
from tensorflow.python.framework import dtypes
import numpy as np
import glob
import fnmatch
import matplotlib.pyplot as plt
from PIL import Image
def test1(path):
filename_queue = tf.train.string_input_producer(tf.train.match_filenames_once(path))
image_reader = tf.WholeFileReader()
label, image_file = image_reader.read(filename_queue)
image = tf.image.decode_jpeg(image_file,3)
print(image)
image = tf.image.resize_images(image, [224 , 224])
print(image)
with tf.Session() as sess:
tf.global_variables_initializer().run()
coord = tf.train.Coordinator()
threads = tf.train.start_queue_runners(coord=coord)
for i in range(1):
img = image.eval()
Image.fromarray(np.asarray(img.astype(np.uint8))).show()
coord.request_stop()
coord.join(threads)
sess.close()
if __name__== "__main__":
test1("./data/test1/1099.jpg")
感谢人们:)