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

RuntimeError: An attempt has been made to start a new process before the current process has finished its bootstrapping phase. #75

Open
1 of 2 tasks
jeffreyianwilson opened this issue Nov 1, 2023 · 5 comments
Labels
bug Something isn't working

Comments

@jeffreyianwilson
Copy link

Search before asking

  • I have searched the Autodistill issues and found no similar bug report.

Bug

Microsoft Windows [Version 10.0.22635.2552]
(c) Microsoft Corporation. All rights reserved.

D:\work\dev>C:/Python/Python311/python.exe d:/work/dev/github/autodistill/autodistill.py
WARNING Ultralytics settings reset to defaults. This is normal and may be due to a recent ultralytics package update, but may have overwritten previous settings.
View and update settings with 'yolo settings' or at 'C:\Users\jeffr\AppData\Roaming\Ultralytics\settings.yaml'
trying to load grounding dino directly
C:\Python\Python311\Lib\site-packages\torch\functional.py:504: UserWarning: torch.meshgrid: in an upcoming release, it will be required to pass the indexing argument. (Triggered internally at ..\aten\src\ATen\native\TensorShape.cpp:3484.)
return _VF.meshgrid(tensors, **kwargs) # type: ignore[attr-defined]
final text_encoder_type: bert-base-uncased
New https://pypi.org/project/ultralytics/8.0.203 available Update with 'pip install -U ultralytics'
Ultralytics YOLOv8.0.81 Python-3.11.4 torch-2.0.1+cu118 CUDA:0 (NVIDIA GeForce RTX 4090 Laptop GPU, 16376MiB)
yolo\engine\trainer: task=detect, mode=train, model=yolov8n.pt, data=D:/work/dev/python/segmentation/test/01_input/data.yaml, epochs=200, patience=50, batch=16, imgsz=640, save=True, save_period=-1, cache=False, device=None, workers=8, project=None, name=None, exist_ok=False, pretrained=False, optimizer=SGD, verbose=True, seed=0, deterministic=True, single_cls=False, image_weights=False, rect=False, cos_lr=False, close_mosaic=0, resume=False, amp=True, overlap_mask=True, mask_ratio=4, dropout=0.0, val=True, split=val, save_json=False, save_hybrid=False, conf=None, iou=0.7, max_det=300, half=False, dnn=False, plots=True, source=None, show=False, save_txt=False, save_conf=False, save_crop=False, show_labels=True, show_conf=True, vid_stride=1, line_thickness=3, visualize=False, augment=False, agnostic_nms=False, classes=None, retina_masks=False, boxes=True, format=torchscript, keras=False, optimize=False, int8=False, dynamic=False, simplify=False, opset=None, workspace=4, nms=False, lr0=0.01, lrf=0.01, momentum=0.937, weight_decay=0.0005, warmup_epochs=3.0, warmup_momentum=0.8, warmup_bias_lr=0.1, box=7.5, cls=0.5, dfl=1.5, pose=12.0, kobj=1.0, label_smoothing=0.0, nbs=64, hsv_h=0.015, hsv_s=0.7, hsv_v=0.4, degrees=0.0, translate=0.1, scale=0.5, shear=0.0, perspective=0.0, flipud=0.0, fliplr=0.5, mosaic=1.0, mixup=0.0, copy_paste=0.0, cfg=None, v5loader=False, tracker=botsort.yaml, save_dir=runs\detect\train11
Overriding model.yaml nc=80 with nc=1

               from  n    params  module                                       arguments

