Elfenreigen / UniChest

https://tianjiedai.github.io/unichest/
MIT License
14 stars 1 forks source link

Test code - args.finetune error #5

Open njan-creative opened 2 weeks ago

njan-creative commented 2 weeks ago

The below error happens when trying to use the test code as suggested in code base.

File "/home/dell/UniChest/infer.py", line 282, in main
    test(model,image_encoder, text_encoder, tokenizer, test_dataloader,device,save_result_path,args,text_list,dist_csv_col)
  File "/home/dell/UniChest/engine/test.py", line 144, in test
    pred_class,_ = model(image_features,text_features,args)
  File "/home/dell/anaconda3/envs/mimicnle/lib/python3.9/site-packages/torch/nn/modules/module.py", line 1518, in _wrapped_call_impl
    return self._call_impl(*args, **kwargs)
  File "/home/dell/anaconda3/envs/mimicnle/lib/python3.9/site-packages/torch/nn/modules/module.py", line 1527, in _call_impl
    return forward_call(*args, **kwargs)
  File "/home/dell/UniChest/models/clip_tqn.py", line 323, in forward
    if args.finetune: 
AttributeError: 'Namespace' object has no attribute 'finetune'

If I set args.finetune to False, then

File "/home/dell/UniChest/models/clip_tqn.py", line 345, in forward
    out_bias = gate_weight[:,0].unsqueeze(1).unsqueeze(2) * out_1 + gate_weight[:,1].unsqueeze(1).unsqueeze(2) * out_2 + gate_weight[:,2].unsqueeze(1).unsqueeze(2) * out_3
UnboundLocalError: local variable 'out_1' referenced before assignment

If I set args.finetune to True, then


File "/home/dell/UniChest/infer.py", line 327, in <module>
    main(args, config)
  File "/home/dell/UniChest/infer.py", line 282, in main
    test(model,image_encoder, text_encoder, tokenizer, test_dataloader,device,save_result_path,args,text_list,dist_csv_col)
  File "/home/dell/UniChest/engine/test.py", line 161, in test
    AUROCs = compute_AUCs(array_gt, array_pred,n_class)
  File "/home/dell/UniChest/engine/test.py", line 48, in compute_AUCs
    AUROCs.append(roc_auc_score(gt_np[:, i], pred_np[:, i]))
  File "/home/dell/anaconda3/envs/mimicnle/lib/python3.9/site-packages/sklearn/utils/_param_validation.py", line 214, in wrapper
    return func(*args, **kwargs)
  File "/home/dell/anaconda3/envs/mimicnle/lib/python3.9/site-packages/sklearn/metrics/_ranking.py", line 627, in roc_auc_score
    return _average_binary_score(
  File "/home/dell/anaconda3/envs/mimicnle/lib/python3.9/site-packages/sklearn/metrics/_base.py", line 75, in _average_binary_score
    return binary_metric(y_true, y_score, sample_weight=sample_weight)
  File "/home/dell/anaconda3/envs/mimicnle/lib/python3.9/site-packages/sklearn/metrics/_ranking.py", line 382, in _binary_roc_auc_score
    raise ValueError(
ValueError: Only one class present in y_true. ROC AUC score is not defined in that case.
njan-creative commented 2 weeks ago

If I set args.finetune to True, then ValueError: Only one class present in y_true. ROC AUC score is not defined in that case.

There is no positive for 'Edema' in VinDr-CXR test set. How to handle this case.