【发布时间】:2020-07-14 02:21:13
【问题描述】:
我正在尝试将图像信息映射到由图像和标签字典组成的数据集。
parse_function() 应该只从 2 个文件名路径和标签列表中解码。
def parse_function(filename, label):
image_string = tf.io.read_file(filename)
image_decoded = tf.image.decode_jpeg(image_string)
image_resized = tf.image.resize(image_decoded, [4, 4])
return image_resized, label
def dataset_maker(list_sample_paths, list_labels):
filenames = tf.constant(list_sample_paths)
labels = tf.constant(list_labels)
dataset = tf.data.Dataset.from_tensor_slices({"image": filenames, "label": labels})
dataset = dataset.map(parse_function)
training_dataset = dataset_maker(list_training_sample_paths, list_training_sample_labels)
但我收到此错误消息
TypeError: tf__parse_function() missing 1 required positional argument: 'label'
在这种情况下我需要使用字典理解吗? 非常感谢解决此问题的任何帮助。 谢谢!
在 Srihari Humbarwadi 回复后添加此信息以使用元组解决它: 我想要一个字典结构,因为我用 Mnist 给我的模型下雨了。
一个随机的 Mnist 示例具有以下结构:
{'image': <tf.Tensor: id=140275, shape=(28, 28, 1), dtype=uint8, numpy=array([[[ 0],[ 0],[ 0]],dtype=uint8)>, 'label': <tf.Tensor: id=140276, shape=(), dtype=int64, numpy=6>}
【问题讨论】:
标签: python tensorflow dictionary mapping dictionary-comprehension