open-mmlab / mmdetection

OpenMMLab Detection Toolbox and Benchmark
https://mmdetection.readthedocs.io
Apache License 2.0
28.56k stars 9.29k forks source link

Training with my own dataset and I got SyntaxError: invalid syntax #7533

Closed BaeSukkyoung closed 2 years ago

BaeSukkyoung commented 2 years ago

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

Checklist

  1. I have searched related issues but cannot get the expected help.
  2. I have read the FAQ documentation but cannot get the expected help.
  3. The bug has not been fixed in the latest version.

Describe the bug A clear and concise description of what the bug is.

Reproduction

  1. What command or script did you run?

I run the ./tools/dist_train.sh configs/cascade_mask_rcnn_x101_64x4d_fpn_1x_coco.py 4 .

A placeholder for the command.
  1. Did you make any modifications on the code or config? Did you understand what you have modified?

I make some modifications on the config. 'cascade_mask_rcnn_x101_64x4d_fpn_1x_coco' for concrete crack dataset.

  1. What dataset did you use?

I used my own dataset about concrete crack. I also made concrete_crack.py on mmdetection/mmdet/datasets. And add concrete_crack_classes on init.py & class_names.py on mmdetection/mmdet/core/evaluation/class_names.py

Environment

  1. Please run python mmdet/utils/collect_env.py to collect necessary environment information and paste it here.
  2. 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 trackback here.


