UnboundLocalError: local variable 'x' referenced before assignment
airparkchen opened this issue · comments
Hi,I'm a student and very interested in your "3D Interacting Hand Pose Estimation by Hand De-occlusion and Removal" paper.
i'm getting error on running demo.py
(hdr_hope) C:\HDR>python demo/demo.py
load checkpoint from local path: ./demo_work_dirs/Interhand_seg/iter_237500.pth => loading checkpoint './demo_work_dirs/TDR_fintune/checkpoints\ckpt_iter_138000.pth.tar' => loading checkpoint './demo_work_dirs/All_train_SingleRightHand\checkpoints\ckpt_iter_261000.pth.tar' img.shape= torch.Size([1, 3, 256, 256]) Traceback (most recent call last): File "demo/demo.py", line 163, in <module> seg_result = inference_segmentor(seg_model, rgb.cuda()) File "C:\HDR\mmseg\apis\inference.py", line 168, in inference_segmentor seg_logits = model.encode_decode(img, None) File "C:\HDR\mmseg\models\segmentors\encoder_decoder.py", line 77, in encode_decode x = self.extract_feat(img) File "C:\HDR\mmseg\models\segmentors\encoder_decoder.py", line 73, in extract_feat return x UnboundLocalError: local variable 'x' referenced before assignment
i think maybe the problem is in "extract_feat" so i also post it on here
def extract_feat(self, img): """Extract features from images.""" # print(self.backbone(img)) # print(img) try: x = self.backbone(img) except : print("img.shape=", img.shape) if self.with_neck: x = self.neck(self.backbone(img))
Sorry for late response. The error seems to be caused by the version of mmsegmentation or invalid input data type or shape. Have you tried to reinstall mmsegmentation with recommended version and checked the input?
Thanks for your response!
I have tried reinstall and using the demo picture(Tzionas_dataset-02-1-rgb-100.png)
still get the same error.
btw
at first i'm using your "[environment.yml]" to create a anaconda envirnment
but i got an" ImportError: DLL load failed " error from "mmcv-full"
so i upgrade "mmcv-full" to 1.4.0
and check the torch cuda version is compare to mine .
are these might be a reason i got the "UnboundLocalError: " which i mention at the beginning?
@airparkchen hi, i get the same error and fix it. You can modify the code at class 'EfficientMultiheadAttention' from mit.py to "out = self.attn(query=x_q.permute(1,0,2), key=x_kv.permute(1,0,2), value=x_kv.permute(1,0,2), need_weights=False)[0].permute(1,0,2)". This error may a code bug or caused by the version of pytorch. You can obtain the correct input dimensions from torch.nn.MultiheadAttention.
@binghui-z Sorry for late response.
Error Fixed!!
Thank you so much!!
@airparkchen hi, i get the same error and fix it. You can modify the code at class 'EfficientMultiheadAttention' from mit.py to "out = self.attn(query=x_q.permute(1,0,2), key=x_kv.permute(1,0,2), value=x_kv.permute(1,0,2), need_weights=False)[0].permute(1,0,2)". This error may a code bug or caused by the version of pytorch. You can obtain the correct input dimensions from torch.nn.MultiheadAttention.
Thanks!