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

KeyError: 'test_mode' #249

Open
followingcode opened this issue Aug 27, 2024 · 3 comments
Open

KeyError: 'test_mode' #249

followingcode opened this issue Aug 27, 2024 · 3 comments

Comments

@followingcode
Copy link

followingcode commented Aug 27, 2024

Traceback (most recent call last):
File "demo/demo_skeleton.py", line 314, in
main()
File "demo/demo_skeleton.py", line 293, in main
results = inference_recognizer(model, fake_anno)
File "/root/pyskl/pyskl/apis/inference.py", line 163, in inference_recognizer
data = test_pipeline(data)
File "/root/pyskl/pyskl/datasets/pipelines/compose.py", line 41, in call
data = t(data)
File "/root/pyskl/pyskl/datasets/pipelines/multi_modality.py", line 65, in call
if results['test_mode']:
KeyError: 'test_mode'

@followingcode
Copy link
Author

The --config parameter in demo/demo_skeleton.py is default='configs/rgbpose_conv3d/rgbpose_conv3d.py', and the --checkpoint parameter is default='https://download.openmmlab.com/mmaction/pyskl/ckpt/ rgbpose_conv3d/rgbpose_conv3d.pth'

Run the Python demo/demo_skeleton.py demo/ntu_sample.avi demo/demo.mp4 command line and find an error KeyError: 'test_mode'

@followingcode
Copy link
Author

@kennymckormick

@followingcode
Copy link
Author

The code from lines 258 to 265 of demo/demo_skeleton.py is modified as follows:

fake_anno = dict(
frame_dir='',
label=-1,
img_shape=(h, w),
original_shape=(h, w),
start_index=0,
modality='Pose',
total_frames=num_frame,
test_mode = True
)
print('fake_anno', fake_anno)
if not fake_anno['frame_dir']:
fake_anno['frame_dir'] = args.video
print(fake_anno['frame_dir'])

and pyskl/pyskl/apis/inference.py line 173 deleted
And lines 173 to 176 of pyskl/pyskl/apis/inference.py need to be changed to:

output = model(return_loss=False,**data)
        print('Model output' , output)

        if isinstance(output[0], dict):
            if 'pose' in output[0] and 'rgb' in output[0]:
                    # 取出 rgb 和 pose 数据
                    rgb_data = output[0]['rgb']
                    pose_data = output[0]['pose']

                    # 比较两种模态,取最大值
                    scores = np.maximum(rgb_data, pose_data)
            else:
                 raise ValueError('输出字典不包括‘rgb’和‘pose’')
        else:
             scores = output[0]
        
        print('scores type ', type(scores))
        print('socres shape', scores.shape)
        print(scores.ndim)
        if scores.ndim == 1:
            num_classes = scores.shape[0]
            print(num_classes)
        elif scores.ndim > 1:
            num_classes = scores.shape[-1]
        else:
            raise ValueError(f'Unexpected shape: {scores.shape}')

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

1 participant