DDGRCF / YOLOX_OBB

https://zhuanlan.zhihu.com/p/430850089
Apache License 2.0
147 stars 19 forks source link

ValueError: tuple.index(x): x not in tuple #39

Closed KajiMaCN closed 1 year ago

KajiMaCN commented 1 year ago

How can I solve the following error?

/root/anaconda3/envs/yolox_dect/lib/python3.7/site-packages/torch/cuda/init.py:104: UserWarning: NVIDIA A100-SXM4-40GB with CUDA capability sm_80 is not compatible with the current PyTorch installation. The current PyTorch install supports CUDA capabilities sm_37 sm_50 sm_60 sm_61 sm_70 sm_75 compute_37. If you want to use the NVIDIA A100-SXM4-40GB GPU with PyTorch, please check the instructions at https://pytorch.org/get-started/locally/

warnings.warn(incompatible_device_warn.format(device_name, capability, " ".join(arch_list), device_name)) 2023-05-09 07:44:56 | INFO | yolox.models.parse_model:18 - overriding modules.yaml num_classes=80 with num_classes=1 2023-05-09 07:44:56 | INFO | yolox.core.trainer:138 - Model Summary: Params: 8.05M, Gflops: 55.78 2023-05-09 08:01:59 | ERROR | yolox.core.launch:98 - An error has been caught in function 'launch', process 'MainProcess' (5309), thread 'MainThread' (140538046510016): Traceback (most recent call last):

