Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UnboundLocalError: local variable 'x' referenced before assignment #8

Open
airparkchen opened this issue Jan 2, 2023 · 5 comments
Open

Comments

@airparkchen
Copy link

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))

@MengHao666
Copy link
Owner

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?

@airparkchen
Copy link
Author

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?

@binghui-z
Copy link

@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.

@airparkchen
Copy link
Author

@binghui-z Sorry for late response.
Error Fixed!!
Thank you so much!!

@wenkaiH
Copy link

wenkaiH commented May 31, 2023

@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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants