|
3 | 3 | import shutil
|
4 | 4 | import os
|
5 | 5 |
|
6 |
| -####################################################################################################################### |
7 |
| -## 🎯 The aim of this script is to do transfert learning on YOLOv8 model. ## |
8 |
| -## ℹ️ Note on the environments variables: ## |
9 |
| -## - YOLO_MODEL (default value yolo11n.pt) is the YOLO model you want fine tune ## |
10 |
| -## - NB_OF_EPOCHS (default value: 50) is an environment variable passed to the Docker run command to specify ## |
11 |
| -## the number of epochs ## |
12 |
| -## - DEVICE_TO_USE (default value 0) is to specify to use GPU (0) or CPU (cpu) ## |
13 |
| -## - PATH_TO_DATASET (default value is '/workspace/data/data.yaml') is to specify the path to the ## |
14 |
| -## training dataset ## |
15 |
| -## - PATH_TO_EXPORTED_MODEL (default value is '/workspace/data/') is to specify the path where export the ## |
16 |
| -## trained model ## |
17 |
| -####################################################################################################################### |
| 6 | +######################################################################################################################### |
| 7 | +## 🎯 The aim of this script is to do transfert learning on YOLOv11 model. ## |
| 8 | +## ℹ️ Note on the environments variables: ## |
| 9 | +## - NB_OF_EPOCHS (default value: 50) is an environment variable passed to the Docker run command to specify ## |
| 10 | +## the number of epochs ## |
| 11 | +## - DEVICE_TO_USE (default value 0) is to specify to use GPU (0) or CPU (cpu) ## |
| 12 | +## - PATH_TO_DATASET (default value is '/workspace/attendee/data.yaml') is to specify the path to the ## |
| 13 | +## training dataset ## |
| 14 | +## - PATH_TO_EXPORTED_MODEL (default value is '/workspace/attendee/') is to specify the path where export the ## |
| 15 | +## trained model ## |
| 16 | +## - BATCH specifies the number of images used for one training iteration before updating the model's weights. ## |
| 17 | +## A larger batch size can lead to faster training but requires more memory. ## |
| 18 | +## - FREEZE allows to freeze certain layers of a pre-trained model. This way, these layers are kept unchanged ## |
| 19 | +## during training, which allows to preserve knowledge from the pre-trained model. ## |
| 20 | +######################################################################################################################### |
18 | 21 |
|
19 | 22 | # ✅ Check configuration
|
20 | 23 | ultralytics.checks()
|
21 | 24 |
|
| 25 | +# 🧠 Load a pretrained YOLO model |
| 26 | +model = YOLO('yolo11n.pt') |
| 27 | + |
22 | 28 | # 🛠 Get configuration from environment variables
|
23 |
| -yoloModel = os.getenv('YOLO_MODEL', 'yolo11n.pt') |
24 | 29 | nbOfEpochs = os.getenv('NB_OF_EPOCHS', 50)
|
25 | 30 | deviceToUse = os.getenv('DEVICE_TO_USE', 0)
|
26 | 31 | pathToDataset = os.getenv('PATH_TO_DATASET', '/workspace/data/data.yaml')
|
27 | 32 | pathToExportedModel = os.getenv('PATH_TO_EXPORTED_MODEL', '/workspace/data/')
|
28 |
| -print('YOLO model to use:', yoloModel) |
| 33 | +batch = os.getenv('BATCH', 64) |
| 34 | +freeze = os.getenv('FREEZE', 10) |
29 | 35 | print('Number of epochs to set:', nbOfEpochs)
|
30 | 36 | print('Device to set:', deviceToUse)
|
31 | 37 | print('Path to the dataset to set:', pathToDataset)
|
32 | 38 | print('Path to the exported model to set:', pathToExportedModel)
|
33 | 39 |
|
34 |
| -# 🧠 Load a pretrained YOLO model |
35 |
| -model = YOLO(yoloModel) |
36 |
| - |
37 | 40 | # 💪 Train the model with new data ➡️ one GPU / NB_OF_EPOCHS iterations (epochs)
|
38 |
| -model.train(data=pathToDataset, device=deviceToUse, epochs=int(nbOfEpochs), verbose=True) |
| 41 | +model.train(data=pathToDataset, device=deviceToUse, epochs=int(nbOfEpochs), verbose=True, batch=batch, freeze=freeze) |
39 | 42 |
|
40 | 43 | # 💾 Save the model
|
41 | 44 | exportedMetaData = model.export()
|
|
0 commit comments