Repository: open-mmlab/mmpose

Issue:
ValueError: LinearReIDHead: Please choose at least one loss in triplet loss and cross entropy loss.


**Checklist**

- [✓ ]  I have searched related issues but cannot get the expected help.

- [✓ ]  The bug has not been fixed in the latest version.

**Describe the bug**

While trying to run the **"demo/top_down_pose_tracking_demo_with_mmtracking.py"** i get the error in the title:
`ValueError: LinearReIDHead: Please choose at least one loss in triplet loss and cross entropy loss.`
or
`ValueError: Tracktor: BaseReID: LinearReIDHead: Please choose at least one loss in triplet loss and cross entropy loss.`
I have been successful to run all the other top-down demo. just stuck in this one with mmtracking.

**Reproduction**

- What command or script did you run?

```
python -m demo.top_down_pose_tracking_demo_with_mmtracking demo/mmtracking_cfg/tracktor_faster-rcnn_r50_fpn_4e_mot17-private.py configs/body/2d_kpt_sview_rgb_img/topdown_heatmap/coco/hrnet_w48_coco_256x192.py https://download.openmmlab.com/mmpose/top_down/hrnet/hrnet_w48_coco_256x192-b9e0b3ab_20200708.pth --video-path demo/resources/demo.mp4 --out-video-root vis_results --show

```

- What config did you run?

```
demo/mmtracking_cfg/tracktor_faster-rcnn_r50_fpn_4e_mot17-private.py
configs/body/2d_kpt_sview_rgb_img/topdown_heatmap/coco/hrnet_w48_coco_256x192.py

```

- Did you make any modifications on the code or config? Did you understand what you have modified?
- What dataset did you use?

**Environment**

1. Please run `PYTHONPATH=${PWD}:$PYTHONPATH python mmpose/utils/collect_env.py` to collect necessary environment information and paste it here.
```sys.platform: linux
Python: 3.6.9 (default, Jan 26 2021, 15:33:00) [GCC 8.4.0]
CUDA available: True
GPU 0: GeForce GTX 1080
CUDA_HOME: /usr/local/cuda-10.0
NVCC: Cuda compilation tools, release 10.0, V10.0.130
GCC: gcc (Ubuntu 7.5.0-3ubuntu1~18.04) 7.5.0
PyTorch: 1.4.0+cu100
PyTorch compiling details: PyTorch built with:
  - GCC 7.3
  - Intel(R) Math Kernel Library Version 2019.0.4 Product Build 20190411 for Intel(R) 64 architecture applications
  - Intel(R) MKL-DNN v0.21.1 (Git Hash 7d2fd500bc78936d1d648ca713b901012f470dbc)
  - OpenMP 201511 (a.k.a. OpenMP 4.5)
  - NNPACK is enabled
  - CUDA Runtime 10.0
  - NVCC architecture flags: -gencode;arch=compute_37,code=sm_37;-gencode;arch=compute_50,code=sm_50;-gencode;arch=compute_60,code=sm_60;-gencode;arch=compute_61,code=sm_61;-gencode;arch=compute_70,code=sm_70;-gencode;arch=compute_75,code=sm_75;-gencode;arch=compute_37,code=compute_37
  - CuDNN 7.6.3
  - Magma 2.5.1
  - Build settings: BLAS=MKL, BUILD_NAMEDTENSOR=OFF, BUILD_TYPE=Release, CXX_FLAGS= -Wno-deprecated -fvisibility-inlines-hidden -fopenmp -DUSE_FBGEMM -DUSE_QNNPACK -DUSE_PYTORCH_QNNPACK -O2 -fPIC -Wno-narrowing -Wall -Wextra -Wno-missing-field-initializers -Wno-type-limits -Wno-array-bounds -Wno-unknown-pragmas -Wno-sign-compare -Wno-unused-parameter -Wno-unused-variable -Wno-unused-function -Wno-unused-result -Wno-strict-overflow -Wno-strict-aliasing -Wno-error=deprecated-declarations -Wno-stringop-overflow -Wno-error=pedantic -Wno-error=redundant-decls -Wno-error=old-style-cast -fdiagnostics-color=always -faligned-new -Wno-unused-but-set-variable -Wno-maybe-uninitialized -fno-math-errno -fno-trapping-math -Wno-stringop-overflow, DISABLE_NUMA=1, PERF_WITH_AVX=1, PERF_WITH_AVX2=1, PERF_WITH_AVX512=1, USE_CUDA=ON, USE_EXCEPTION_PTR=1, USE_GFLAGS=OFF, USE_GLOG=OFF, USE_MKL=ON, USE_MKLDNN=ON, USE_MPI=OFF, USE_NCCL=ON, USE_NNPACK=ON, USE_OPENMP=ON, USE_STATIC_DISPATCH=OFF, 

TorchVision: 0.5.0+cu100
OpenCV: 4.5.3
MMCV: 1.3.12
MMCV Compiler: GCC 7.5
MMCV CUDA Compiler: 10.0
MMPose: 0.17.0+e336702
```
1. You may add addition that may be helpful for locating the problem, such as
  - How you installed PyTorch [e.g., pip, conda, source]
  - Other environment variables that may be related (such as `$PATH`, `$LD_LIBRARY_PATH`, `$PYTHONPATH`, etc.)

