caicloud / tensorflow-tutorial

Example TensorFlow codes and Caicloud TensorFlow as a Service dev environment.
2.93k stars 2.08k forks source link

书本代码问题 #9

Closed sunjieee closed 7 years ago

sunjieee commented 7 years ago

首先感谢作者,通过阅读这本书收获很大,学到很多。 我在运行书本中的代码中遇到如下问题: 书本P195,第7.3.4输入数据处理框架(这里github库相应章节中代码和书中不同) features = tf.parse_single_example( serializerd_example, features={ 'image': tf.FixedLenFeature([], tf.string), 'label': tf.FixedLenFeature([], tf.int64), 'height': tf.FixedLenFeature([], tf.int64), 'width': tf.FixedLenFeature([], tf.int64), 'channels': tf.FixedLenFeature([], tf.int64) })

image, label = features['image'], features['label'] height, width = features['height'], features['width'] channels = features['channels'] decoded_image = tf.decode_raw(image, tf.uint8) decoded_image.set_shape([height, width, channels]) (1)

这里(1)处的height, width, channels是从TFRecords文件中读取的,是Tensor, 代码运行时出现以下错误: TypeError: int() argument must be a string or a number, not 'Tensor'

即使我把height,width,channels直接替换为数字, decoded_image.set_shape([224, 224, 3]) 也会报错 ValueError: Shapes (?,) and (224, 224, 3) are not compatible

最后通过尝试以下方式是可行的,但还是要通过tf.reshape来恢复图片shape decoded_image.set_shape([224 224 3])

所以我想问

  1. decoded_image.set_shape函数该如何用, 是否直接用tf.reshape来设定图片的shape更好?
  2. height,width,channels等从TFRecords文件读取的信息都是Tensor,在运行Session前不能得到它们的值,所以是否可以这样理解,在TFRecords文件保存这些信息是没有用的,因为还是必须人为设定这些信息,才能通过reshape恢复图片shape?
perhapszzy commented 7 years ago

对于问题1,我觉得直接用reshape是完全没问题的。 对于问题2, 可以参考Google提供的inception是如何从TFRecords里面读取数值的:https://github.com/tensorflow/models/blob/master/inception/inception/image_processing.py#L394

Stubborn142857 commented 5 years ago

您好,我在学习本书的时候也遇到这样的问题,原链接已经打不开了,请明示,谢谢

bmwn0-0 commented 5 years ago

你在说什么?

发送自 Windows 10 版邮件https://go.microsoft.com/fwlink/?LinkId=550986应用


发件人: zhanglong notifications@github.com 发送时间: Wednesday, April 3, 2019 1:51:40 PM 收件人: caicloud/tensorflow-tutorial 抄送: Subscribed 主题: Re: [caicloud/tensorflow-tutorial] 书本代码问题 (#9)

您好,我在学习本书的时候也遇到这样的问题,原链接已经打不开了,请明示,谢谢

― You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHubhttps://github.com/caicloud/tensorflow-tutorial/issues/9#issuecomment-479349690, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AhUPMwlWj9_v0wmyWQptHikmEUBvpS4Sks5vdEFsgaJpZM4MplfQ.