[{"createTime":1735734952000,"id":1,"img":"hwy_ms_500_252.jpeg","link":"https://activity.huaweicloud.com/cps.html?fromacct=261f35b6-af54-4511-a2ca-910fa15905d1&utm_source=V1g3MDY4NTY=&utm_medium=cps&utm_campaign=201905","name":"华为云秒杀","status":9,"txt":"华为云38元秒杀","type":1,"updateTime":1735747411000,"userId":3},{"createTime":1736173885000,"id":2,"img":"txy_480_300.png","link":"https://cloud.tencent.com/act/cps/redirect?redirect=1077&cps_key=edb15096bfff75effaaa8c8bb66138bd&from=console","name":"腾讯云秒杀","status":9,"txt":"腾讯云限量秒杀","type":1,"updateTime":1736173885000,"userId":3},{"createTime":1736177492000,"id":3,"img":"aly_251_140.png","link":"https://www.aliyun.com/minisite/goods?userCode=pwp8kmv3","memo":"","name":"阿里云","status":9,"txt":"阿里云2折起","type":1,"updateTime":1736177492000,"userId":3},{"createTime":1735660800000,"id":4,"img":"vultr_560_300.png","link":"https://www.vultr.com/?ref=9603742-8H","name":"Vultr","status":9,"txt":"Vultr送$100","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":5,"img":"jdy_663_320.jpg","link":"https://3.cn/2ay1-e5t","name":"京东云","status":9,"txt":"京东云特惠专区","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":6,"img":"new_ads.png","link":"https://www.iodraw.com/ads","name":"发布广告","status":9,"txt":"发布广告","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":7,"img":"yun_910_50.png","link":"https://activity.huaweicloud.com/discount_area_v5/index.html?fromacct=261f35b6-af54-4511-a2ca-910fa15905d1&utm_source=aXhpYW95YW5nOA===&utm_medium=cps&utm_campaign=201905","name":"底部","status":9,"txt":"高性能云服务器2折起","type":2,"updateTime":1735660800000,"userId":3}]
方法1:window10的任务管理器显示的gpu利用率数据有可能是错的,存在bug,
博主就被这个数据误导了。所以,首先从nvidia-smi或其他软件(如,Gpu-Z等)看gpu真实的利用率。
方法2、第一种情况排除后,就要考虑模型太小,batch-size太小。将改变模型结构,或将batch-size调大。
方法3
、如果第二种情况的gpu利用率还是很低,而cpu利用率很高,那瓶颈应该是数据加载的问题,gpu处理太快,cpu经常处于传输数据的过程。所以,启动多线程加载数据,num_worker可以设置2,4,
8, 16,如果你的内存空间够大,那就再设置pin_memory=True。这会让数据锁页,不允许将数据放到虚拟内存中,省掉了一点数据传输时间。
torch.utils.data.DataLoader(image_datasets[x], batch_size=batch_size,
shuffle=True, num_workers=4, pin_memory=True)
方法4、如果设置num_workers不为0后出现boken pipe问题, 就将主程序包含进下面的代码
if __name__ == '__main__':
例如下面的示例:
如果还不行,就设置num_workers=0
方法5、如果是固体硬盘,数据加载的速度很快,num_workers设为0,1, 2,
4就好,不要太大。自己可以尝试看那个比较快。设置太大,cpu对各个子线程的数据合并所花时间太多,会导致数据加载速度不升反降。
方法6、如果还是有问题,尝试重启电脑看看能否解决问题。