Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I'm trying to train custom keypoint detection model and running into some errors #4732

Closed
Codeveen opened this issue Jan 2, 2023 · 2 comments

Comments

@Codeveen
Copy link

Codeveen commented Jan 2, 2023

This is my program so far:
`register_coco_instances("mesh_train", {}, "../mesh_coco_Train.json", "../Data/Train/Images")
register_coco_instances("mesh_test", {}, "../mesh_coco_Test.json", "../Data/Test/Images")

MetadataCatalog.get("mesh_train").keypoint_names = ["joints"]
MetadataCatalog.get("mesh_train").keypoint_flip_map = []
train_dicts = DatasetCatalog.get("mesh_train")
test_dicts = DatasetCatalog.get("mesh_test")
mesh_metadata = MetadataCatalog.get("mesh_train")

def cv2_imshow(im):
im = cv2.cvtColor(im, cv2.COLOR_BGR2RGB)
plt.figure(), plt.imshow(im), plt.axis('off')
plt.show()

for d in random.sample(train_dicts, 5):
print(d["file_name"])
img = cv2.imread(d["file_name"])
visualizer = Visualizer(img[:, :, ::-1], metadata=mesh_metadata, scale=0.5)
vis = visualizer.draw_dataset_dict(d)
cv2_imshow(vis.get_image()[:, :, ::-1])

cfg = get_cfg()
cfg.merge_from_file(model_zoo.get_config_file("COCO-Keypoints/keypoint_rcnn_R_50_FPN_3x.yaml"))
cfg.DATASETS.TRAIN = ("mesh_train",)
cfg.DATASETS.TEST = ("mesh_test",)
cfg.DATALOADER.NUM_WORKERS = 4
cfg.MODEL.WEIGHTS = model_zoo.get_checkpoint_url("COCO-Keypoints/keypoint_rcnn_R_50_FPN_3x.yaml")
cfg.SOLVER.IMS_PER_BATCH = 2
cfg.SOLVER.BASE_LR = 0.001
cfg.SOLVER.MAX_ITER = 300
cfg.MODEL.ROI_HEADS.BATCH_SIZE_PER_IMAGE = 128
cfg.MODEL.ROI_HEADS.NUM_CLASSES = 1

os.makedirs(cfg.OUTPUT_DIR, exist_ok=True)
trainer = DefaultTrainer(cfg)
trainer.resume_or_load(resume=False)

print("training....")
trainer.train()`

But when I run it, I'm getting the following error:

[01/02 13:47:51 d2.engine.train_loop]: Starting training from iteration 0
ERROR [01/02 13:47:51 d2.engine.train_loop]: Exception during training:
Traceback (most recent call last):
File "C:\Users\Singh Automation\AppData\Local\Programs\Python\Python310\lib\site-packages\detectron2\engine\train_loop.py", line 149, in train
self.run_step()
File "C:\Users\Singh Automation\AppData\Local\Programs\Python\Python310\lib\site-packages\detectron2\engine\defaults.py", line 494, in run_step
self._trainer.run_step()
File "C:\Users\Singh Automation\AppData\Local\Programs\Python\Python310\lib\site-packages\detectron2\engine\train_loop.py", line 268, in run_step
data = next(self._data_loader_iter)
File "C:\Users\Singh Automation\AppData\Local\Programs\Python\Python310\lib\site-packages\detectron2\data\common.py", line 283, in iter
for d in self.dataset:
File "C:\Users\Singh Automation\AppData\Local\Programs\Python\Python310\lib\site-packages\torch\utils\data\dataloader.py", line 435, in iter
return self._get_iterator()
File "C:\Users\Singh Automation\AppData\Local\Programs\Python\Python310\lib\site-packages\torch\utils\data\dataloader.py", line 381, in _get_iterator
return _MultiProcessingDataLoaderIter(self)
File "C:\Users\Singh Automation\AppData\Local\Programs\Python\Python310\lib\site-packages\torch\utils\data\dataloader.py", line 1034, in init
w.start()
File "C:\Users\Singh Automation\AppData\Local\Programs\Python\Python310\lib\multiprocessing\process.py", line 121, in start
self._popen = self._Popen(self)
File "C:\Users\Singh Automation\AppData\Local\Programs\Python\Python310\lib\multiprocessing\context.py", line 224, in _Popen
return _default_context.get_context().Process._Popen(process_obj)
File "C:\Users\Singh Automation\AppData\Local\Programs\Python\Python310\lib\multiprocessing\context.py", line 336, in _Popen
return Popen(process_obj)
File "C:\Users\Singh Automation\AppData\Local\Programs\Python\Python310\lib\multiprocessing\popen_spawn_win32.py", line 45, in init
prep_data = spawn.get_preparation_data(process_obj._name)
File "C:\Users\Singh Automation\AppData\Local\Programs\Python\Python310\lib\multiprocessing\spawn.py", line 154, in get_preparation_data
_check_not_importing_main()
File "C:\Users\Singh Automation\AppData\Local\Programs\Python\Python310\lib\multiprocessing\spawn.py", line 134, in _check_not_importing_main
raise RuntimeError('''
RuntimeError:
An attempt has been made to start a new process before the
current process has finished its bootstrapping phase.

    This probably means that you are not using fork to start your
    child processes and you have forgotten to use the proper idiom
    in the main module:

        if __name__ == '__main__':
            freeze_support()
            ...

    The "freeze_support()" line can be omitted if the program
    is not going to be frozen to produce an executable.

[01/02 13:47:51 d2.engine.hooks]: Total training time: 0:00:00 (0:00:00 on hooks)
[01/02 13:47:51 d2.utils.events]: iter: 0 lr: N/A max_mem: 228M

@github-actions github-actions bot added the needs-more-info More info is needed to complete the issue label Jan 2, 2023
@github-actions
Copy link

github-actions bot commented Jan 2, 2023

You've chosen to report an unexpected problem or bug. Unless you already know the root cause of it, please include details about it by filling the issue template.
The following information is missing: "Instructions To Reproduce the Issue and Full Logs"; "Your Environment";

@github-actions github-actions bot removed the needs-more-info More info is needed to complete the issue label Jan 2, 2023
@ppwwyyxx
Copy link
Contributor

As the error says, code should be put into if __name__ == '__main__':

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 9, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants