Skip to content

Commit 1dc52d8

Browse files
committed
Updates:
- Enable logging trials in ClearML. - Correct some typos. Signed-off-by: khaoula boutiche <[email protected]>
1 parent 515f3ce commit 1dc52d8

File tree

26 files changed

+468
-55
lines changed

26 files changed

+468
-55
lines changed

README.md

Lines changed: 48 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ Object detection is used to detect, locate and estimate the occurrences probabil
138138
| [ST Yolo LC v1](https://github.com/STMicroelectronics/stm32ai-modelzoo/blob/master/object_detection/st_yolo_lc_v1/README.md) | 192x192x3<br> 224x224x3<br> 256x256x3<br> | Full OD Services | [STM32H747I-DISCO](application_code/object_detection/STM32H7/Application/STM32H747I-DISCO) with B-CAMS-OMV camera daughter board<br> |
139139
| [Tiny Yolo v2](https://github.com/STMicroelectronics/stm32ai-modelzoo/blob/master/object_detection/tiny_yolo_v2/README.md) | 224x224x3<br> 416x416x3<br> | Full OD Services | [STM32N6570-DK](https://www.st.com/en/development-tools/stm32n6-ai.html)<br> |
140140
| [ST Yolo X](https://github.com/STMicroelectronics/stm32ai-modelzoo/blob/master/object_detection/st_yolo_x/README.md) | 256x256x3<br> 416x416x3<br> | Full OD Services | [STM32N6570-DK](https://www.st.com/en/development-tools/stm32n6-ai.html)<br> |
141-
| [Yolo v8](https://github.com/stm32-hotspot/ultralytics/tree/main/examples/YOLOv8-STEdgeAI/stedgeai_models/object_detection) | 192x192x3<br> 256x256x3<br> 320x320x3<br> 416x416x3<br> | Evaluation / Benchmarking / Prediction / Deployment | [STM32N6570-DK](https://www.st.com/en/development-tools/stm32n6-ai.html)<br> |
141+
| [Yolo v8](https://github.com/stm32-hotspot/ultralytics/tree/main/examples/YOLOv8-STEdgeAI/stedgeai_models/object_detection) <br> Yolo v5u | 192x192x3<br> 256x256x3<br> 320x320x3<br> 416x416x3<br> | Evaluation / Benchmarking / Prediction / Deployment | [STM32N6570-DK](https://www.st.com/en/development-tools/stm32n6-ai.html)<br> |
142142

143143

144144
[Full OD Services](object_detection/README.md) : training, evaluation, quantization, benchmarking, prediction, deployment
@@ -457,18 +457,54 @@ pip install -r requirements.txt
457457
458458
## Jump start with Colab
459459
460-
In [tutorials/notebooks](tutorials/notebooks/README.md) you will find a jupyter notebook that can be easily deployed on
461-
Colab to exercise STM32 model zoo training scripts.
462-
460+
In the `tutorials/notebooks` directory, you will find a Jupyter notebook that can be easily deployed on Colab to exercise STM32 model zoo training scripts.
463461
464462
> [!IMPORTANT]
465-
> In this project, we are using **TensorFLow version 2.8.3** following unresolved issues with newest versions of TensorFlow, see [more](https://github.com/tensorflow/tensorflow/issues/56242).
463+
> In this project, we are using TensorFlow version 2.8.3 due to unresolved issues with newer versions of TensorFlow. For more details, see [this issue](https://github.com/tensorflow/tensorflow/issues/56242).
466464
467-
>[!CAUTION]
468-
> If there are some white spaces in the paths (for Python, STM32CubeIDE, or, STM32Cube.AI local installation) this can result in errors. So avoid having paths with white spaces in them.
465+
> [!CAUTION]
466+
> If there are any white spaces in the paths (for Python, STM32CubeIDE, or STM32Cube.AI local installation), this can result in errors. Avoid having paths with white spaces.
469467
470-
>[!TIP]
471-
> In this project we are using the `mlflow` library to log the results of different runs. Depending on which version of Windows OS are you using or where you place the project the output log files might have a very long path which might result in an error at the time of logging the results. As by default, Windows uses a path length limitation (MAX_PATH) of 256 characters: Naming Files, Paths, and Namespaces. To avoid this potential error, create (or edit) a variable named `LongPathsEnabled` in **Registry Editor** under **Computer/HKEY_LOCAL_MACHINE/SYSTEM/CurrentControlSet/Control/FileSystem/** and assign it a value of `1`. This will change the maximum length allowed for the file length on Windows machines and will avoid any errors resulting due to this. For more details have a look at this [link](https://knowledge.autodesk.com/support/autocad/learn-explore/caas/sfdcarticles/sfdcarticles/The-Windows-10-default-path-length-limitation-MAX-PATH-is-256-characters.html). Note that using GIT, line below may help solving long path issue :
472-
```bash
473-
git config --system core.longpaths true
474-
```
468+
> [!TIP]
469+
> In this project, we are using the ClearML library to log the results of different runs.
470+
471+
### ClearML Setup
472+
473+
1. **Sign Up**: Sign up for free to the [ClearML Hosted Service](https://app.clear.ml). Alternatively, you can set up your own server as described [here](https://clear.ml/docs/latest/docs/deploying_clearml/).
474+
475+
2. **Create Credentials**: Go to your ClearML workspace and create new credentials.
476+
477+
3. **Configure ClearML**: Create a `clearml.conf` file and paste the credentials into it. If you are behind a proxy or using SSL portals, add `verify_certificate = False` to the configuration to make it work. Here is an example of what your `clearml.conf` file might look like:
478+
479+
```ini
480+
api {
481+
web_server: https://app.clear.ml
482+
api_server: https://api.clear.ml
483+
files_server: https://files.clear.ml
484+
# Add this line if you are behind a proxy or using SSL portals
485+
verify_certificate = False
486+
credentials {
487+
"access_key" = "YOUR_ACCESS_KEY"
488+
"secret_key" = "YOUR_SECRET_KEY"
489+
}
490+
}
491+
492+
```
493+
494+
Once configured, your experiments will be logged directly and shown in the project section under the name of your project.
495+
496+
### MLflow Setup
497+
498+
In this project, we are also using the MLflow library to log the results of different runs.
499+
500+
#### Windows Path Length Limitation
501+
502+
Depending on which version of Windows OS you are using or where you place the project, the output log files might have a very long path, which might result in an error at the time of logging the results. By default, Windows uses a path length limitation (MAX_PATH) of 256 characters. To avoid this potential error, follow these steps:
503+
504+
1. **Enable Long Paths**: Create (or edit) a variable named `LongPathsEnabled` in the Registry Editor under `Computer\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem` and assign it a value of `1`. This will change the maximum length allowed for the file path on Windows machines and will avoid any errors resulting due to this. For more details, refer to [Naming Files, Paths, and Namespaces](https://docs.microsoft.com/en-us/windows/win32/fileio/naming-a-file).
505+
506+
2. **GIT Configuration**: If you are using GIT, the line below may help solve the long path issue:
507+
508+
```bash
509+
git config --system core.longpaths true
510+
```

audio_event_detection/src/README.md

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,35 @@ This directory contains the following files :
3030
- Several confusion matrices, as well as plots of the loss & validation accuracy curves during training are included.
3131

3232
</details></ul>
33-
<ul><details open><summary><a href="#1-3">1.3 MLflow</a></summary><a id="1-3"></a>
33+
<ul><details open><summary><a href="#1-3">1.3 ClearML run</a></summary><a id="1-3"></a>
34+
35+
ClearML is an open-source tool used for logging and tracking machine learning experiments. It allows you to record metrics, parameters, and results, making it easier to monitor and compare diffrent runs.
36+
37+
Follow these steps to configurate ClearML for logging your results. This setup only needs to be done once. if you haven't set it up yet, complete the steps below. if you've already configured ClearML, your results should be automatically logged and available in your session.
38+
39+
- Sign up for free to the [ClearML Hosted Service](https://app.clear.ml), then go to your ClearML workspace and create new credentials.
40+
41+
- Create a `clearml.conf` file and paste the credentials into it. If you are behind a proxy or using SSL portals, add `verify_certificate = False` to the configuration to make it work. Here is an example of what your `clearml.conf` file might look like:
42+
43+
```ini
44+
api {
45+
web_server: https://app.clear.ml
46+
api_server: https://api.clear.ml
47+
files_server: https://files.clear.ml
48+
# Add this line if you are behind a proxy or using SSL portals
49+
verify_certificate = False
50+
credentials {
51+
"access_key" = "YOUR_ACCESS_KEY"
52+
"secret_key" = "YOUR_SECRET_KEY"
53+
}
54+
}
55+
56+
```
57+
58+
Once configured, your experiments will be logged directly and shown in the project section under the name of your project.
59+
60+
</details></ul>
61+
<ul><details open><summary><a href="#1-4">1.4 MLflow run</a></summary><a id="1-4"></a>
3462

3563
MLflow is an API for logging parameters, code versions, metrics, and artifacts while running machine learning code and for visualizing results.
3664
The model zoo lets you use MLflow to easily visualize the results and metrics obtained in multiple trainings.

audio_event_detection/src/stm32ai_main.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
import argparse
2222
import logging
2323
from typing import Optional
24+
from clearml import Task
25+
from clearml.backend_config.defs import get_active_config_file
2426

2527
sys.path.append(os.path.join(os.path.dirname(__file__), '../../common'))
2628
sys.path.append(os.path.join(os.path.dirname(__file__), '../../common/benchmarking'))
@@ -545,6 +547,14 @@ def process_mode(mode: str = None, configs: DictConfig = None, train_ds: tf.data
545547
# logging the completion of the chain
546548
log_to_file(configs.output_dir, f'operation finished: {mode}')
547549

550+
# ClearML - Example how to get task's context anywhere in the file.
551+
# Checks if there's a valid ClearML configuration file
552+
if get_active_config_file() is not None:
553+
print(f"[INFO] : ClearML task connection")
554+
task = Task.current_task()
555+
task.connect(configs)
556+
557+
548558
@hydra.main(version_base=None, config_path="", config_name="user_config")
549559
def main(cfg: DictConfig) -> None:
550560
"""
@@ -573,6 +583,17 @@ def main(cfg: DictConfig) -> None:
573583
cfg.output_dir = HydraConfig.get().run.dir
574584
mlflow_ini(cfg)
575585

586+
# Checks if there's a valid ClearML configuration file
587+
print(f"[INFO] : ClearML config check")
588+
if get_active_config_file() is not None:
589+
print(f"[INFO] : ClearML initialization and configuration")
590+
# ClearML - Initializing ClearML's Task object.
591+
task = Task.init(project_name=cfg.general.project_name,
592+
task_name='aed_modelzoo_task')
593+
# ClearML - Optional yaml logging
594+
task.connect_configuration(name=cfg.operation_mode,
595+
configuration=cfg)
596+
576597
# Seed global seed for random generators
577598
seed = get_random_seed(cfg)
578599
print(f'[INFO] : The random seed for this simulation is {seed}')

audio_event_detection/src/utils/gen_h_file.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ def gen_h_user_file(config):
140140
if config.feature_extraction.to_db:
141141
f.write('#define CTRL_X_CUBE_AI_SPECTROGRAM_SILENCE_THR (0) // 0 means disabled\n')
142142
else:
143-
f.write('#define CTRL_X_CUBE_AI_SPECTROGRAM_SILENCE_THR (3000.0F) // 0 means disabled\n')
143+
f.write('#define CTRL_X_CUBE_AI_SPECTROGRAM_SILENCE_THR (100.0F) // 0 means disabled\n')
144144
f.write('#define CTRL_X_CUBE_AI_SPECTROGRAM_WIN (user_win)\n')
145145
f.write('#define CTRL_X_CUBE_AI_SPECTROGRAM_MEL_LUT (user_melFiltersLut)\n')
146146
f.write('#define CTRL_X_CUBE_AI_SPECTROGRAM_MEL_START_IDX (user_melFiltersStartIndices)\n')

hand_posture/src/README.md

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ Remember that minimalistic yaml files are available [here](./config_file_example
1919
- [3.1 Saved results](#3-1)
2020
- [3.2 Run tensorboard](#3-2)
2121
- [3.3 Run MLFlow](#3-3)
22+
- [3.4 Run ClearML](#3-4)
2223

2324
<details open><summary><a href="#1"><b>1. Hand Posture Model Zoo introduction</b></a></summary><a id="1"></a>
2425

@@ -357,7 +358,7 @@ tensorboard --logdir logs
357358
This will start a server and its address will be displayed. Use this address in a web browser to connect to the server. Then, using the web browser, you will be able to explore the learning curves and other training metrics.
358359

359360
</details></ul>
360-
<ul><details open><summary><a href="#3-3">3.3 Run MLFlow</a></summary><a id="4-3"></a>
361+
<ul><details open><summary><a href="#3-3">3.3 Run MLFlow</a></summary><a id="3-3"></a>
361362

362363
MLflow is an API that allows you to log parameters, code versions, metrics, and artifacts while running machine learning code, and provides a way to visualize the results.
363364

@@ -368,8 +369,35 @@ mlflow ui
368369
```
369370
This will start a server and its address will be displayed. Use this address in a web browser to connect to the server. Then, using the web browser, you will be able to navigate the different experiment directories and look at the metrics that were collected. Refer to [MLflow Home](https://mlflow.org/) for more information about MLflow.
370371

372+
371373
</details></ul>
372-
</details>
374+
<ul><details open><summary><a href="#3-4">3.4 Run ClearML</a></summary><a id="3-4"></a>
375+
376+
ClearML is an open-source tool used for logging and tracking machine learning experiments. It allows you to record metrics, parameters, and results, making it easier to monitor and compare diffrent runs.
377+
378+
Follow these steps to configurate ClearML for logging your results. This setup only needs to be done once. if you haven't set it up yet, complete the steps below. if you've already configured ClearML, your results should be automatically logged and available in your session.
379+
380+
- Sign up for free to the [ClearML Hosted Service](https://app.clear.ml), then go to your ClearML workspace and create new credentials.
381+
382+
- Create a `clearml.conf` file and paste the credentials into it. If you are behind a proxy or using SSL portals, add `verify_certificate = False` to the configuration to make it work. Here is an example of what your `clearml.conf` file might look like:
383+
384+
```ini
385+
api {
386+
web_server: https://app.clear.ml
387+
api_server: https://api.clear.ml
388+
files_server: https://files.clear.ml
389+
# Add this line if you are behind a proxy or using SSL portals
390+
verify_certificate = False
391+
credentials {
392+
"access_key" = "YOUR_ACCESS_KEY"
393+
"secret_key" = "YOUR_SECRET_KEY"
394+
}
395+
}
396+
397+
```
398+
399+
Once configured, your experiments will be logged directly and shown in the project section under the name of your project.
400+
373401
<details open><summary><a href="#A"><b>Appendix A: YAML syntax</b></a></summary><a id="A"></a>
374402

375403
**Example and terminology:**

hand_posture/src/stm32ai_main.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,15 @@
1111
from hydra.core.hydra_config import HydraConfig
1212
import hydra
1313
import warnings
14-
1514
warnings.filterwarnings("ignore")
1615
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3'
1716

1817
import tensorflow as tf
1918
from omegaconf import DictConfig
2019
import mlflow
2120
import argparse
21+
from clearml import Task
22+
from clearml.backend_config.defs import get_active_config_file
2223

2324
sys.path.append(os.path.join(os.path.dirname(__file__), '../../common'))
2425
sys.path.append(os.path.join(os.path.dirname(__file__), '../../common/benchmarking'))
@@ -111,6 +112,13 @@ def process_mode(mode: str = None,
111112
# logging the completion of the chain
112113
log_to_file(configs.output_dir, f'operation finished: {mode}')
113114

115+
# ClearML - Example how to get task's context anywhere in the file.
116+
# Checks if there's a valid ClearML configuration file
117+
if get_active_config_file() is not None:
118+
print(f"[INFO] : ClearML task connection")
119+
task = Task.current_task()
120+
task.connect(configs)
121+
114122

115123
@hydra.main(version_base=None, config_path="", config_name="user_config")
116124
def main(cfg: DictConfig) -> None:
@@ -140,6 +148,17 @@ def main(cfg: DictConfig) -> None:
140148
cfg.output_dir = HydraConfig.get().run.dir
141149
mlflow_ini(cfg)
142150

151+
# Checks if there's a valid ClearML configuration file
152+
print(f"[INFO] : ClearML config check")
153+
if get_active_config_file() is not None:
154+
print(f"[INFO] : ClearML initialization and configuration")
155+
# ClearML - Initializing ClearML's Task object.
156+
task = Task.init(project_name=cfg.general.project_name,
157+
task_name='hpr_modelzoo_task')
158+
# ClearML - Optional yaml logging
159+
task.connect_configuration(name=cfg.operation_mode,
160+
configuration=cfg)
161+
143162
# Seed global seed for random generators
144163
seed = get_random_seed(cfg)
145164
print(f'[INFO] : The random seed for this simulation is {seed}')

hand_posture/src/user_config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ training:
5454

5555
tools:
5656
stedgeai:
57-
version: 9.1.0
57+
version: 10.0.0
5858
optimization: balanced
5959
on_cloud: True
6060
path_to_stedgeai: C:/Users/<XXXXX>/STM32Cube/Repository/Packs/STMicroelectronics/X-CUBE-AI/<*.*.*>/Utilities/windows/stedgeai.exe

human_activity_recognition/src/stm32ai_main.py

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,15 @@
1111
from hydra.core.hydra_config import HydraConfig
1212
import hydra
1313
import warnings
14-
1514
warnings.filterwarnings("ignore")
1615
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3'
1716

1817
import tensorflow as tf
1918
from omegaconf import DictConfig
2019
import mlflow
2120
import argparse
21+
from clearml import Task
22+
from clearml.backend_config.defs import get_active_config_file
2223

2324
sys.path.append(os.path.join(os.path.dirname(__file__), '../../common'))
2425
sys.path.append(os.path.join(os.path.dirname(__file__), '../../common/benchmarking'))
@@ -145,6 +146,14 @@ def process_mode(mode: str = None,
145146
# logging the completion of the chain
146147
log_to_file(configs.output_dir, f'operation finished: {mode}')
147148

149+
# ClearML - Example how to get task's context anywhere in the file.
150+
# Checks if there's a valid ClearML configuration file
151+
if get_active_config_file() is not None:
152+
print(f"[INFO] : ClearML task connection")
153+
task = Task.current_task()
154+
task.connect(configs)
155+
156+
148157
@hydra.main(version_base=None, config_path="", config_name="user_config")
149158
def main(cfg: DictConfig) -> None:
150159
"""
@@ -172,7 +181,18 @@ def main(cfg: DictConfig) -> None:
172181
cfg = get_config(cfg)
173182
cfg.output_dir = HydraConfig.get().run.dir
174183
mlflow_ini(cfg)
175-
184+
185+
# Checks if there's a valid ClearML configuration file
186+
print(f"[INFO] : ClearML config check")
187+
if get_active_config_file() is not None:
188+
print(f"[INFO] : ClearML initialization and configuration")
189+
# ClearML - Initializing ClearML's Task object.
190+
task = Task.init(project_name=cfg.general.project_name,
191+
task_name='har_modelzoo_task')
192+
# ClearML - Optional yaml logging
193+
task.connect_configuration(name=cfg.operation_mode,
194+
configuration=cfg)
195+
176196
# Seed global seed for random generators
177197
seed = get_random_seed(cfg)
178198
print(f'[INFO] : The random seed for this simulation is {seed}')

0 commit comments

Comments
 (0)