demo.py 文件源码

python
阅读 36 收藏 0 点赞 0 评论 0

项目:apparent-age-gender-classification 作者: danielyou0230 项目源码 文件源码
def read_and_decode(filename, img_size=128, depth=1):
    if not filename.endswith('.tfrecords'):
        print "Invalid file \"{:s}\"".format(filename)
        return [], []
    else:
        data_queue = tf.train.string_input_producer([filename])

        reader = tf.TFRecordReader()
        _, serialized_example = reader.read(data_queue) 
        features = tf.parse_single_example(serialized_example,
                   features={
                             'label'   : tf.FixedLenFeature([], tf.int64),
                             'img_raw' : tf.FixedLenFeature([], tf.string),
                            })

        img = tf.decode_raw(features['img_raw'], tf.uint8)
        img = tf.reshape(img, [img_size, img_size, depth])
        # Normalize the image
        img = tf.cast(img, tf.float32) * (1. / 255) - 0.5
        label = tf.cast(features['label'], tf.int32)
        label_onehot = tf.stack(tf.one_hot(label, n_classes))
        return img, label_onehot
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号