作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用此序列从磁盘读取图像文件并将其输入到 TF Keras 模型中。
#Make dataset for training
dataset_train = tf.data.Dataset.from_tensor_slices((file_ids_training,file_names_training))
dataset_train = dataset_train.flat_map(lambda file_id,file_name: tf.data.Dataset.from_tensor_slices(
tuple (tf.py_func(_get_data_for_dataset, [file_id,file_name], [tf.float32,tf.float32]))))
dataset_train = dataset_train.cache()
dataset_train= dataset_train.shuffle(buffer_size=train_buffer_size)
dataset_train= dataset_train.batch(train_batch_size) #Make dataset, shuffle, and create batches
dataset_train= dataset_train.repeat()
dataset_train = dataset_train.prefetch(1)
dataset_train_iterator = dataset_train.make_one_shot_iterator()
get_train_batch = dataset_train_iterator.get_next()
我对这是否是最佳序列有疑问。例如repeat 应该在 shuffle() 之后和 batch() 之前吗?cache() 应该在 batch 之后吗?
最佳答案
答案在这里Output differences when changing order of batch(), shuffle() and repeat()建议在批处理之前重复或随机播放。我经常使用的顺序是 (1) shuffle,(2) repeat,(3) map,(4) batch 但它可以根据您的喜好而有所不同。我在 repeat 之前使用 shuffle 以避免模糊 epoch 边界。我在批处理之前使用 map,因为我的映射函数适用于单个示例(而不是一批示例),但您当然可以编写一个矢量化的 map 函数,并期望将批处理视为输入。
关于tensorflow - TF 数据集 API : Is the following sequence correct? 映射、缓存、随机播放、批量、重复、预取,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51485781/
我是一名优秀的程序员,十分优秀!