torch.cuda.is_available() is False解决
RuntimeError: Attempting to deserialize object on a CUDA device but torch.cuda.is_available() is False. If you are running on a CPU-only machine, please use torch.load with map_location=torch.device(‘
·
RuntimeError: Attempting to deserialize object on a CUDA device but torch.cuda.is_available() is False. If you are running on a CPU-only machine, please use torch.load with map_location=torch.device(‘cpu’) to map your storages to the CPU.
if __name__ == '__main__':
args = parse_args()
print("torch-version:", torch.__version__)
print('gpu0:', torch.cuda.is_available()) #在入口__main__加上这个 is_available()就变成true了
os.environ["CUDA_VISIBLE_DEVICES"]=args.gpu
update_config(args.config_file)
img_dir = args.data_dir
query = ['1.jpg']
gallery = ['2.jpg',
'3.jpg',
'4.jpg',
'5.jpg',
'7.jpg']
img_list = query + gallery
resize_wh = opt.aug.resize_size #[128,256]
imgs = [io.imread(os.path.join(img_dir, imgname)) for imgname in img_list]
imgs = np.asarray([im_preprocess(cv2.resize(p, (resize_wh[1], resize_wh[0]))) for p in imgs], dtype=np.float32)
reid_model = load_reid_model(args.model_path)
print('[INFO] Load model path: {}'.format(args.model_path))
with torch.no_grad():
im_var = Variable(torch.from_numpy(imgs))
im_var = im_var.cuda()
feats = F.normalize(reid_model(im_var)).cpu()
q_feats = feats[:len(query)]
g_feats = feats[len(query):]
distmat = cdist(q_feats, g_feats)
print('[INFO] Query-gallery distance:')
for i,q in enumerate(query):
for j,g in enumerate(gallery):
print(' {} - {} distance: {:.2f}'.format(q,g,distmat[i][j]))
for i in range(len(query)):
g_idx = np.where(distmat[i]==np.min(distmat[i]))[0][0]
print('[INFO] Gallery image {} is the same id as query image {}\n'.format(gallery[g_idx], query[i]))
(exxx_tf) [exxx@cccfpga pt_personreid-res50_market1501_256_128_5.4G_1.3]$ sh run_demo.sh
torch-version: 1.8.1
gpu0: True
torch-version: 1.8.1
gpu: True
[INFO] Load model path: /home/exxx/keras/reid/pt_personreid-res50_market1501_256_128_5.4G_1.3/float//personreid_resnet50.pth
[INFO] Query-gallery distance:
1.jpg - 2.jpg distance: 1.27
1.jpg - 3.jpg distance: 1.28
1.jpg - 4.jpg distance: 0.99
1.jpg - 5.jpg distance: 1.34
1.jpg - 7.jpg distance: 1.23
[INFO] Gallery image 4.jpg is the same id as query image 1.jpg
欢迎来到FlagOS开发社区,这里是一个汇聚了AI开发者、数据科学家、机器学习爱好者以及业界专家的活力平台。我们致力于成为业内领先的Triton技术交流与应用分享的殿堂,为推动人工智能技术的普及与深化应用贡献力量。
更多推荐
所有评论(0)