Spaces:
Runtime error
Runtime error
File size: 3,175 Bytes
fd52b7f |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 |
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import os\n",
"HOME = os.getcwd()\n",
"print(HOME)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Pip install method (recommended)\n",
"\n",
"%pip install ultralytics==8.0.20\n",
"\n",
"from IPython import display\n",
"display.clear_output()\n",
"\n",
"import ultralytics\n",
"ultralytics.checks()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from ultralytics import YOLO\n",
"\n",
"from IPython.display import display, Image"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"!mkdir {HOME}/datasets\n",
"%cd {HOME}/datasets\n",
"\n",
"%pip install roboflow --quiet\n",
"\n",
"from roboflow import Roboflow\n",
"rf = Roboflow(api_key=\"YOUR_API_KEY\")\n",
"project = rf.workspace(\"WORKSPACE\").project(\"PROJECT\")\n",
"dataset = project.version(1).download(\"yolov8\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%cd {HOME}\n",
"\n",
"!yolo task=detect mode=train model=yolov8s.pt data={dataset.location}/data.yaml epochs=25 imgsz=800 plots=True"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%cd {HOME}\n",
"Image(filename=f'{HOME}/runs/detect/train/confusion_matrix.png', width=600)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%cd {HOME}\n",
"Image(filename=f'{HOME}/runs/detect/train/results.png', width=600)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%cd {HOME}\n",
"Image(filename=f'{HOME}/runs/detect/train/val_batch0_pred.jpg', width=600)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%cd {HOME}\n",
"\n",
"!yolo task=detect mode=val model={HOME}/runs/detect/train/weights/best.pt data={dataset.location}/data.yaml"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%cd {HOME}\n",
"!yolo task=detect mode=predict model={HOME}/runs/detect/train/weights/best.pt conf=0.25 source={dataset.location}/test/images save=True"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import glob\n",
"from IPython.display import Image, display\n",
"\n",
"for image_path in glob.glob(f'{HOME}/runs/detect/predict3/*.jpg')[:3]:\n",
" display(Image(filename=image_path, width=600))\n",
" print(\"\\n\")"
]
}
],
"metadata": {
"language_info": {
"name": "python"
},
"orig_nbformat": 4
},
"nbformat": 4,
"nbformat_minor": 2
}
|