0 -1 1 464 ultralytics.nn.modules.Conv [3, 16, 3, 2]
1 -1 1 4672 ultralytics.nn.modules.Conv [16, 32, 3, 2]
2 -1 1 7360 ultralytics.nn.modules.C2f [32, 32, 1, True]
3 -1 1 18560 ultralytics.nn.modules.Conv [32, 64, 3, 2]
4 -1 2 49664 ultralytics.nn.modules.C2f [64, 64, 2, True]
5 -1 1 73984 ultralytics.nn.modules.Conv [64, 128, 3, 2]
6 -1 2 197632 ultralytics.nn.modules.C2f [128, 128, 2, True]
7 -1 1 295424 ultralytics.nn.modules.Conv [128, 256, 3, 2]
8 -1 1 460288 ultralytics.nn.modules.C2f [256, 256, 1, True]
9 -1 1 164608 ultralytics.nn.modules.SPPF [256, 256, 5]
10 -1 1 0 torch.nn.modules.upsampling.Upsample [None, 2, 'nearest']
11 [-1, 6] 1 0 ultralytics.nn.modules.Concat [1]
12 -1 1 148224 ultralytics.nn.modules.C2f [384, 128, 1]
13 -1 1 0 torch.nn.modules.upsampling.Upsample [None, 2, 'nearest']
14 [-1, 4] 1 0 ultralytics.nn.modules.Concat [1]
15 -1 1 37248 ultralytics.nn.modules.C2f [192, 64, 1]
16 -1 1 36992 ultralytics.nn.modules.Conv [64, 64, 3, 2]
17 [-1, 12] 1 0 ultralytics.nn.modules.Concat [1]
18 -1 1 123648 ultralytics.nn.modules.C2f [192, 128, 1]
19 -1 1 147712 ultralytics.nn.modules.Conv [128, 128, 3, 2]
20 [-1, 9] 1 0 ultralytics.nn.modules.Concat [1]
21 -1 1 493056 ultralytics.nn.modules.C2f [384, 256, 1]
22 [15, 18, 21] 1 751507 ultralytics.nn.modules.Detect [1, [64, 128, 256]]
Model summary: 225 layers, 3011043 parameters, 3011027 gradients, 8.2 GFLOPs

Transferred 319/355 items from pretrained weights
TensorBoard: Start with 'tensorboard --logdir runs\detect\train11', view at http://localhost:6006/
AMP: running Automatic Mixed Precision (AMP) checks with YOLOv8n...
AMP: checks passed
optimizer: SGD(lr=0.01) with parameter groups 57 weight(decay=0.0), 64 weight(decay=0.0005), 63 bias
train: Scanning D:\work\dev\python\segmentation\test\01_input\train\labels... 142 images, 1 backgrounds, 0 corrupt: 100%|██████████| 142/142 [00:00<00:00, 1356.82it/s]
train: WARNING D:\work\dev\python\segmentation\test\01_input\train\images\DJI.0473.JPG: 1 duplicate labels removed
train: New cache created: D:\work\dev\python\segmentation\test\01_input\train\labels.cache
trying to load grounding dino directly
C:\Python\Python311\Lib\site-packages\torch\functional.py:504: UserWarning: torch.meshgrid: in an upcoming release, it will be required to pass the indexing argument. (Triggered internally at ..\aten\src\ATen\native\TensorShape.cpp:3484.)
return _VF.meshgrid(tensors, **kwargs) # type: ignore[attr-defined]
final text_encoder_type: bert-base-uncased
New https://pypi.org/project/ultralytics/8.0.203 available Update with 'pip install -U ultralytics'
Ultralytics YOLOv8.0.81 Python-3.11.4 torch-2.0.1+cu118 CUDA:0 (NVIDIA GeForce RTX 4090 Laptop GPU, 16376MiB)
yolo\engine\trainer: task=detect, mode=train, model=yolov8n.pt, data=D:/work/dev/python/segmentation/test/01_input/data.yaml, epochs=200, patience=50, batch=16, imgsz=640, save=True, save_period=-1, cache=False, device=None, workers=8, project=None, name=None, exist_ok=False, pretrained=False, optimizer=SGD, verbose=True, seed=0, deterministic=True, single_cls=False, image_weights=False, rect=False, cos_lr=False, close_mosaic=0, resume=False, amp=True, overlap_mask=True, mask_ratio=4, dropout=0.0, val=True, split=val, save_json=False, save_hybrid=False, conf=None, iou=0.7, max_det=300, half=False, dnn=False, plots=True, source=None, show=False, save_txt=False, save_conf=False, save_crop=False, show_labels=True, show_conf=True, vid_stride=1, line_thickness=3, visualize=False, augment=False, agnostic_nms=False, classes=None, retina_masks=False, boxes=True, format=torchscript, keras=False, optimize=False, int8=False, dynamic=False, simplify=False, opset=None, workspace=4, nms=False, lr0=0.01, lrf=0.01, momentum=0.937, weight_decay=0.0005, warmup_epochs=3.0, warmup_momentum=0.8, warmup_bias_lr=0.1, box=7.5, cls=0.5, dfl=1.5, pose=12.0, kobj=1.0, label_smoothing=0.0, nbs=64, hsv_h=0.015, hsv_s=0.7, hsv_v=0.4, degrees=0.0, translate=0.1, scale=0.5, shear=0.0, perspective=0.0, flipud=0.0, fliplr=0.5, mosaic=1.0, mixup=0.0, copy_paste=0.0, cfg=None, v5loader=False, tracker=botsort.yaml, save_dir=runs\detect\train12
Overriding model.yaml nc=80 with nc=1

               from  n    params  module                                       arguments

