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

Error when trying to train yolov8 model #14664

Closed
1 task done
vrathi101 opened this issue Jul 24, 2024 · 7 comments
Closed
1 task done

Error when trying to train yolov8 model #14664

vrathi101 opened this issue Jul 24, 2024 · 7 comments
Labels
detect Object Detection issues, PR's question Further information is requested

Comments

@vrathi101
Copy link

vrathi101 commented Jul 24, 2024

Search before asking

Question

I followed the Ultralytics documentation online for using YoloV8 for training an object detection model but keep experiencing the following issue. This is the code I ran:

os.chdir('/kaggle/working')
!pip uninstall -y ultralytics
!pip cache purge
!pip install -U ultralytics
from ultralytics import YOLO
model = YOLO("yolov8s.pt")
results = model.train(
data="/kaggle/working/data.yaml", epochs=20,
imgsz=640, batch=-1, save=True
)

I previously installed ultralytics so here I just uninstalled and reinstalled it. the model loads properly but whenever I try training it I get the following error:


FileNotFoundError Traceback (most recent call last)
Cell In[27], line 1
----> 1 results = model.train(
2 data="/kaggle/working/data.yaml", epochs=20,
3 imgsz=640, batch=-1, save=True
4 )

File /opt/conda/lib/python3.10/site-packages/ultralytics/yolo/engine/model.py:189, in YOLO.train(self, **kwargs)
186 if overrides.get("resume"):
187 overrides["resume"] = self.ckpt_path
--> 189 self.trainer = self.TrainerClass(overrides=overrides)
190 if not overrides.get("resume"): # manually set model only if not resuming
191 self.trainer.model = self.trainer.get_model(weights=self.model if self.ckpt else None, cfg=self.model.yaml)

File /opt/conda/lib/python3.10/site-packages/ultralytics/yolo/engine/trainer.py:86, in init(self, config, overrides)

File /opt/conda/lib/python3.10/site-packages/ultralytics/yolo/configs/init.py:25, in get_config(config, overrides)

File /opt/conda/lib/python3.10/site-packages/omegaconf/omegaconf.py:189, in OmegaConf.load(file_)
186 from .utils import get_yaml_loader
188 if isinstance(file
, (str, pathlib.Path)):
--> 189 with io.open(os.path.abspath(file_), "r", encoding="utf-8") as f:
190 obj = yaml.load(f, Loader=get_yaml_loader())
191 elif getattr(file_, "read", None):

FileNotFoundError: [Errno 2] No such file or directory: '/opt/conda/lib/python3.10/site-packages/ultralytics/yolo/configs/default.yaml'

@vrathi101 vrathi101 added the question Further information is requested label Jul 24, 2024
@UltralyticsAssistant UltralyticsAssistant added the detect Object Detection issues, PR's label Jul 24, 2024
Copy link

👋 Hello @vrathi101, thank you for your interest in Ultralytics YOLOv8 🚀! We recommend a visit to the Docs for new users where you can find many Python and CLI usage examples and where many of the most common questions may already be answered.

If this is a 🐛 Bug Report, please provide a minimum reproducible example to help us debug it.

If this is a custom training ❓ Question, please provide as much information as possible, including dataset image examples and training logs, and verify you are following our Tips for Best Training Results.

Join the vibrant Ultralytics Discord 🎧 community for real-time conversations and collaborations. This platform offers a perfect space to inquire, showcase your work, and connect with fellow Ultralytics users.

Install

Pip install the ultralytics package including all requirements in a Python>=3.8 environment with PyTorch>=1.8.

pip install ultralytics

Environments

YOLOv8 may be run in any of the following up-to-date verified environments (with all dependencies including CUDA/CUDNN, Python and PyTorch preinstalled):

Status

Ultralytics CI

If this badge is green, all Ultralytics CI tests are currently passing. CI tests verify correct operation of all YOLOv8 Modes and Tasks on macOS, Windows, and Ubuntu every 24 hours and on every commit.

@Y-T-G
Copy link
Contributor

Y-T-G commented Jul 25, 2024

Just restart the notebook kernel

@vrathi101
Copy link
Author

vrathi101 commented Jul 25, 2024

I tried that but now am getting this error:
AttributeError: module 'torch.amp' has no attribute 'GradScaler'


AttributeError Traceback (most recent call last)
Cell In[5], line 1
----> 1 results = model.train(
2 data="/kaggle/working/data.yaml", epochs=20,
3 imgsz=640, batch=-1, save=True
4 )

File /opt/conda/lib/python3.10/site-packages/ultralytics/engine/model.py:810, in Model.train(self, trainer, **kwargs)
807 self.model = self.trainer.model
809 self.trainer.hub_session = self.session # attach optional HUB session
--> 810 self.trainer.train()
811 # Update model and cfg after training
812 if RANK in {-1, 0}:

File /opt/conda/lib/python3.10/site-packages/ultralytics/engine/trainer.py:206, in BaseTrainer.train(self)
203 ddp_cleanup(self, str(file))
205 else:
--> 206 self._do_train(world_size)

File /opt/conda/lib/python3.10/site-packages/ultralytics/engine/trainer.py:329, in BaseTrainer._do_train(self, world_size)
327 if world_size > 1:
328 self._setup_ddp(world_size)
--> 329 self._setup_train(world_size)
331 nb = len(self.train_loader) # number of batches
332 nw = max(round(self.args.warmup_epochs * nb), 100) if self.args.warmup_epochs > 0 else -1 # warmup iterations

File /opt/conda/lib/python3.10/site-packages/ultralytics/engine/trainer.py:270, in BaseTrainer._setup_train(self, world_size)
267 dist.broadcast(self.amp, src=0) # broadcast the tensor from rank 0 to all other ranks (returns None)
268 self.amp = bool(self.amp) # as boolean
269 self.scaler = (
--> 270 torch.amp.GradScaler("cuda", enabled=self.amp)
271 if TORCH_1_13
272 else torch.cuda.amp.GradScaler(enabled=self.amp)
273 )
274 if world_size > 1:
275 self.model = nn.parallel.DistributedDataParallel(self.model, device_ids=[RANK], find_unused_parameters=True)

AttributeError: module 'torch.amp' has no attribute 'GradScaler'

@vrathi101
Copy link
Author

yes that worked, thank you!

@Laughing-q
Copy link
Member

@vrathi101 closing the issue as it's resolved, please feel free to reopen it if you encounter any related issues. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
detect Object Detection issues, PR's question Further information is requested
Projects
None yet
Development

No branches or pull requests

5 participants
@Y-T-G @Laughing-q @vrathi101 @UltralyticsAssistant and others