nengdong96 / CSDN

9 stars 0 forks source link

How to fix AttributeError: 'tuple' object has no attribute 'detach'? #3

Open zh0415 opened 3 months ago

zh0415 commented 3 months ago

main.py:(The 3st Stage Training) if current_epoch + 1 >= 1 and (current_epoch + 1) % config.eval_epoch == 0: cmc, mAP, mINP = test(model, loaders, config)

test.py: def test(base, loader, config): base.set_eval() print('Extracting Query Feature...') ptr = 0 query_feat = np.zeros((loader.n_query, 3072))
with torch.no_grad(): for batch_idx, (input, label) in enumerate(loader.query_loader): batch_num = input.size(0) input = Variable(input.cuda()) # [128, 3, 288, 144] feat = base.model(x2=input)

f.shape for f in feat: [128, 2048, 18, 9], [163, 128, 1024], [128, 395], [128, 395]

        query_feat[ptr:ptr + batch_num, :] = feat.detach().cpu().numpy()
        ptr = ptr + batch_num

Start the 3st Stage Training Extracting Text Features Text Features Extracted, Start Training Time: 2024-08-14 10:20:17; Epoch: 0; LR, 2.9999999999999997e-06; pid_loss: 5.962477; pid_loss_proj: 5.958371; triplet_loss: 3.3407512; triplet_loss_proj: 0.6742919; rgb_i2t_pid_loss: 6.019183; ir_i2t_pid_loss: 6.0137625;
Extracting Query Feature... Traceback (most recent call last): File "/data3/code/CSDN-main/main.py", line 251, in main(config) File "/data3/code/CSDN-main/main.py", line 182, in main cmc, mAP, mINP = test(model, loaders, config) File "/data3/code/CSDN-main/core/test.py", line 20, in test query_feat[ptr:ptr + batch_num, :] = feat.detach().cpu().numpy() AttributeError: 'tuple' object has no attribute 'detach'

ytzxc commented 1 month ago

me too, Have you solve this problem?