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
readers.py 文件源码
python
阅读 29
收藏 0
点赞 0
评论 0
评论列表
文章目录