**Error traceback**

If applicable, paste the error traceback here.

```

/home/user/mmpose/mmpose/env/lib/python3.6/site-packages/mmdet/core/anchor/builder.py:17: UserWarning: ``build_anchor_generator`` would be deprecated soon, please use ``build_prior_generator`` 
  '``build_anchor_generator`` would be deprecated soon, please use '
Traceback (most recent call last):
  File "/home/user/mmpose/mmpose/env/lib/python3.6/site-packages/mmcv/utils/registry.py", line 52, in build_from_cfg
    return obj_cls(**args)
  File "/home/user/mmpose/mmpose/env/lib/python3.6/site-packages/mmtrack/models/reid/linear_reid_head.py", line 58, in __init__
    raise ValueError('Please choose at least one loss in '
ValueError: Please choose at least one loss in triplet loss and cross entropy loss.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/user/mmpose/mmpose/env/lib/python3.6/site-packages/mmcv/utils/registry.py", line 52, in build_from_cfg
    return obj_cls(**args)
  File "/home/user/mmpose/mmpose/env/lib/python3.6/site-packages/mmtrack/models/reid/base_reid.py", line 11, in __init__
    super().__init__(*args, **kwargs)
  File "/home/user/mmpose/mmpose/env/lib/python3.6/site-packages/mmcls/models/classifiers/image.py", line 25, in __init__
    self.head = build_head(head)
  File "/home/user/mmpose/mmpose/env/lib/python3.6/site-packages/mmcls/models/builder.py", line 25, in build_head
    return HEADS.build(cfg)
  File "/home/user/mmpose/mmpose/env/lib/python3.6/site-packages/mmcv/utils/registry.py", line 212, in build
    return self.build_func(*args, **kwargs, registry=self)
  File "/home/user/mmpose/mmpose/env/lib/python3.6/site-packages/mmcv/cnn/builder.py", line 27, in build_model_from_cfg
    return build_from_cfg(cfg, registry, default_args)
  File "/home/user/mmpose/mmpose/env/lib/python3.6/site-packages/mmcv/utils/registry.py", line 55, in build_from_cfg
    raise type(e)(f'{obj_cls.__name__}: {e}')
ValueError: LinearReIDHead: Please choose at least one loss in triplet loss and cross entropy loss.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/user/mmpose/mmpose/env/lib/python3.6/site-packages/mmcv/utils/registry.py", line 52, in build_from_cfg
    return obj_cls(**args)
  File "/home/user/mmpose/mmpose/env/lib/python3.6/site-packages/mmtrack/models/mot/tracktor.py", line 28, in __init__
    self.reid = build_reid(reid)
  File "/home/user/mmpose/mmpose/env/lib/python3.6/site-packages/mmtrack/models/builder.py", line 23, in build_reid
    return REID.build(cfg)
  File "/home/user/mmpose/mmpose/env/lib/python3.6/site-packages/mmcv/utils/registry.py", line 212, in build
    return self.build_func(*args, **kwargs, registry=self)
  File "/home/user/mmpose/mmpose/env/lib/python3.6/site-packages/mmcv/cnn/builder.py", line 27, in build_model_from_cfg
    return build_from_cfg(cfg, registry, default_args)
  File "/home/user/mmpose/mmpose/env/lib/python3.6/site-packages/mmcv/utils/registry.py", line 55, in build_from_cfg
    raise type(e)(f'{obj_cls.__name__}: {e}')
ValueError: BaseReID: LinearReIDHead: Please choose at least one loss in triplet loss and cross entropy loss.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3.6/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/usr/lib/python3.6/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/home/user/mmpose/mmpose/demo/top_down_pose_tracking_demo_with_mmtracking.py", line 165, in <module>
    main()
  File "/home/user/mmpose/mmpose/demo/top_down_pose_tracking_demo_with_mmtracking.py", line 81, in main
    args.tracking_config, None, device=args.device.lower())
  File "/home/user/mmpose/mmpose/env/lib/python3.6/site-packages/mmtrack/apis/inference.py", line 34, in init_model
    model = build_model(config.model)
  File "/home/user/mmpose/mmpose/env/lib/python3.6/site-packages/mmtrack/models/builder.py", line 34, in build_model
    return MODELS.build(cfg)
  File "/home/user/mmpose/mmpose/env/lib/python3.6/site-packages/mmcv/utils/registry.py", line 212, in build
    return self.build_func(*args, **kwargs, registry=self)
  File "/home/user/mmpose/mmpose/env/lib/python3.6/site-packages/mmcv/cnn/builder.py", line 27, in build_model_from_cfg
    return build_from_cfg(cfg, registry, default_args)
  File "/home/user/mmpose/mmpose/env/lib/python3.6/site-packages/mmcv/utils/registry.py", line 55, in build_from_cfg
    raise type(e)(f'{obj_cls.__name__}: {e}')
ValueError: Tracktor: BaseReID: LinearReIDHead: Please choose at least one loss in triplet loss and cross entropy loss.

```





Discussion:
Could you please provide the version information of mmtracking you used?
`mmtrack==0.6.0`


Resolving patch:
diff --git a/demo/mmtracking_cfg/tracktor_faster-rcnn_r50_fpn_4e_mot17-private.py b/demo/mmtracking_cfg/tracktor_faster-rcnn_r50_fpn_4e_mot17-private.py
--- a/demo/mmtracking_cfg/tracktor_faster-rcnn_r50_fpn_4e_mot17-private.py
+++ b/demo/mmtracking_cfg/tracktor_faster-rcnn_r50_fpn_4e_mot17-private.py
@@ -111,10 +111,10 @@
                 max_per_img=100))),
     type='Tracktor',
     pretrains=dict(
-        detector='https://download.openmmlab.com/mmtracking/mot/'
-        'faster_rcnn/faster-rcnn_r50_fpn_4e_mot17-ffa52ae7.pth',
+        detector='https://download.openmmlab.com/mmtracking/'
+        'mot/faster_rcnn/faster-rcnn_r50_fpn_4e_mot17-ffa52ae7.pth',
         reid='https://download.openmmlab.com/mmtracking/mot/'
-        'reid/tracktor_reid_r50_iter25245-a452f51f.pth'),
+        'reid/reid_r50_6e_mot17-4bf6b63d.pth'),
     reid=dict(
         type='BaseReID',
         backbone=dict(
@@ -130,6 +130,10 @@
             in_channels=2048,
             fc_channels=1024,
             out_channels=128,
+            num_classes=378,
+            loss=dict(type='CrossEntropyLoss', loss_weight=1.0),
+            loss_pairwise=dict(
+                type='TripletLoss', margin=0.3, loss_weight=1.0),
             norm_cfg=dict(type='BN1d'),
             act_cfg=dict(type='ReLU'))),
     motion=dict(
@@ -202,7 +206,7 @@
                 std=[58.395, 57.12, 57.375],
                 to_rgb=True),
             dict(type='Pad', size_divisor=32),
-            dict(type='DefaultFormatBundle', keys=['img']),
+            dict(type='ImageToTensor', keys=['img']),
             dict(type='VideoCollect', keys=['img'])
         ])
 ]
@@ -272,7 +276,7 @@
                         std=[58.395, 57.12, 57.375],
                         to_rgb=True),
                     dict(type='Pad', size_divisor=32),
-                    dict(type='DefaultFormatBundle', keys=['img']),
+                    dict(type='ImageToTensor', keys=['img']),
                     dict(type='VideoCollect', keys=['img'])
                 ])
         ]),
@@ -296,7 +300,7 @@
                         std=[58.395, 57.12, 57.375],
                         to_rgb=True),
                     dict(type='Pad', size_divisor=32),
-                    dict(type='DefaultFormatBundle', keys=['img']),
+                    dict(type='ImageToTensor', keys=['img']),
                     dict(type='VideoCollect', keys=['img'])
                 ])
         ]))


Test patch: