You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Navigate to [Google Colab](https://colab.research.google.com/) and sign in (right upper corner) with your Google account. Create a new notebook by clicking **New notebook**.
39
40
@@ -104,109 +105,56 @@ The last setup step is to install the YOLO library. There are two ways to do thi
104
105
105
106
---
106
107
107
-
## Preparing the files
108
+
### Preparing the files
108
109
109
-
Before training, you need to upload your dataset and the configuration file to Colab. There are several approaches:
110
+
Before training, you need to upload your dataset and the configuration file to Colab. There are multiple options available to do this, like mounting Google Drive (especially for larger datasets), or downloading from an URL link. We take a closer look on the easiest option: to directly upload the files to the Colab session.
110
111
111
-
xxxxxxxxxxxxxxx
112
-
xxxxxxxxxxxxx
112
+
On the left side of colab you see the files icon :material-folder-outline:. By clicking on it, something like a file explorer will open. We can now upload the files by simply dragging and dropping the files into this area. In our case, we want to upload the `annotations` folder and the `config.yaml` file. For both we need to make small changes compared to the local training.
113
113
114
+
Since the upload only allows files, the `annotations` folder can not be uploaded directly. Therefore we need to create a zip file (here called `annotated.zip`) of the folder and upload this file instead.
115
+
The upload can take a few minutes. The progress is shown in the bottom of the file explorer.
A popup will ask you to authorize access. After mounting, your files are accessible at `/content/drive/MyDrive/`.
146
-
147
-
### Option B: Direct Upload (Small Datasets)
148
-
149
-
For small datasets, you can upload directly to the Colab session:
150
-
151
-
```python
152
-
from google.colab import files
153
-
uploaded = files.upload() # Opens file picker
154
-
```
126
+
After the unzipping, the `annotations` folder should be available in the file explorer.
155
127
156
128
???+ warning "Session Storage"
157
129
Files uploaded directly to Colab are **temporary** and will be deleted when the session ends. Use Google Drive for persistent storage.
158
130
159
-
### Option C: Download from URL
160
-
161
-
If your dataset is hosted online (e.g., GitHub, cloud storage):
162
-
163
-
```python
164
-
!wget https://example.com/your-dataset.zip
165
-
!unzip your-dataset.zip -d /content/dataset
166
-
```
167
-
168
-
---
169
-
170
-
## Training in Colab
171
131
172
-
### Install Ultralytics
132
+
The second file we need to upload is the `config.yaml` file. We already created this file in the [training chapter](training.md#configuration-file). We need to make small changes to the path to the dataset.
173
133
174
-
First, install the YOLO library:
175
-
176
-
```python
177
-
!pip install ultralytics -q
178
-
```
179
-
180
-
The `-q` flag suppresses verbose output.
181
-
182
-
### Create Configuration File
183
-
184
-
Create the `config.yaml` file directly in Colab. The paths need to point to your mounted Google Drive location:
Some self performed tests to train the model for 10 epochs on ~300 images showed the following time consumption:
244
173
245
-
After training completes, you need to save your model before the Colab session expires.
174
+
- locally on a CPU (in this case an Intel Core i9-12900): ~8.5 minutes.
175
+
- locally on a GPU (in this case a NVIDIA GeForce RTX 3060): ~1.5 minutes.
176
+
- in Colab on a Tesla T4 GPU: ~1.5 minutes.
246
177
247
-
### Copy to Google Drive
178
+
What we can see here is that the performance of the training depends massively on the hardware. If you are not in possession of a GPU, it is a good idea to use Colab to train your model.
248
179
249
-
```python
250
-
import shutil
251
-
252
-
# Copy best model to Google Drive
253
-
shutil.copy(
254
-
'/content/runs/detect/train/weights/best.pt',
255
-
'/content/drive/MyDrive/yolo_training/best.pt'
256
-
)
257
180
258
-
# Copy last model as backup
259
-
shutil.copy(
260
-
'/content/runs/detect/train/weights/last.pt',
261
-
'/content/drive/MyDrive/yolo_training/last.pt'
262
-
)
263
-
264
-
print("Models saved to Google Drive!")
265
-
```
181
+
### Working with the results
266
182
267
-
### Download to Local Machine
183
+
After the training is finished, we can work with the results just as we did locally. In the colab file explorer you can see the `runs` folder with the same results as explained in the [training chapter](training.md#training-results).
184
+
Everything - including the model weights - can be downloaded by right clicking on the file and selecting "Download".
268
185
269
-
Alternatively, download the model directly to your computer:
186
+
How to download all files? You can use the following code in a new code cell in colab:
print("Training complete! Model saved to Google Drive.")
191
+
os.system('zip -r runs.zip runs/detect/trainX')
320
192
```
321
193
322
-
---
323
-
324
-
## Tips for Colab Training
325
-
326
-
???+ tip "Prevent Session Timeout"
327
-
Free Colab sessions disconnect after ~90 minutes of inactivity. Keep the browser tab active during training. For longer runs, consider [Colab Pro](https://colab.research.google.com/signup).
328
-
329
-
???+ tip "Check GPU Allocation"
330
-
Sometimes Colab assigns a slower GPU or no GPU at all due to high demand. Always verify GPU availability before starting long training runs.
331
-
332
-
???+ tip "Use Checkpoints"
333
-
If training might exceed session limits, save intermediate checkpoints to Google Drive:
334
-
```python
335
-
model.train(data='config.yaml', epochs=50, save_period=10) # Save every 10 epochs
336
-
```
337
-
338
-
???+ tip "Resume Training"
339
-
If your session disconnects, you can resume training from the last checkpoint:
340
-
```python
341
-
model = YOLO('/content/drive/MyDrive/yolo_training/last.pt')
You have now trained your own YOLO model on Google Colab. If you to not have a GPU, this is a really good way to speed up the training process.
369
204
370
-
For our Euro note detection project, Colab enables training that would otherwise be impractical on a CPU-only laptop. The trained model can then be downloaded and used locally for inference.
371
-
372
-
After completing the training (either locally or in Colab), proceed to the [Inference chapter](./inference.md) to test your model on real images and video streams.
Copy file name to clipboardExpand all lines: docs/yolo/train/index.md
-4Lines changed: 0 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -25,10 +25,6 @@ Let's get started! 🚀
25
25
26
26
In addition to the theoretical foundation, we will look at the following chapters using a practical example. This will enable us to better understand and apply the theoretical concepts.
27
27
28
-
???+ warning "Training Hardware"
29
-
Training a YOLO model requires a lot of computational resources. The best way to train a computer vision model is to use a GPU. Since a lot of you might work on a laptop without a GPU you can try to train the model on a CPU, but it will take much longer to train the model.
30
-
If your hardware is limited, it is a good idea to use a free online service like [Google Colab](https://colab.research.google.com/) or [Kaggle](https://www.kaggle.com/) to train your model. In the [bonus chapter](colab.md) you will find a guide on how to use Colab to train your model.
Training a YOLO model requires a lot of computational resources. The best way to train a computer vision model is to use a GPU. Since a lot of you might work on a laptop without a GPU you can try to train the model on a CPU, but it will take much longer to train the model.
126
+
If your hardware is limited, it is a good idea to use a free online service like [Google Colab](https://colab.research.google.com/) or [Kaggle](https://www.kaggle.com/) to train your model. In the [bonus chapter](colab.md) you will find a guide on how to use Colab to train your model.
0 commit comments