Repository: open-mmlab/mmaction2

Issue:
Ava custom model prediction error
Before raising a question, you may need to check the following listed items.

**Checklist**

1. I have searched related issues but cannot get the expected help.
2. I have read the [FAQ documentation](https://mmaction2.readthedocs.io/en/latest/faq.html) but cannot get the expected help.


When training a specific category of ava, change the original custom_classes = [3, 6, 10, 27, 29, 38, 41, 48, 51, 53, 54, 59, 61, 64, 70, 72] to custom_classes = [38 , 41, 48, 51]. When the model predicts, the prediction result of custom_classes=3 will still appear. I expect the prediction result to appear is only 38, 41, 48, 51 these 4 classes



Discussion:
Stdet Results: [[]]
DEBUG:__main__:Main thread inference time 709 ms
DEBUG:__main__:Display thread: 689 ms, read id 29, display id 29
DEBUG:__main__:Read thread: 1633 ms, 18 fps
INFO:__main__:Stdet Results: [[('crouch/kneel', 0.6173151)]]
DEBUG:__main__:Main thread inference time 145 ms
DEBUG:__main__:Display thread: 924 ms, read id 30, display id 30
@dreamerlin @lindahua @hellock @innerlee 
For ava models trained by custom classes, you need a new `--label-map` file for `webcam_demo_spatiotemporal_det.py`

In this case, label map should be 
```
1: open (e.g., a window, a car door)
2: play musical instrument
3: read
4: sail boat
```
Maybe I'll create a pr to fix this at the weekend. For now, you can refer to the previous comment.
I used the original 80 classes, only a few of them were kept, and no new actions were defined
I think I have the answer

Resolving patch:
diff --git a/demo/demo_spatiotemporal_det.py b/demo/demo_spatiotemporal_det.py
--- a/demo/demo_spatiotemporal_det.py
+++ b/demo/demo_spatiotemporal_det.py
@@ -281,9 +281,6 @@ def main():
     num_frame = len(frame_paths)
     h, w, _ = original_frames[0].shape
 
-    # Load label_map
-    label_map = load_label_map(args.label_map)
-
     # resize frames to shortside 256
     new_w, new_h = mmcv.rescale_size((w, h), (256, np.Inf))
     frames = [mmcv.imresize(img, (new_w, new_h)) for img in original_frames]
@@ -300,6 +297,18 @@ def main():
     timestamps = np.arange(window_size // 2, num_frame + 1 - window_size // 2,
                            args.predict_stepsize)
 
+    # Load label_map
+    label_map = load_label_map(args.label_map)
+    try:
+        if config['data']['train']['custom_classes'] is not None:
+            label_map = {
+                id + 1: label_map[cls]
+                for id, cls in enumerate(config['data']['train']
+                                         ['custom_classes'])
+            }
+    except KeyError:
+        pass
+
     # Get Human detection results
     center_frames = [frame_paths[ind - 1] for ind in timestamps]
     human_detections = detection_inference(args, center_frames)
diff --git a/demo/webcam_demo_spatiotemporal_det.py b/demo/webcam_demo_spatiotemporal_det.py
--- a/demo/webcam_demo_spatiotemporal_det.py
+++ b/demo/webcam_demo_spatiotemporal_det.py
@@ -290,6 +290,15 @@ def __init__(self, config, checkpoint, device, score_thr, label_map_path):
             lines = f.readlines()
         lines = [x.strip().split(': ') for x in lines]
         self.label_map = {int(x[0]): x[1] for x in lines}
+        try:
+            if config['data']['train']['custom_classes'] is not None:
+                self.label_map = {
+                    id + 1: self.label_map[cls]
+                    for id, cls in enumerate(config['data']['train']
+                                             ['custom_classes'])
+                }
+        except KeyError:
+            pass
 
     def predict(self, task):
         """Spatio-temporval Action Detection model inference."""


Test patch: