mmdetection icon indicating copy to clipboard operation
mmdetection copied to clipboard

AssertionError: The length of palette should not be less than `num_classes`.

Open meng8407 opened this issue 1 year ago • 4 comments

Thanks for your error report and we appreciate it a lot.

Checklist The length of palette should not be less than num_classes. 我的类别数量是40,然而我打印出palette的长度是20,

我运行的代码是: inferencer = DetInferencer(model=config_file,weights=checkpoint_file,device='cuda:0') result = inferencer(imgpath,out_dir=out_dir,show=False)

错误显示是: palette: 20 classes 40 Traceback (most recent call last): File "/home/ai-developer/data/mmdetection-main/inforence_peidian_ceshi.py", line 50, in result = inferencer(imgpath,out_dir=out_dir,show=False)#,show=True File "/home/ai-developer/data/mmdetection-main/mmdet/apis/det_inferencer.py", line 397, in call visualization = self.visualize( File "/home/ai-developer/data/mmdetection-main/mmdet/apis/det_inferencer.py", line 484, in visualize self.visualizer.add_datasample( File "/home/ai-developer/anaconda3/envs/nmmdet/lib/python3.10/site-packages/mmengine/dist/utils.py", line 419, in wrapper return func(*args, **kwargs) File "/home/ai-developer/data/mmdetection-main/mmdet/visualization/local_visualizer.py", line 477, in add_datasample pred_img_data = self._draw_instances(image, pred_instances, File "/home/ai-developer/data/mmdetection-main/mmdet/visualization/local_visualizer.py", line 138, in _draw_instances bbox_palette = get_palette(bbox_color, max_label + 1) File "/home/ai-developer/data/mmdetection-main/mmdet/visualization/palette.py", line 65, in get_palette assert len(dataset_palette) >= num_classes,
AssertionError: The length of palette should not be less than num_classes. 错误问题

meng8407 avatar Feb 04 '24 09:02 meng8407

@meng8407 你可以修改 palette 的长度。或者在推理时候直接指定 --palette random

hhaAndroid avatar Feb 05 '24 02:02 hhaAndroid

@meng8407 你可以修改 palette 的长度。或者在推理时候直接指定 --palette random

您好,我想问在mmdetection源码的哪个位置可以修改palette 我在两场景中都会出现这个问题, 1.运行mmdeploy转tensorrt时候 2.运行的代码 inferencer = DetInferencer(model=config_file,weights=checkpoint_file,device='cuda:0') result = inferencer(imgpath,out_dir=out_dir,show=False)

期待您的回答

meng8407 avatar Feb 05 '24 03:02 meng8407

DetInferencer 在初始化时候是可以传入 palette 参数的,你可以看下

hhaAndroid avatar Feb 05 '24 07:02 hhaAndroid

DetInferencer 在初始化时候是可以传入 palette 参数的,你可以看下

好的,谢谢您

meng8407 avatar Feb 05 '24 07:02 meng8407