我不确定我的答案是否正确(#note 是我的答案)
def process_image(data):
r""" [0,255] -> [-1, 1]"""
这是否意味着标准化图像数据?但我还没有看到这种语法
img = data['image']
分类
lab = data['label']
img = (tf.cast(img, tf.float32) / 255.0 - 0.5) * 2.0
图像-> float32 格式(0,255)-> 归一化为 (-1,1) 返回 img, lab
def create_image_dataset(ds, batch_size=256, training=None):
if training:
ds = ds.shuffle(1000)
我知道这意味着随机洗牌数据集,但 1000 是什么意思?
ds = ds.batch(batch_size).map(process_image).prefetch(
tf.data.experimental.AUTOTUNE)
关于部分预取,是不是意味着程序可以自动选择最优的并行线程数?</p>
return ds
train = create_image_dataset(mnist['train'], batch_size=256, training=True)
image_shape = tf.data.experimental.get_structure(train)[0].shape[1:]
print("Image shape:", image_shape)
get_structure 是什么意思?和reshape func一样吗?
非常感谢