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
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值