Traceback (most recent call last): File "./tools/train.py", line 16, in from mmdet.apis import set_random_seed, train_detector File "/home/user/mmdetection/mmdet/apis/init.py", line 2, in from .inference import (async_inference_detector, inference_detector, File "/home/user/mmdetection/mmdet/apis/inference.py", line 11, in from mmdet.core import get_classes File "/home/user/mmdetection/mmdet/core/init.py", line 5, in from .evaluation import # noqa: F401, F403 File "/home/user/mmdetection/mmdet/core/evaluation/init.py", line 2, in from .class_names import (concrete_crack_classes, cityscapes_classes, coco_classes, dataset_aliases, File "/home/user/mmdetection/mmdet/core/evaluation/class_names.py", line 106 'concrete_crack': ['concrete_crack'] ^ SyntaxError: invalid syntax Traceback (most recent call last): File "./tools/train.py", line 16, in from mmdet.apis import set_random_seed, train_detector File "/home/user/mmdetection/mmdet/apis/init.py", line 2, in from .inference import (async_inference_detector, inference_detector, File "/home/user/mmdetection/mmdet/apis/inference.py", line 11, in from mmdet.core import get_classes File "/home/user/mmdetection/mmdet/core/init.py", line 5, in from .evaluation import # noqa: F401, F403 File "/home/user/mmdetection/mmdet/core/evaluation/init.py", line 2, in from .class_names import (concrete_crack_classes, cityscapes_classes, coco_classes, dataset_aliases, File "/home/user/mmdetection/mmdet/core/evaluation/class_names.py", line 106 'concrete_crack': ['concrete_crack'] ^ SyntaxError: invalid syntax Traceback (most recent call last): File "./tools/train.py", line 16, in from mmdet.apis import set_random_seed, train_detector File "/home/user/mmdetection/mmdet/apis/init.py", line 2, in from .inference import (async_inference_detector, inference_detector, File "/home/user/mmdetection/mmdet/apis/inference.py", line 11, in from mmdet.core import get_classes File "/home/user/mmdetection/mmdet/core/init.py", line 5, in from .evaluation import # noqa: F401, F403 File "/home/user/mmdetection/mmdet/core/evaluation/init.py", line 2, in from .class_names import (concrete_crack_classes, cityscapes_classes, coco_classes, dataset_aliases, File "/home/user/mmdetection/mmdet/core/evaluation/class_names.py", line 106 'concrete_crack': ['concrete_crack'] ^ SyntaxError: invalid syntax Traceback (most recent call last): File "./tools/train.py", line 16, in from mmdet.apis import set_random_seed, train_detector File "/home/user/mmdetection/mmdet/apis/init.py", line 2, in from .inference import (async_inference_detector, inference_detector, File "/home/user/mmdetection/mmdet/apis/inference.py", line 11, in from mmdet.core import get_classes File "/home/user/mmdetection/mmdet/core/init.py", line 5, in from .evaluation import # noqa: F401, F403 File "/home/user/mmdetection/mmdet/core/evaluation/init.py", line 2, in from .class_names import (concrete_crack_classes, cityscapes_classes, coco_classes, dataset_aliases, File "/home/user/mmdetection/mmdet/core/evaluation/class_names.py", line 106 'concrete_crack': ['concrete_crack'] ^ SyntaxError: invalid syntax Killing subprocess 23071 Killing subprocess 23072 Killing subprocess 23073 Killing subprocess 23074 Traceback (most recent call last): File "/usr/lib/python3.7/runpy.py", line 193, in _run_module_as_main "main", mod_spec) File "/usr/lib/python3.7/runpy.py", line 85, in _run_code exec(code, run_globals) File "/home/user/python-envs/mmdet/lib/python3.7/site-packages/torch/distributed/launch.py", line 340, in main() File "/home/user/python-envs/mmdet/lib/python3.7/site-packages/torch/distributed/launch.py", line 326, in main sigkill_handler(signal.SIGTERM, None) # not coming back File "/home/user/python-envs/mmdet/lib/python3.7/site-packages/torch/distributed/launch.py", line 301, in sigkill_handler raise subprocess.CalledProcessError(returncode=last_return_code, cmd=cmd) subprocess.CalledProcessError: Command '['/home/user/python-envs/mmdet/bin/python', '-u', './tools/train.py', '--local_rank=3', 'configs/shm_training/cascade_rcnn_x101_64x4d_fpn_1x_for_concrete_crack_220325.py', '--launcher', 'pytorch']' returned non-zero exit status 1.

A placeholder for trackback.

Bug fix If you have already identified the reason, you can provide the information here. If you are willing to create a PR to fix it, please also leave a comment here and that would be much appreciated!

BIGWangYuDong commented 2 years ago

what code did you change? maybe you loss ',' in your code

BaeSukkyoung commented 2 years ago

I changed "class_names.py" under like this.

Copyright (c) OpenMMLab. All rights reserved.

import mmcv

def wider_face_classes(): return ['face']

def voc_classes(): return [ 'aeroplane', 'bicycle', 'bird', 'boat', 'bottle', 'bus', 'car', 'cat', 'chair', 'cow', 'diningtable', 'dog', 'horse', 'motorbike', 'person', 'pottedplant', 'sheep', 'sofa', 'train', 'tvmonitor' ]

def imagenet_det_classes(): return [ 'accordion', 'airplane', 'ant', 'antelope', 'apple', 'armadillo', 'artichoke', 'axe', 'baby_bed', 'backpack', 'bagel', 'balance_beam', 'banana', 'band_aid', 'banjo', 'baseball', 'basketball', 'bathing_cap', 'beaker', 'bear', 'bee', 'bell_pepper', 'bench', 'bicycle', 'binder', 'bird', 'bookshelf', 'bow_tie', 'bow', 'bowl', 'brassiere', 'burrito', 'bus', 'butterfly', 'camel', 'can_opener', 'car', 'cart', 'cattle', 'cello', 'centipede', 'chain_saw', 'chair', 'chime', 'cocktail_shaker', 'coffee_maker', 'computer_keyboard', 'computer_mouse', 'corkscrew', 'cream', 'croquet_ball', 'crutch', 'cucumber', 'cup_or_mug', 'diaper', 'digital_clock', 'dishwasher', 'dog', 'domestic_cat', 'dragonfly', 'drum', 'dumbbell', 'electric_fan', 'elephant', 'face_powder', 'fig', 'filing_cabinet', 'flower_pot', 'flute', 'fox', 'french_horn', 'frog', 'frying_pan', 'giant_panda', 'goldfish', 'golf_ball', 'golfcart', 'guacamole', 'guitar', 'hair_dryer', 'hair_spray', 'hamburger', 'hammer', 'hamster', 'harmonica', 'harp', 'hat_with_a_wide_brim', 'head_cabbage', 'helmet', 'hippopotamus', 'horizontal_bar', 'horse', 'hotdog', 'iPod', 'isopod', 'jellyfish', 'koala_bear', 'ladle', 'ladybug', 'lamp', 'laptop', 'lemon', 'lion', 'lipstick', 'lizard', 'lobster', 'maillot', 'maraca', 'microphone', 'microwave', 'milk_can', 'miniskirt', 'monkey', 'motorcycle', 'mushroom', 'nail', 'neck_brace', 'oboe', 'orange', 'otter', 'pencil_box', 'pencil_sharpener', 'perfume', 'person', 'piano', 'pineapple', 'ping-pong_ball', 'pitcher', 'pizza', 'plastic_bag', 'plate_rack', 'pomegranate', 'popsicle', 'porcupine', 'power_drill', 'pretzel', 'printer', 'puck', 'punching_bag', 'purse', 'rabbit', 'racket', 'ray', 'red_panda', 'refrigerator', 'remote_control', 'rubber_eraser', 'rugby_ball', 'ruler', 'salt_or_pepper_shaker', 'saxophone', 'scorpion', 'screwdriver', 'seal', 'sheep', 'ski', 'skunk', 'snail', 'snake', 'snowmobile', 'snowplow', 'soap_dispenser', 'soccer_ball', 'sofa', 'spatula', 'squirrel', 'starfish', 'stethoscope', 'stove', 'strainer', 'strawberry', 'stretcher', 'sunglasses', 'swimming_trunks', 'swine', 'syringe', 'table', 'tape_player', 'tennis_ball', 'tick', 'tie', 'tiger', 'toaster', 'traffic_light', 'train', 'trombone', 'trumpet', 'turtle', 'tv_or_monitor', 'unicycle', 'vacuum', 'violin', 'volleyball', 'waffle_iron', 'washer', 'water_bottle', 'watercraft', 'whale', 'wine_bottle', 'zebra' ]

def imagenet_vid_classes(): return [ 'airplane', 'antelope', 'bear', 'bicycle', 'bird', 'bus', 'car', 'cattle', 'dog', 'domestic_cat', 'elephant', 'fox', 'giant_panda', 'hamster', 'horse', 'lion', 'lizard', 'monkey', 'motorcycle', 'rabbit', 'red_panda', 'sheep', 'snake', 'squirrel', 'tiger', 'train', 'turtle', 'watercraft', 'whale', 'zebra' ]

def coco_classes(): return [ 'person', 'bicycle', 'car', 'motorcycle', 'airplane', 'bus', 'train', 'truck', 'boat', 'traffic_light', 'fire_hydrant', 'stop_sign', 'parking_meter', 'bench', 'bird', 'cat', 'dog', 'horse', 'sheep', 'cow', 'elephant', 'bear', 'zebra', 'giraffe', 'backpack', 'umbrella', 'handbag', 'tie', 'suitcase', 'frisbee', 'skis', 'snowboard', 'sports_ball', 'kite', 'baseball_bat', 'baseball_glove', 'skateboard', 'surfboard', 'tennis_racket', 'bottle', 'wine_glass', 'cup', 'fork', 'knife', 'spoon', 'bowl', 'banana', 'apple', 'sandwich', 'orange', 'broccoli', 'carrot', 'hot_dog', 'pizza', 'donut', 'cake', 'chair', 'couch', 'potted_plant', 'bed', 'dining_table', 'toilet', 'tv', 'laptop', 'mouse', 'remote', 'keyboard', 'cell_phone', 'microwave', 'oven', 'toaster', 'sink', 'refrigerator', 'book', 'clock', 'vase', 'scissors', 'teddy_bear', 'hair_drier', 'toothbrush' ]

def cityscapes_classes(): return [ 'person', 'rider', 'car', 'truck', 'bus', 'train', 'motorcycle', 'bicycle' ]

_def concrete_crackclasses(): return [ 'background', 'crack' ]

dataset_aliases = { 'voc': ['voc', 'pascal_voc', 'voc07', 'voc12'], 'imagenet_det': ['det', 'imagenet_det', 'ilsvrc_det'], 'imagenet_vid': ['vid', 'imagenet_vid', 'ilsvrc_vid'], 'coco': ['coco', 'mscoco', 'ms_coco'], 'wider_face': ['WIDERFaceDataset', 'widerface', 'WIDERFace'], 'cityscapes': ['cityscapes'] **'concrete_crack': ['concretecrack']** }

def get_classes(dataset): """Get class names of a dataset.""" alias2name = {} for name, aliases in dataset_aliases.items(): for alias in aliases: alias2name[alias] = name

if mmcv.is_str(dataset):
    if dataset in alias2name:
        labels = eval(alias2name[dataset] + '_classes()')
    else:
        raise ValueError(f'Unrecognized dataset: {dataset}')
else:
    raise TypeError(f'dataset must a str, but got {type(dataset)}')
return labels
BIGWangYuDong commented 2 years ago

dataset_aliases = { 'voc': ['voc', 'pascal_voc', 'voc07', 'voc12'], 'imagenet_det': ['det', 'imagenet_det', 'ilsvrc_det'], 'imagenet_vid': ['vid', 'imagenet_vid', 'ilsvrc_vid'], 'coco': ['coco', 'mscoco', 'ms_coco'], 'wider_face': ['WIDERFaceDataset', 'wider_face', 'WIDERFace'], 'cityscapes': ['cityscapes'] 'concrete_crack': ['concrete_crack'] }

you loss ",", you need add a , behind 'cityscapes': ['cityscapes']

BaeSukkyoung commented 2 years ago

After doing what you said, another problem arose under like this.

Traceback (most recent call last): File "./tools/train.py", line 16, in Traceback (most recent call last): Traceback (most recent call last): File "./tools/train.py", line 16, in File "./tools/train.py", line 16, in from mmdet.apis import set_random_seed, train_detector File "/home/user/mmdetection/mmdet/apis/init.py", line 2, in Traceback (most recent call last): File "./tools/train.py", line 16, in from mmdet.apis import set_random_seed, train_detectorfrom mmdet.apis import set_random_seed, train_detectorfrom .inference import (async_inference_detector, inference_detector,

File "/home/user/mmdetection/mmdet/apis/inference.py", line 12, in

File "/home/user/mmdetection/mmdet/apis/init.py", line 2, in File "/home/user/mmdetection/mmdet/apis/init.py", line 2, in from mmdet.datasets import replace_ImageToTensor File "/home/user/mmdetection/mmdet/datasets/init.py", line 17, in from .inference import (async_inference_detector, inference_detector,
from .inference import (async_inference_detector, inference_detector, File "/home/user/mmdetection/mmdet/apis/inference.py", line 12, in File "/home/user/mmdetection/mmdet/apis/inference.py", line 12, in from mmdet.apis import set_random_seed, train_detector from .concrete_crack import ConcreteCrack from mmdet.datasets import replace_ImageToTensorfrom mmdet.datasets import replace_ImageToTensor

File "/home/user/mmdetection/mmdet/apis/init.py", line 2, in

File "/home/user/mmdetection/mmdet/datasets/concrete_crack.py", line 2, in File "/home/user/mmdetection/mmdet/datasets/init.py", line 17, in File "/home/user/mmdetection/mmdet/datasets/init.py", line 17, in from .registry import DATASETSfrom .inference import (async_inference_detector, inference_detector,

from .concrete_crack import ConcreteCrackModuleNotFoundErrorfrom .concrete_crack import ConcreteCrack File "/home/user/mmdetection/mmdet/apis/inference.py", line 12, in

: No module named 'mmdet.datasets.registry' File "/home/user/mmdetection/mmdet/datasets/concrete_crack.py", line 2, in File "/home/user/mmdetection/mmdet/datasets/concrete_crack.py", line 2, in

        from .registry import DATASETSfrom mmdet.datasets import replace_ImageToTensorfrom .registry import DATASETS

ModuleNotFoundError File "/home/user/mmdetection/mmdet/datasets/init.py", line 17, in : ModuleNotFoundErrorNo module named 'mmdet.datasets.registry': No module named 'mmdet.datasets.registry' from .concrete_crack import ConcreteCrack File "/home/user/mmdetection/mmdet/datasets/concrete_crack.py", line 2, in from .registry import DATASETS ModuleNotFoundError: No module named 'mmdet.datasets.registry' Killing subprocess 4028 Killing subprocess 4029 Killing subprocess 4030 Killing subprocess 4031 Traceback (most recent call last): File "/usr/lib/python3.7/runpy.py", line 193, in _run_module_as_main "main", mod_spec) File "/usr/lib/python3.7/runpy.py", line 85, in _run_code exec(code, run_globals) File "/home/user/python-envs/mmdet/lib/python3.7/site-packages/torch/distributed/launch.py", line 340, in main() File "/home/user/python-envs/mmdet/lib/python3.7/site-packages/torch/distributed/launch.py", line 326, in main sigkill_handler(signal.SIGTERM, None) # not coming back File "/home/user/python-envs/mmdet/lib/python3.7/site-packages/torch/distributed/launch.py", line 301, in sigkill_handler raise subprocess.CalledProcessError(returncode=last_return_code, cmd=cmd) subprocess.CalledProcessError: Command '['/home/user/python-envs/mmdet/bin/python', '-u', './tools/train.py', '--local_rank=3', 'configs/shm_training/cascade_rcnn_x101_64x4d_fpn_1x_for_concrete_crack_220325.py', '--launcher', 'pytorch']' returned non-zero exit status 1.

BIGWangYuDong commented 2 years ago

from .registry import DATASETSfrom mmdet.datasets import replace_ImageToTensorfrom .registry import DATASETS

Seems this is a typo error that you write in your code. Also, please check your path

BaeSukkyoung commented 2 years ago

Thx. Then, where can I change the number of epoch ? which script.. I cannot find it.

BIGWangYuDong commented 2 years ago

https://mmdetection.readthedocs.io/en/v2.21.0/tutorials/config.html There some tutorials may help you understand MMDet

BaeSukkyoung commented 2 years ago

Thx. I find and change the epoch then...

'The old API of register_module(module, force=False) ' [>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>] 356/353, 9.0 task/s, elapsed: 40s, ETA: 0s

Traceback (most recent call last): File "./tools/train.py", line 189, in main() File "./tools/train.py", line 185, in main meta=meta) File "/home/user/kec-detection/mmdetection/mmdet/apis/train.py", line 211, in train_detector runner.run(data_loaders, cfg.workflow) File "/home/user/kec-detection/mmcv/mmcv/runner/epoch_based_runner.py", line 127, in run epoch_runner(data_loaders[i], kwargs) File "/home/user/kec-detection/mmcv/mmcv/runner/epoch_based_runner.py", line 54, in train self.call_hook('after_train_epoch') File "/home/user/kec-detection/mmcv/mmcv/runner/base_runner.py", line 307, in call_hook getattr(hook, fn_name)(self) File "/home/user/kec-detection/mmcv/mmcv/runner/hooks/evaluation.py", line 267, in after_train_epoch self._do_evaluate(runner) File "/home/user/kec-detection/mmdetection/mmdet/core/evaluation/eval_hooks.py", line 58, in _do_evaluate key_score = self.evaluate(runner, results) File "/home/user/kec-detection/mmcv/mmcv/runner/hooks/evaluation.py", line 360, in evaluate results, logger=runner.logger, self.eval_kwargs) File "/home/user/kec-detection/mmdetection/mmdet/datasets/coco.py", line 414, in evaluate result_files, tmp_dir = self.format_results(results, jsonfile_prefix) File "/home/user/kec-detection/mmdetection/mmdet/datasets/coco.py", line 359, in format_results result_files = self.results2json(results, jsonfile_prefix) File "/home/user/kec-detection/mmdetection/mmdet/datasets/coco.py", line 296, in results2json json_results = self._segm2json(results) File "/home/user/kec-detection/mmdetection/mmdet/datasets/coco.py", line 247, in _segm2json data['category_id'] = self.cat_ids[label] IndexError: list index out of range Traceback (most recent call last): File "/usr/lib/python3.7/runpy.py", line 193, in _run_module_as_main "main", mod_spec) File "/usr/lib/python3.7/runpy.py", line 85, in _run_code exec(code, run_globals) File "/home/user/python-envs/kec-detect/lib/python3.7/site-packages/torch/distributed/launch.py", line 260, in main() File "/home/user/python-envs/kec-detect/lib/python3.7/site-packages/torch/distributed/launch.py", line 256, in main cmd=cmd) subprocess.CalledProcessError: Command '['/home/user/python-envs/kec-detect/bin/python', '-u', './tools/train.py', '--local_rank=3', 'configs/cascade_mask_rcnn_x101_64x4d_fpn_1x_concrete_crack_220328.py', '--launcher', 'pytorch']' returned non-zero exit status 1.

I got this error, what does it mean ? It means that my dataset include the object which doesn't need to be detected ?

BIGWangYuDong commented 2 years ago

maybe your num class is not equal to bbox_head.num_class. you need to check your config file