{
 "schema_version": 1,
 "generated": "2026-10-31",
 "id": "ultralytics-ultralytics--train-a-custom-yolo-model-in-python",
 "repo": "ultralytics/ultralytics",
 "repo_url": "https://github.com/ultralytics/ultralytics",
 "repo_slug": "ultralytics-ultralytics",
 "title": "Train and validate a YOLO model on your dataset",
 "page_title": "How to train and validate a YOLO model on your dataset with Ultralytics",
 "summary": "Fine-tune YOLO26n on a dataset config, then check its metrics on the validation set.",
 "who": "A team building detection for its own objects, like products on a shelf.",
 "problem": "Pretrained classes rarely match the objects you care about.",
 "outcome": "A trained model with validation metrics.",
 "steps": [
  "Install with `pip install ultralytics`",
  "In Python load the model with YOLO(\"yolo26n.pt\")",
  "Call model.train with data set to your dataset yaml (the README uses coco8.yaml), epochs and imgsz",
  "Call model.val() to evaluate on the validation set"
 ],
 "agent_prompt": "With ultralytics/ultralytics, write a Python script that loads YOLO(\"yolo26n.pt\"), trains on <my dataset yaml> for 100 epochs at imgsz 640 like the README example, runs model.val(), and prints the key metrics.",
 "agents": [
  "claude-code",
  "codex",
  "cursor",
  "gemini-cli"
 ],
 "difficulty": "Intermediate",
 "time": "1 to 3 hours",
 "basis": "readme",
 "caveat": "Training on CPU works per the README example but is slow.",
 "category": "Data and analytics",
 "tags": [
  "Data and analytics"
 ],
 "lang": "python",
 "requirements": [
  "Python 3.8 or newer with pip (PyTorch is installed with the package requirements)",
  "A GPU is optional for prediction and recommended for training",
  "Images or video to run on, or a dataset config for training"
 ],
 "risk": "none",
 "seen_in_the_wild": false,
 "mentioned_publicly": false,
 "risks": [
  {
   "tag": "platform",
   "notice": "AGPL-3.0: commercial closed-source use needs an Ultralytics enterprise license."
  }
 ],
 "best": false,
 "score": 0.9,
 "evidence": [],
 "url": "https://dedupedai.com/use-cases/ultralytics-ultralytics/train-a-custom-yolo-model-in-python/",
 "md": "https://dedupedai.com/use-cases/ultralytics-ultralytics/train-a-custom-yolo-model-in-python/index.md",
 "disclaimer": "Deduped lists open-source repositories that belong to other people. We do not own, maintain, audit, or vouch for any of them, and a repo appearing here is not an endorsement or a safety check. The use cases, steps, and prompts are written by AI and may be incomplete, outdated, or just wrong. Where a use case is marked \"Seen in the wild\", we link to public posts where someone described something similar, but we have not verified those posts and the use case itself is still our AI's own write-up. Use all of this at your own risk. Only run code, commands, or agents on systems and accounts you are authorized to use, and read the code and every command before you run it, especially anything that touches credentials, files, or the network. Nothing here is professional, security, legal, or financial advice. All trademarks and project names belong to their respective owners, and their use here does not imply affiliation. Content is provided as is, without warranties of any kind. Found a mistake, a safety problem, or something you want removed? Email hello@dedupedai.com and we will look at it promptly.",
 "api": "https://dedupedai.com/api/v1/usecases/ultralytics-ultralytics--train-a-custom-yolo-model-in-python.json",
 "api_version": "v1"
}