File "tools/train.py", line 133, in args=(exp, args), │ └ Namespace(batch_size=16, cache=False, ckpt=None, devices=1, dist_backend='nccl', dist_url=None, exp_file='/YOLOX_OBB/exps/exa... └ ╒═════════════════════╤═════════════════════════════════════════════════════════════════════════════════════════════════════╕...

File "/install/YOLOX_OBB/yolox/core/launch.py", line 98, in launch main_func(*args) │ └ (╒═════════════════════╤═════════════════════════════════════════════════════════════════════════════════════════════════════... └ <function main at 0x7fd18f4883b0>

File "tools/train.py", line 108, in main trainer.train() │ └ <function Trainer.train at 0x7fd04498ad40> └ <yolox.core.trainer.Trainer object at 0x7fd100c6c190>

File "/install/YOLOX_OBB/yolox/core/trainer.py", line 72, in train self.before_train() │ └ <function Trainer.before_train at 0x7fd0449a09e0> └ <yolox.core.trainer.Trainer object at 0x7fd100c6c190>

File "/install/YOLOX_OBB/yolox/core/trainer.py", line 154, in before_train cache_img=self.args.cache, │ │ └ False │ └ Namespace(batch_size=16, cache=False, ckpt=None, devices=1, dist_backend='nccl', dist_url=None, exp_file='/YOLOX_OBB/exps/exa... └ <yolox.core.trainer.Trainer object at 0x7fd100c6c190>

File "/install/YOLOX_OBB/yolox/exp/yolox_obb_base.py", line 132, in get_data_loader work_dir=os.path.join(self.output_dir, self.exp_name) │ │ │ │ │ │ └ 'obb' │ │ │ │ │ └ ╒═════════════════════╤═════════════════════════════════════════════════════════════════════════════════════════════════════╕... │ │ │ │ └ 'YOLOX_outputs' │ │ │ └ ╒═════════════════════╤═════════════════════════════════════════════════════════════════════════════════════════════════════╕... │ │ └ <function join at 0x7fd1903c2cb0> │ └ <module 'posixpath' from '/root/anaconda3/envs/yolox_dect/lib/python3.7/posixpath.py'> └ <module 'os' from '/root/anaconda3/envs/yolox_dect/lib/python3.7/os.py'>

File "/install/YOLOX_OBB/yolox/data/datasets/mosaicdetection.py", line 414, in init self.aug_ignore_list = self._aug_ignore_convert(aug_ignore) │ │ │ └ ['roundabout', 'storage-tank'] │ │ └ <function MosaicOBBDetection._aug_ignore_convert at 0x7fd0449858c0> │ └ <yolox.data.datasets.mosaicdetection.MosaicOBBDetection object at 0x7fd0e7e88e50> └ <yolox.data.datasets.mosaicdetection.MosaicOBBDetection object at 0x7fd0e7e88e50>

File "/install/YOLOX_OBB/yolox/data/datasets/mosaicdetection.py", line 428, in _aug_ignore_convert ignore_list.append(self._dataset.CLASSES.index(item)) │ │ │ │ │ │ └ 'roundabout' │ │ │ │ │ └ <method 'index' of 'tuple' objects> │ │ │ │ └ ('s', 'h', 'i', 'p') │ │ │ └ <yolox.data.datasets.dota.DOTADataset object at 0x7fd0aced9f90> │ │ └ <yolox.data.datasets.mosaicdetection.MosaicOBBDetection object at 0x7fd0e7e88e50> │ └ <method 'append' of 'list' objects> └ []

ValueError: tuple.index(x): x not in tuple

DDGRCF commented 1 year ago

https://github.com/DDGRCF/YOLOX_OBB/blob/986dbee50c7a0ccbeb4c7db94d672db8a2a7e3a2/exps/example/yolox_obb/yolox_s_dota1_0.py#L23

try to change self.aug_ignore = ['roundabout', 'storage-tank'] to self.aug_ignore = [] in your custom exps config

KajiMaCN commented 1 year ago

https://github.com/DDGRCF/YOLOX_OBB/blob/986dbee50c7a0ccbeb4c7db94d672db8a2a7e3a2/exps/example/yolox_obb/yolox_s_dota1_0.py#L23

try to change self.aug_ignore = ['roundabout', 'storage-tank'] to self.aug_ignore = [] in your custom exps config

Thanks for your help. Also, in Line 28, if it is set to true here, there will be no images in the resulting images folder, should I change it to false?

KajiMaCN commented 1 year ago

https://github.com/DDGRCF/YOLOX_OBB/blob/986dbee50c7a0ccbeb4c7db94d672db8a2a7e3a2/exps/example/yolox_obb/yolox_s_dota1_0.py#L23

try to change self.aug_ignore = ['roundabout', 'storage-tank'] to self.aug_ignore = [] in your custom exps config

I have changed self.aug_ignore = ['roundabout', 'storage-tank'] to self.aug_ignore = [] by referring to your way. But the following error occurs:

*******************************
activate env yolox_dect
*******************************
Current dir is /workspace/YOLOX_OBB
exp is /workspace/YOLOX_OBB/exps/example/yolox_obb/yolox_s_my_planes.py
cuda_device is cuda: 0
num_device is 1
batch_size is 8
other args: 
find YOLOX_outputs/abc, do you want to del(y or n):y
already del YOLOX_outputs/abc
2023-05-10 16:54:31 | INFO     | yolox.core.trainer:131 - args: Namespace(batch_size=8, cache=False, ckpt=None, devices=1, dist_backend='nccl', dist_url=None, exp_file='/workspace/YOLOX_OBB/exps/example/yolox_obb/yolox_s_my_planes.py', experiment_name='abc', fp16=False, machine_rank=0, name=None, num_machines=1, occupy=False, options=None, resume=False, start_epoch=None)
2023-05-10 16:54:31 | INFO     | yolox.core.trainer:132 - exp value:
╒═════════════════════╤════════════════════════════════════════════════════════╕
│ keys                │ values                                                 │
╞═════════════════════╪════════════════════════════════════════════════════════╡
│ seed                │ None                                                   │
├─────────────────────┼────────────────────────────────────────────────────────┤
│ output_dir          │ 'YOLOX_outputs'                                        │
├─────────────────────┼────────────────────────────────────────────────────────┤
│ print_interval      │ 10                                                     │
├─────────────────────┼────────────────────────────────────────────────────────┤
│ eval_interval       │ 10                                                     │
├─────────────────────┼────────────────────────────────────────────────────────┤
│ modules_config      │ 'configs/modules/yoloxs_obb.yaml'                      │
├─────────────────────┼────────────────────────────────────────────────────────┤
│ losses_config       │ 'configs/losses/yolox_losses_obb.yaml'                 │
├─────────────────────┼────────────────────────────────────────────────────────┤
│ dataset_config      │ '/workspace/YOLOX_OBB/configs/datasets/my_planes.yaml' │
├─────────────────────┼────────────────────────────────────────────────────────┤
│ data_num_workers    │ 4                                                      │
├─────────────────────┼────────────────────────────────────────────────────────┤
│ input_size          │ (1024, 1024)                                           │
├─────────────────────┼────────────────────────────────────────────────────────┤
│ multiscale_range    │ 5                                                      │
├─────────────────────┼────────────────────────────────────────────────────────┤
│ mosaic_prob         │ 1.0                                                    │
├─────────────────────┼────────────────────────────────────────────────────────┤
│ mixup_prob          │ 0.0                                                    │
├─────────────────────┼────────────────────────────────────────────────────────┤
│ hsv_prob            │ 1.0                                                    │
├─────────────────────┼────────────────────────────────────────────────────────┤
│ flip_prob           │ 0.5                                                    │
├─────────────────────┼────────────────────────────────────────────────────────┤
│ degrees             │ 10.0                                                   │
├─────────────────────┼────────────────────────────────────────────────────────┤
│ translate           │ 0.1                                                    │
├─────────────────────┼────────────────────────────────────────────────────────┤
│ mosaic_scale        │ (0.4, 1.2)                                             │
├─────────────────────┼────────────────────────────────────────────────────────┤
│ mixup_scale         │ (0.4, 1.2)                                             │
├─────────────────────┼────────────────────────────────────────────────────────┤
│ shear               │ 2.0                                                    │
├─────────────────────┼────────────────────────────────────────────────────────┤
│ enable_mixup        │ True                                                   │
├─────────────────────┼────────────────────────────────────────────────────────┤
│ warmup_epochs       │ 1                                                      │
├─────────────────────┼────────────────────────────────────────────────────────┤
│ max_epoch           │ 80                                                     │
├─────────────────────┼────────────────────────────────────────────────────────┤
│ warmup_lr           │ 0                                                      │
├─────────────────────┼────────────────────────────────────────────────────────┤
│ basic_lr_per_img    │ 0.00015625                                             │
├─────────────────────┼────────────────────────────────────────────────────────┤
│ scheduler           │ 'yoloxwarmcos'                                         │
├─────────────────────┼────────────────────────────────────────────────────────┤
│ no_aug_epochs       │ 2                                                      │
├─────────────────────┼────────────────────────────────────────────────────────┤
│ min_lr_ratio        │ 0.05                                                   │
├─────────────────────┼────────────────────────────────────────────────────────┤
│ ema                 │ True                                                   │
├─────────────────────┼────────────────────────────────────────────────────────┤
│ no_eval             │ True                                                   │
├─────────────────────┼────────────────────────────────────────────────────────┤
│ weight_decay        │ 0.0005                                                 │
├─────────────────────┼────────────────────────────────────────────────────────┤
│ momentum            │ 0.9                                                    │
├─────────────────────┼────────────────────────────────────────────────────────┤
│ exp_name            │ 'abc'                                                  │
├─────────────────────┼────────────────────────────────────────────────────────┤
│ test_size           │ (1024, 1024)                                           │
├─────────────────────┼────────────────────────────────────────────────────────┤
│ postprocess_cfg     │ {'conf_thre': 0.05, 'nms_thre': 0.1}                   │
├─────────────────────┼────────────────────────────────────────────────────────┤
│ copy_paste_prob     │ 1.0                                                    │
├─────────────────────┼────────────────────────────────────────────────────────┤
│ enable_debug        │ False                                                  │
├─────────────────────┼────────────────────────────────────────────────────────┤
│ enable_resample     │ True                                                   │
├─────────────────────┼────────────────────────────────────────────────────────┤
│ aug_ignore          │ []                                                     │
├─────────────────────┼────────────────────────────────────────────────────────┤
│ empty_ignore        │ True                                                   │
├─────────────────────┼────────────────────────────────────────────────────────┤
│ long_wh_thre        │ 6                                                      │
├─────────────────────┼────────────────────────────────────────────────────────┤
│ short_wh_thre       │ 3                                                      │
├─────────────────────┼────────────────────────────────────────────────────────┤
│ overlaps_thre       │ 0.6                                                    │
├─────────────────────┼────────────────────────────────────────────────────────┤
│ evaluate_cfg        │ {'is_merge': False, 'is_submiss': False, 'nproc': 10}  │
├─────────────────────┼────────────────────────────────────────────────────────┤
│ export_input_names  │ ['input']                                              │
├─────────────────────┼────────────────────────────────────────────────────────┤
│ export_output_names │ ['boxes', 'scores', 'class']                           │
├─────────────────────┼────────────────────────────────────────────────────────┤
│ include_post        │ True                                                   │
├─────────────────────┼────────────────────────────────────────────────────────┤
│ data_dir            │ '/workspace/data/split_ss_dota1_0'                     │
├─────────────────────┼────────────────────────────────────────────────────────┤
│ train_ann           │ 'train'                                                │
├─────────────────────┼────────────────────────────────────────────────────────┤
│ val_ann             │ 'val'                                                  │
├─────────────────────┼────────────────────────────────────────────────────────┤
│ test_ann            │ 'test'                                                 │
├─────────────────────┼────────────────────────────────────────────────────────┤
│ num_classes         │ 1                                                      │
╘═════════════════════╧════════════════════════════════════════════════════════╛
2023-05-10 16:54:31 | INFO     | yolox.models.parse_model:18 - overriding modules.yaml num_classes=80 with num_classes=1
2023-05-10 16:54:32 | INFO     | yolox.core.trainer:138 - Model Summary: Params: 8.05M, Gflops: 55.78
2023-05-10 16:54:35 | ERROR    | yolox.core.launch:98 - An error has been caught in function 'launch', process 'MainProcess' (3948), thread 'MainThread' (140618233053888):
Traceback (most recent call last):

  File "tools/train.py", line 133, in <module>
    args=(exp, args),
          │    └ Namespace(batch_size=8, cache=False, ckpt=None, devices=1, dist_backend='nccl', dist_url=None, exp_file='/workspace/YOLOX_OBB...
          └ ╒═════════════════════╤═════════════════════════════════════════════════════════════════════════════════════════════════════╕...

> File "/workspace/YOLOX_OBB/yolox/core/launch.py", line 98, in launch
    main_func(*args)
    │          └ (╒═════════════════════╤═════════════════════════════════════════════════════════════════════════════════════════════════════...
    └ <function main at 0x7fe43ac75320>

  File "tools/train.py", line 108, in main
    trainer.train()
    │       └ <function Trainer.train at 0x7fe32d346b90>
    └ <yolox.core.trainer.Trainer object at 0x7fe3b5c956d0>

  File "/workspace/YOLOX_OBB/yolox/core/trainer.py", line 72, in train
    self.before_train()
    │    └ <function Trainer.before_train at 0x7fe32d35c830>
    └ <yolox.core.trainer.Trainer object at 0x7fe3b5c956d0>

  File "/workspace/YOLOX_OBB/yolox/core/trainer.py", line 154, in before_train
    cache_img=self.args.cache,
              │    │    └ False
              │    └ Namespace(batch_size=8, cache=False, ckpt=None, devices=1, dist_backend='nccl', dist_url=None, exp_file='/workspace/YOLOX_OBB...
              └ <yolox.core.trainer.Trainer object at 0x7fe3b5c956d0>

  File "/workspace/YOLOX_OBB/yolox/exp/yolox_obb_base.py", line 132, in get_data_loader
    work_dir=os.path.join(self.output_dir, self.exp_name)
             │  │    │    │    │           │    └ 'abc'
             │  │    │    │    │           └ ╒═════════════════════╤═════════════════════════════════════════════════════════════════════════════════════════════════════╕...
             │  │    │    │    └ 'YOLOX_outputs'
             │  │    │    └ ╒═════════════════════╤═════════════════════════════════════════════════════════════════════════════════════════════════════╕...
             │  │    └ <function join at 0x7fe43bb9bcb0>
             │  └ <module 'posixpath' from '/home/anaconda3/envs/yolox_dect/lib/python3.7/posixpath.py'>
             └ <module 'os' from '/home/anaconda3/envs/yolox_dect/lib/python3.7/os.py'>

  File "/workspace/YOLOX_OBB/yolox/data/datasets/mosaicdetection.py", line 414, in __init__
    self.aug_ignore_list = self._aug_ignore_convert(aug_ignore)
    │                      │    │                   └ []
    │                      │    └ <function MosaicOBBDetection._aug_ignore_convert at 0x7fe32d33e710>
    │                      └ <yolox.data.datasets.mosaicdetection.MosaicOBBDetection object at 0x7fe3b5c8b650>
    └ <yolox.data.datasets.mosaicdetection.MosaicOBBDetection object at 0x7fe3b5c8b650>

  File "/workspace/YOLOX_OBB/yolox/data/datasets/mosaicdetection.py", line 425, in _aug_ignore_convert
    if isinstance(aug_ignore[0], str):
                  └ []

IndexError: list index out of range
/workspace/YOLOX_OBB/configs/datasets

I tried changing self.aug_ignore = ['roundabout', 'storage-tank'] to self.aug_ignore =None and the above error does not occur. But the same problem as in #16 arises, the program does not run. Do you know how can I fix it?

KajiMaCN commented 1 year ago

I have solved this problem and the following is my experience, which I hope will provide some help to those who have the same problem. If you have the same problem as #16, please confirm the pkl file you generated, which can be checked by opening the pkl file with the following code:

import pickle

path='path/to/ori_annfile.pkl'
with open(path, 'rb') as f:
    data = pickle.load(f)

Use debugging to check if the internal data is empty or some other problem.

For me, the reason for this problem is that a new "my_planes" has been defined in BboxToolkit Line38, as follows:

dataset_classes = {
    ...
    ...
    'HRSC_cls': ('01', '02', '03', '04', '05', '06', '07', '08', '09', '10',
                 '11', '12', '13', '14', '15', '16', '17', '18', '19', '20',
                 '21', '22', '23', '24', '25', '26', '27', '28', '29', '30',
                 '31', '32', '33'),
    'MSRA_TD500': ('text', ),
    'RCTW_17': ('text', ),
    'my_planes': ('ship')
}

In subsequent code processing, 'ship' is split into 's' 'h' 'i' 'p', so be sure to check that when your custom category is only one class, that class is followed by ','. So the correct code would be: 'my_planes': ('ship') --> 'my_planes': ('ship',)