0 -1 1 464 ultralytics.nn.modules.Conv [3, 16, 3, 2]
1 -1 1 4672 ultralytics.nn.modules.Conv [16, 32, 3, 2]
2 -1 1 7360 ultralytics.nn.modules.C2f [32, 32, 1, True]
3 -1 1 18560 ultralytics.nn.modules.Conv [32, 64, 3, 2]
4 -1 2 49664 ultralytics.nn.modules.C2f [64, 64, 2, True]
5 -1 1 73984 ultralytics.nn.modules.Conv [64, 128, 3, 2]
6 -1 2 197632 ultralytics.nn.modules.C2f [128, 128, 2, True]
7 -1 1 295424 ultralytics.nn.modules.Conv [128, 256, 3, 2]
8 -1 1 460288 ultralytics.nn.modules.C2f [256, 256, 1, True]
9 -1 1 164608 ultralytics.nn.modules.SPPF [256, 256, 5]
10 -1 1 0 torch.nn.modules.upsampling.Upsample [None, 2, 'nearest']
11 [-1, 6] 1 0 ultralytics.nn.modules.Concat [1]
12 -1 1 148224 ultralytics.nn.modules.C2f [384, 128, 1]
13 -1 1 0 torch.nn.modules.upsampling.Upsample [None, 2, 'nearest']
14 [-1, 4] 1 0 ultralytics.nn.modules.Concat [1]
15 -1 1 37248 ultralytics.nn.modules.C2f [192, 64, 1]
16 -1 1 36992 ultralytics.nn.modules.Conv [64, 64, 3, 2]
17 [-1, 12] 1 0 ultralytics.nn.modules.Concat [1]
18 -1 1 123648 ultralytics.nn.modules.C2f [192, 128, 1]
19 -1 1 147712 ultralytics.nn.modules.Conv [128, 128, 3, 2]
20 [-1, 9] 1 0 ultralytics.nn.modules.Concat [1]
21 -1 1 493056 ultralytics.nn.modules.C2f [384, 256, 1]
22 [15, 18, 21] 1 751507 ultralytics.nn.modules.Detect [1, [64, 128, 256]]
Model summary: 225 layers, 3011043 parameters, 3011027 gradients, 8.2 GFLOPs

