Sac*_*rma 1 generator deep-learning tensorflow2.0
Below generator function is too slow. Is there a way by which we can optimise this code ?. train_dataset_c1 is train dataset for Class 1 of the form image,1 train_dataset_c0 is train dataset for Class 0 of the form image,0
def generator(positive_dataset, negative_dataset):
while True:
for pos_rec, neg_rec in zip(positive_dataset, negative_dataset):
pos_x, pos_y = pos_rec
neg_x, neg_y = neg_rec
x = tf.concat([pos_x, neg_x], axis=0)
y = tf.concat([pos_y, neg_y], axis=0)
yield x, y
train_generator = generator(train_dataset_c1, train_dataset_c0)
test_generator = generator(test_dataset_c1, test_dataset_c0)
Run Code Online (Sandbox Code Playgroud)
小智 5
如果您使用 tensorflow 2.0,我建议您使用 tf.data API 来加速您的管道。
实际上有一个from_generator函数,您可以将其应用于生成器以加快速度
使用此函数将其转换为 tf.data.Dataset 对象后,您可以使用本教程中的任何策略进一步优化它
| 归档时间: |
|
| 查看次数: |
410 次 |
| 最近记录: |