tf使用GPU训练与推理记录

本文介绍了如何利用CUDA环境选择GPU设备进行预测,并探讨了在TensorFlow中设置GPU内存增长,实现分布式训练的流程。通过MirroredStrategy进行模型并行训练,提升了模型的训练效率,最后完成模型的保存和资源清理。
摘要由CSDN通过智能技术生成

推理

import os
os.environ['CUDA_VISIBLE_DEVICES'] = '0, 1' # 选择GPU设备
predict = model.predict(SignalSeq_16[:10])

训练

os.environ['CUDA_VISIBLE_DEVICES'] = '0'
gpus = tf.config.experimental.list_physical_devices(device_type='GPU')
for gpu in gpus:
    tf.config.experimental.set_memory_growth(gpu, True)
mirrored_strategy = tf.distribute.MirroredStrategy()
with mirrored_strategy.scope():
    ...
    model = 
    model.compile()
    model.fit()
    model.save()
    del model
    gc.collect()
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值