readers.py 文件源码

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

项目:tutorial_mnist 作者: machine-learning-challenge 项目源码 文件源码
def prepare_serialized_examples(self, serialized_examples):
    feature_map = {
        'image_raw': tf.FixedLenFeature([784], tf.int64),
        'label': tf.FixedLenFeature([], tf.int64),
    }
    features = tf.parse_example(serialized_examples, features=feature_map)

    images = tf.cast(features["image_raw"], tf.float32) * (1. / 255)
    labels = tf.cast(features['label'], tf.int32)

    def dense_to_one_hot(label_batch, num_classes):
      one_hot = tf.map_fn(lambda x : tf.cast(slim.one_hot_encoding(x, num_classes), tf.int32), label_batch)
      one_hot = tf.reshape(one_hot, [-1, num_classes])
      return one_hot

    labels = dense_to_one_hot(labels, 10)
    return images, labels
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号