运行代码和参考步骤
具体步骤参考 从零开始行人重识别
下载Market-1501数据集和源代码
试运行-第一部分
prepare.py
输入指令
python3 prepare.py
运行顺利
model.py
train.py
输入指令
python train.py --gpu_ids 0 --name ft_ResNet50 --train_all --batchsize 32 --data_dir your_data_path
记得修改your_data_path
出现了以下报错
RuntimeError: CUDA out of memory. Tried to allocate 20.00 MiB (GPU 0; 1.31 GiB total capacity; 1.04 GiB already allocated; 4.39 MiB free)
(这里的具体数据编了一下,大概是这样,因为之前没存)
解决办法
将batch_size
改小,我改成2
以后就可以跑了,但是跑了15个小时才跑完。(又忘记截图了)
输入指令
python train.py --gpu_ids 0 --name ft_ResNet50 --train_all --batchsize 2 --data_dir your_data_path
试运行-第二部分
test.py
报错如下
File “/home/wuboqun/Downloads/Person_reID_baseline_pytorch/evaluate_gpu.py”, line 79, in (module)
query_feature = query_feature.cuda()RuntimeError: CUDA error: device-side assert triggered CUDA kernel errors might be asynchronously reported at some other API call,so the stacktrace below might be incorrect. For debugging consider passing CUDA_LAUNCH_BLOCKING=1
解决方法
在运行指令前加上 (我觉得可能不对,因为出现了下面新的报错)
CUDA_LAUNCH_BLOCKING=1
之后报错如下
File “/home/wuboqun/Downloads/Person_reID_baseline_pytorch/evaluate_gpu.py”, line 79, in (module)
query_feature = query_feature.cuda()
RuntimeError: CUDA error: out of memory
之后在网上查找了关于CUDA error: out of memory
所有方法都没有用,一直报这个错,我一直在用nvidia-smi
这个指令查看gpu的占用情况,每次运行占用量都在1500MiB
左右,之后又单独运行了test.py
里的这一句
os.system('python evaluate_gpu.py | tee -a %s'%result)
因为这句运行了evaluate_gpu.py
,而出错的语句就是这个里面的这句
query_feature = query_feature.cuda()
这个时候查看gpu的 占用量,大概是800MiB
左右。
因为我的gpu内存容量是2048MiB,所以才一直有CUDA error: out of memory
的报错
所以我把这两句
query_feature = query_feature.cuda()
gallery_feature = gallery_feature.cuda()
改成了
device = torch.device("cpu")
query_feature = query_feature.to(device)
gallery_feature = gallery_feature.to(device)
就是不在gpu跑而是在cpu上
是跑出来了,但是我不确定对不对。之后要仔细读一下代码。
更新:应该是不对的,不知道是我在自己电脑上跑batchsize太小了还是我改了这里,跑出来rank-1
等数据都是0.00059
这种,显然是不对的。所以我在网上找了租显卡的,然后好快,20分钟就训练完了,我自己电脑跑了15个小时…结果还不对
在租的上面跑了以后结果是对的。
batchsize = 64
在train的时候加上--cosface
后得到的(batchsize = 128)
在train的时候加上--triplet
后得到的(batchsize = 64)
在train的时候加上--cosface
后得到的(batchsize = 64)
所以之后就是读一下代码