Transferred 319/355 items from pretrained weights
TensorBoard: Start with 'tensorboard --logdir runs\detect\train12', view at http://localhost:6006/
AMP: running Automatic Mixed Precision (AMP) checks with YOLOv8n...
AMP: checks passed
optimizer: SGD(lr=0.01) with parameter groups 57 weight(decay=0.0), 64 weight(decay=0.0005), 63 bias
train: Scanning D:\work\dev\python\segmentation\test\01_input\train\labels.cache... 142 images, 1 backgrounds, 0 corrupt: 100%|██████████| 142/142 [00:00<?, ?it/s]
train: WARNING D:\work\dev\python\segmentation\test\01_input\train\images\DJI.0473.JPG: 1 duplicate labels removed
Traceback (most recent call last):
File "", line 1, in
File "C:\Python\Python311\Lib\multiprocessing\spawn.py", line 120, in spawn_main
exitcode = _main(fd, parent_sentinel)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Python\Python311\Lib\multiprocessing\spawn.py", line 129, in _main
prepare(preparation_data)
File "C:\Python\Python311\Lib\multiprocessing\spawn.py", line 240, in prepare
_fixup_main_from_path(data['init_main_from_path'])
File "C:\Python\Python311\Lib\multiprocessing\spawn.py", line 291, in _fixup_main_from_path
main_content = runpy.run_path(main_path,
^^^^^^^^^^^^^^^^^^^^^^^^^
File "", line 291, in run_path
File "", line 98, in _run_module_code
File "", line 88, in _run_code
File "d:\work\dev\github\autodistill\autodistill.py", line 18, in
target_model.train("D:/work/dev/python/segmentation/test/01_input/data.yaml", epochs=200)
File "C:\Python\Python311\Lib\site-packages\autodistill_yolov8\yolov8.py", line 13, in train
self.yolo.train(data=dataset_yaml, epochs=epochs)
File "C:\Python\Python311\Lib\site-packages\ultralytics\yolo\engine\model.py", line 371, in train
self.trainer.train()
File "C:\Python\Python311\Lib\site-packages\ultralytics\yolo\engine\trainer.py", line 191, in train
self._do_train(world_size)
File "C:\Python\Python311\Lib\site-packages\ultralytics\yolo\engine\trainer.py", line 268, in _do_train
self._setup_train(world_size)
File "C:\Python\Python311\Lib\site-packages\ultralytics\yolo\engine\trainer.py", line 250, in _setup_train
self.train_loader = self.get_dataloader(self.trainset, batch_size=batch_size, rank=RANK, mode='train')
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Python\Python311\Lib\site-packages\ultralytics\yolo\v8\detect\train.py", line 43, in get_dataloader
build_dataloader(self.args, batch_size, img_path=dataset_path, stride=gs, rank=rank, mode=mode,
File "C:\Python\Python311\Lib\site-packages\ultralytics\yolo\data\build.py", line 100, in build_dataloader
return loader(
^^^^^^^
File "C:\Python\Python311\Lib\site-packages\ultralytics\yolo\data\build.py", line 30, in init
self.iterator = super().iter()
^^^^^^^^^^^^^^^^^^
File "C:\Python\Python311\Lib\site-packages\torch\utils\data\dataloader.py", line 441, in iter
return self._get_iterator()
^^^^^^^^^^^^^^^^^^^^
File "C:\Python\Python311\Lib\site-packages\torch\utils\data\dataloader.py", line 388, in _get_iterator
return _MultiProcessingDataLoaderIter(self)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Python\Python311\Lib\site-packages\torch\utils\data\dataloader.py", line 1042, in init
w.start()
File "C:\Python\Python311\Lib\multiprocessing\process.py", line 121, in start
self._popen = self._Popen(self)
^^^^^^^^^^^^^^^^^
File "C:\Python\Python311\Lib\multiprocessing\context.py", line 224, in _Popen
return _default_context.get_context().Process._Popen(process_obj)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Python\Python311\Lib\multiprocessing\context.py", line 336, in _Popen
return Popen(process_obj)
^^^^^^^^^^^^^^^^^^
File "C:\Python\Python311\Lib\multiprocessing\popen_spawn_win32.py", line 45, in init
prep_data = spawn.get_preparation_data(process_obj._name)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Python\Python311\Lib\multiprocessing\spawn.py", line 158, in get_preparation_data
_check_not_importing_main()
File "C:\Python\Python311\Lib\multiprocessing\spawn.py", line 138, 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.

Environment

No response

Minimal Reproducible Example

from autodistill_grounded_sam import GroundedSAM
from autodistill_yolov8 import YOLOv8
from autodistill.detection.caption_ontology import CaptionOntology

# define an ontology to map class names to our GroundingDINO prompt
# the ontology dictionary has the format {caption: class}
# where caption is the prompt sent to the base model, and class is the label that will
# be saved for that caption in the generated annotations
base_model = GroundedSAM(ontology=CaptionOntology({"car": "car"}))

# label all images in a folder called `context_images`
#base_model.label(
#  input_folder="D:/work/dev/python/segmentation/test/01_input/",
#  output_folder="D:/work/dev/python/segmentation/test/01_input/"
#)

target_model = YOLOv8("yolov8n.pt")
target_model.train("D:/work/dev/python/segmentation/test/01_input/data.yaml", epochs=200)

# run inference on the new model
pred = target_model.predict("D:/work/dev/python/segmentation/test/01_input/DJI.0377.JPG", confidence=0.5)
print(pred)

Additional

No response

Are you willing to submit a PR?

  • Yes I'd like to help by submitting a PR!
@jeffreyianwilson jeffreyianwilson added the bug Something isn't working label Nov 1, 2023
@capjamesg
Copy link
Member

This looks like an issue with ultralytics. We are working on upgrading the package since autodistill-yolov8 is running an outdated version. We hope for this update to be out in the next day, which may fix your issue. I will let you know here when the update is live.

@capjamesg
Copy link
Member

A new version of autodistill-yolov8 is now released. Can you run pip install --upgrade autodistill-yolov8 and run your script again?

@jeffreyianwilson
Copy link
Author

same error.

@capjamesg
Copy link
Member

capjamesg commented Jan 31, 2024

Can you try enclosing your .train() in:

if __name__ == "__main__":
    target_model.train(...)
    ...

@capjamesg
Copy link
Member

Is this still a problem? If there is no response in a few days, we will close this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants