tfrecord數據集讀取問題,tf.image.decode_image解碼前後出現數值不一樣

問題描述:
自己製作的圖像分割label.png,二進制編碼打開png圖像源文件後,標籤全部變爲0
原因:
製作標籤時,注意圖像的存儲模式,是RGB還是灰度模式(L)

from PIL import Image
import tensorflow as tf
import numpy as np
#img_path='F:\\VOC2012\\SegmentationClassAug\\2007_000032.png'
img_path='00.png'

#原label.png
img=Image.open(img_path)
img_array=np.asarray(img)
print('1')
print(np.sum(np.int32(img_array==1)))

#二進制打開png圖片,再解碼
with tf.gfile.GFile(img_path, 'rb') as fid:
  encoded_jpg0 = fid.read()
with tf.Session() as s:
  label0 = tf.image.decode_image(encoded_jpg0,1)
  #label0=tf.decode_raw(encoded_jpg0,out_type=tf.uint8)
  print('2')
  print(np.sum(np.int32(s.run(label0)==1)))

#原label.png
img=Image.open(img_path).convert('L')
img.save('01.png')

img_path1='01.png'
#二進制打開png圖片,再解碼
with tf.gfile.GFile(img_path1, 'rb') as fid:
  encoded_jpg0 = fid.read()
with tf.Session() as s:
  label0 = tf.image.decode_image(encoded_jpg0,1)
  print('3')
  print(np.sum(np.int32(s.run(label0)==1)))
1
866
2
0
3
866
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章