【发布时间】:2020-12-25 07:06:09
【问题描述】:
首先:我是新手,请原谅我的无知。
我尝试从TFRecord-File 加载图像,并且可以使用plt.show() 显示它们,但是当我尝试使用plt.imsave() 保存图像时出现错误。
这是我尝试做的:
import tensorflow as tf
import matplotlib.pyplot as plt
reader = tf.data.TFRecordDataset(input_file)
for raw_record in reader.take(1):
example = tf.train.Example()
example.ParseFromString(raw_record.numpy())
raw_record = example.features.feature['image/encoded']
img = example.features.feature["image/encoded"].bytes_list.value[0]
decoded = tf.io.decode_jpeg(img)
plt.figure(figsize = (20,3))
plt.imshow(decoded)
plt.show()
plt.imsave(output_file, decoded)
错误如下:
Traceback (most recent call last):
File "/home/freddy/PycharmProjects/ocr/visualize_fsns.py", line 30, in <module>
plt.imsave(flags.output_file, decoded)
File "/home/freddy/.local/lib/python3.8/site-packages/matplotlib/pyplot.py", line 2235, in imsave
return matplotlib.image.imsave(fname, arr, **kwargs)
File "/home/freddy/.local/lib/python3.8/site-packages/matplotlib/image.py", line 1567, in imsave
rgba = sm.to_rgba(arr, bytes=True)
File "/home/freddy/.local/lib/python3.8/site-packages/matplotlib/cm.py", line 305, in to_rgba
xx = np.empty(shape=(m, n, 4), dtype=x.dtype)
TypeError: data type not understood
你能帮我解开这个谜吗?
【问题讨论】:
-
你可以试试
xx = np.empty((m, n, 4))
标签: python matplotlib image-processing save typeerror