Skip to content
Snippets Groups Projects
Commit ea581844 authored by Stephane Chavin's avatar Stephane Chavin
Browse files

readme

parent 205fe400
Branches
No related tags found
No related merge requests found
<h1 align="center"><strong>Raven2YOLO</strong></h1> <h1 align="center"><strong>RAVEN2YOLO</strong></h1>
<<<<<<< HEAD
This GitHub repository was created to simplify learning YOLOv5 and to adapt it for bioacoustics. It supports a paper analyzing Humpback Whale (<i>Megaptera novaeangliae</i>) vocalizations through the automatic detection and classification of 28 units. This GitHub repository was created to simplify learning YOLOv5 and to adapt it for bioacoustics. It supports a paper analyzing Humpback Whale (<i>Megaptera novaeangliae</i>) vocalizations through the automatic detection and classification of 28 units.
=======
Ce git a été créé avec comme objectif une prise en main de YOLOV5 plus facile.
Il contient notamment un script permettant d'extraire les spectrogrammes de plusieurs enregistrements ([get_spectrogram.py](https://gitlab.lis-lab.fr/stephane.chavin/yolo-dyni/-/blob/main/get_spectrogram.py)), un script nécessaire à la conversion des annotations LabelMe vers YOLO ([labelme2yolo.py](https://gitlab.lis-lab.fr/stephane.chavin/yolo-dyni/-/blob/main/labelme2yolo.py)), un script pour convertir des annotations d'un dataframe vers YOLO ([get_train_annot_YOLO.py](https://gitlab.lis-lab.fr/stephane.chavin/yolo-dyni/-/blob/main/get_train_annot_YOLO.py/)), un script permettant de séparer le train et la validation de manière équilibré ([get_train_val_YOLO.py](https://gitlab.lis-lab.fr/stephane.chavin/yolo-dyni/-/blob/main/get_train_val_YOLO.py)), un script qui permet de compiler les détections, d'un modèle entrainé, dans un dataframe ([get_yolo_detection.py](https://gitlab.lis-lab.fr/stephane.chavin/yolo-dyni/-/blob/main/get_yolo_detection.py)) et divers autres scripts.
>>>>>>> 729ca99066972cd2d914d6054b6e8885d8e9c856
See : [Publication]() See : [Publication]()
...@@ -20,7 +15,6 @@ This repository includes essential scripts for adapting YOLOv5 to bioacoustics r ...@@ -20,7 +15,6 @@ This repository includes essential scripts for adapting YOLOv5 to bioacoustics r
* [get_train_val.py](https://gitlab.lis-lab.fr/stephane.chavin/yolo-dyni/-/blob/main/get_train_val.py) : Separates training and validation datasets in a balanced manner. * [get_train_val.py](https://gitlab.lis-lab.fr/stephane.chavin/yolo-dyni/-/blob/main/get_train_val.py) : Separates training and validation datasets in a balanced manner.
* [get_time_freq_detection.py](https://gitlab.lis-lab.fr/stephane.chavin/yolo-dyni/-/blob/main/get_time_freq_detection.py) : Compiles detections from a trained model into a dataframe and/or into Raven annotation format (.txt). * [get_time_freq_detection.py](https://gitlab.lis-lab.fr/stephane.chavin/yolo-dyni/-/blob/main/get_time_freq_detection.py) : Compiles detections from a trained model into a dataframe and/or into Raven annotation format (.txt).
<<<<<<< HEAD
<br> <br>
--- ---
...@@ -32,59 +26,15 @@ To use the scripts with Raven annotation software ([Raven Lite](https://www.rave ...@@ -32,59 +26,15 @@ To use the scripts with Raven annotation software ([Raven Lite](https://www.rave
* go into the folder that contains the scripts * go into the folder that contains the scripts
* Run get_train_annot.py * Run get_train_annot.py
* Launch training * Launch training
=======
## Annoter des images :
```bash
python get_spectrogram.py path_to_data directory [-h] [-m {unique,multiple}] [-n COLUMNS_NAME] [-f FILE]
[--frames FRAMES] [--duration DURATION] [--overlap OVERLAP] [--sr SR] [--window WINDOW] [--hop HOP]
[--cpu CPU]
```
-h, --help: Show this help message and exit.
-m, --mode {unique,multiple}: If unique, only 1 image per file (default: multiple).
-n, --columns_name COLUMNS_NAME: Name of the columns that contain the path of the .wav (default: 'Path').
-f, --file FILE: Name of the file that contains the recording to print (default: None).
--frames FRAMES: Number of spectrogram per file (default: 30).
--duration DURATION: Duration for each spectrogram (default: 8).
--overlap OVERLAP: Overlap between 2 spectrograms (default: 2).
--sr SR: Sampling rate for the spectrogram. If no argument, SR will be original SR of the recording (default: None).
--window WINDOW: Window size for the Fourier Transform (default: 1024).
--hop HOP: Hop length for the Fourier Transform (default: 512).
--cpu CPU: To speed up the process, write 2 or more (default: 1).
--up UP : High Pass Filter value in Hz (default: 10)
--low LOW : Low Pass Filter value in Hz (default: None)
Exemple :
```bash
python get_spectrogram.py /path/to/data /output/directory --mode multiple --frames 20 --duration 5 --overlap 1 --window 2048 --hop 1024 --cpu 2
```
# LabelMe
>>>>>>> 729ca99066972cd2d914d6054b6e8885d8e9c856
<br> <br>
<<<<<<< HEAD
--- ---
=======
```bash
pip install labelme
```
* Annotation
```bash
labelme /output/directory
```
![Demo](demo.gif "Demo")
>>>>>>> 729ca99066972cd2d914d6054b6e8885d8e9c856
<br> <br>
To use the scripts without Raven annotation software, you can follow these steps: To use the scripts without Raven annotation software, you can follow these steps:
<<<<<<< HEAD
* Run get_spectrogram.py * Run get_spectrogram.py
* Install Labelme (pip install labelme) and annotate the spectrograms * Install Labelme (pip install labelme) and annotate the spectrograms
* Run labelme2yolo.py * Run labelme2yolo.py
...@@ -111,41 +61,6 @@ Additional scripts may be added over time to automate other processes. ...@@ -111,41 +61,6 @@ Additional scripts may be added over time to automate other processes.
<br /> <br />
* For proper citation when using this methodology, please refer to the provided [CITATION.cff](https://gitlab.lis-lab.fr/stephane.chavin/yolo-dyni/-/blob/main/CITATION.cff) file. * For proper citation when using this methodology, please refer to the provided [CITATION.cff](https://gitlab.lis-lab.fr/stephane.chavin/yolo-dyni/-/blob/main/CITATION.cff) file.
=======
```bash
python labelme2yolo.py -p path_to_data -d directory
```
-h, --help: Show this help message and exit.
-p, --path_to_data PATH_TO_DATA: Path to LabelMe annotations (required).
-d, --directory DIRECTORY: Directory to which YOLO annotations will be stored (required).
**WARNING** : Les annotations *.json* et les images *.jpg* doivent être dans le même dossier (**path_to_data/**)
```bash
python labelme2yolo.py -p /path/to/labelme_annotations -d /output/yolo_annotations
```
### Séparation train/val/test
Il est important de vérifier que les images .jpg son dans un dossier **images/all/** et que les labels .txt soient dans le dossier **labels/**
```bash
python get_train_val.py -r ratio -p path_to_data -d directory [--test]
```
-h, --help: Show this help message and exit.
-r, --ratio RATIO: Train ratio (val = 1 - ratio) (default: 0.7).
-p, --path_to_data PATH_TO_DATA: Path of the folder that contains the .txt files (ending with labels/) (required).
-d, --directory DIRECTORY: Directory to which spectrogram and .txt files will be stored (different from -p) (required).
--test TEST: 1 if True. Split into train/test/val. 1 - Ratio / 2 for test and same for validation (default: 0).
Exemple :
```bash
python get_train_val.py -r 0.8 -p /path/to/data -d /output/directory --test 1
```
<p>
</p>
</details>
>>>>>>> 729ca99066972cd2d914d6054b6e8885d8e9c856
<br /> <br />
...@@ -163,20 +78,12 @@ pip install -r requirements.txt ...@@ -163,20 +78,12 @@ pip install -r requirements.txt
``` ```
<br /> <br />
<<<<<<< HEAD
<details> <details>
<summary><strong>Spectrogram Extraction Script</strong></summary> <summary><strong>Spectrogram Extraction Script</strong></summary>
<br /> <br />
=======
<summary>Conversion des annotations</summary>
<p>
</p>
>>>>>>> 729ca99066972cd2d914d6054b6e8885d8e9c856
## Description ## Description
<<<<<<< HEAD
This script extracts spectrograms from `.wav` files. It allows you to specify various parameters such as duration, window size, hop ratio, high and low pass filters, overlap, resampling frequency, and CPU usage to optimize the process. This script extracts spectrograms from `.wav` files. It allows you to specify various parameters such as duration, window size, hop ratio, high and low pass filters, overlap, resampling frequency, and CPU usage to optimize the process.
<br /> <br />
# Usage # Usage
...@@ -236,49 +143,11 @@ python labelme2yolo.py <path_to_data> <directory> ...@@ -236,49 +143,11 @@ python labelme2yolo.py <path_to_data> <directory>
<br /> <br />
## Description ## Description
=======
```bash
python get_train_annot.py filename_path -c columns_name path_to_data directory [-h] [-m {uniform,personalized}] [-u {unique,multiple}] [--export EXPORT] [--duration DURATION] [--overlap OVERLAP] [--sr SR] [--window WINDOW] [--hop HOP] [--cpu CPU]
```
filename_path: Path and name of the file containing the annotations (required).
-c, --columns_name COLUMNS_NAME: Name of the column that contains the path (required).
path_to_data: Path of the folder that contains the recordings (required).
directory: Directory to which spectrograms and .txt files will be stored (required).
Optional Arguments:
-h, --help: Show this help message and exit.
-m, --mode {uniform,personalized}: Choose the mode to calculate the y and height value (default: personalized).
-u, --unique {unique,multiple}: 'unique' for only one spectrogram per file, 'multiple' for multiple spectrograms (default: multiple).
--export EXPORT: To export the position of the bounding box on the spectrogram (default: None).
--duration DURATION: Duration for each spectrogram (default: 8).
--overlap OVERLAP: Overlap between 2 spectrograms (default: 2).
--sr SR: Sampling rate for the spectrogram. If no argument, SR will be original SR of the recording (default: None).
--window WINDOW: Window size for the Fourier Transform (default: 1024).
--hop HOP: Hop length for the Fourier Transform (default: 512).
--cpu CPU: To speed up the process, write 2 or more (default: 1).
## Vérifier le bon placement des bounding box :
Exemple :
```bash
python get_train_annot.py /path/to/filename.txt -c column_name /path/to/data /output/directory -m personalized -u multiple --export annotation_export.txt --duration 10 --overlap 3 --sr 44100 --window 2048 --hop 1024 --cpu 2
```
*Ajouter **--export** permet d'exporter les spectrogrammes avec les bounding box placées par dessus*
**WARNING** : Le mode uniforme permet d'extraire des bounding box avec y = 0.5 et h = 0.8; En utilisant -u unique seul le début des enregistrements est traité tandis que multiple permet de traiter plusieurs spectrogrammes; la fonction -c correspond au nom de la colonne qui contient le path des fichiers
>>>>>>> 729ca99066972cd2d914d6054b6e8885d8e9c856
This script converts annotations from the YOLO format (stored in `.txt` files) to JSON files. It allows you to specify the path to the folder containing the `.txt` files, the path to the folder containing the images, and optionally the directory where the modified JSON files will be stored. This script converts annotations from the YOLO format (stored in `.txt` files) to JSON files. It allows you to specify the path to the folder containing the `.txt` files, the path to the folder containing the images, and optionally the directory where the modified JSON files will be stored.
# Usage # Usage
<<<<<<< HEAD
To run the script, use the following command: To run the script, use the following command:
```bash ```bash
...@@ -308,15 +177,10 @@ This script splits data into training, validation, and optionally test sets base ...@@ -308,15 +177,10 @@ This script splits data into training, validation, and optionally test sets base
# Usage # Usage
To run the script, use the following command: To run the script, use the following command:
=======
<summary>Entrainement</summary>
>>>>>>> 729ca99066972cd2d914d6054b6e8885d8e9c856
```bash ```bash
python get_train_val.py.py <path_to_data> <directory> [options] python get_train_val.py.py <path_to_data> <directory> [options]
``` ```
<<<<<<< HEAD
# Arguments # Arguments
## Positional Arguments ## Positional Arguments
- path_to_data: Path to the folder that contains the .txt files (should end with labels/). - path_to_data: Path to the folder that contains the .txt files (should end with labels/).
...@@ -328,71 +192,19 @@ python get_train_val.py.py <path_to_data> <directory> [options] ...@@ -328,71 +192,19 @@ python get_train_val.py.py <path_to_data> <directory> [options]
<details> <details>
<summary><strong>CSV to Spectrogram and Annotation Converter</strong></summary> <summary><strong>CSV to Spectrogram and Annotation Converter</strong></summary>
<br /> <br />
=======
<summary>Détection</summary>
<p>
</p>
>>>>>>> 729ca99066972cd2d914d6054b6e8885d8e9c856
## Description ## Description
<<<<<<< HEAD
This script creates `.txt` and `.jpg` files for each annotation from a CSV file. It takes in the path to the CSV file containing annotations, the path to the folder containing the recordings, and the directory where the spectrograms and `.txt` files will be stored. The script includes options for setting the duration and overlap of the spectrograms, frequency resampling, window size, hop ratio, CPU usage, and an optional test flag to include a test split. This script creates `.txt` and `.jpg` files for each annotation from a CSV file. It takes in the path to the CSV file containing annotations, the path to the folder containing the recordings, and the directory where the spectrograms and `.txt` files will be stored. The script includes options for setting the duration and overlap of the spectrograms, frequency resampling, window size, hop ratio, CPU usage, and an optional test flag to include a test split.
# Usage # Usage
To run the script, use the following command: To run the script, use the following command:
=======
Arguments :
--weights: Model path or triton URL. Default is 'yolov5s.pt'.
--source: File/dir/URL/glob/screen/0(webcam) for input source. Default is 'data/images'.
--data: Optional dataset.yaml path. Default is 'data/coco128.yaml'.
--imgsz: Inference size height and width. Default is [640].
--conf-thres: Confidence threshold. Default is 0.25.
--iou-thres: NMS IoU threshold. Default is 0.45.
--max-det: Maximum detections per image. Default is 1000.
--device: Cuda device, e.g., 0 or 0,1,2,3 or cpu. Default is ''.
--view-img: Show results. Action 'store_true'.
--save-txt: Save results to *.txt. Action 'store_true'.
--save-conf: Save confidences in --save-txt labels. Action 'store_true'.
--save-crop: Save cropped prediction boxes. Action 'store_true'.
--nosave: Do not save images/videos. Action 'store_true'.
--classes: Filter by class. Example: --classes 0, or --classes 0 2 3.
--agnostic-nms: Class-agnostic NMS. Action 'store_true'.
--augment: Augmented inference. Action 'store_true'.
--visualize: Visualize features. Action 'store_true'.
--update: Update all models. Action 'store_true'.
--project: Save results to project/name. Default is 'runs/detect'.
--name: Save results to project/name. Default is 'exp'.
--exist-ok: Existing project/name ok, do not increment. Action 'store_true'.
--line-thickness: Bounding box thickness (pixels). Default is 3.
--hide-labels: Hide labels. Default is False. Action 'store_true'.
--sampleDur: Duration for each spectrogram for detection. Default is 8.
--sr: Samplerate for each spectrogram for detection. Default is 22050.
--window: Window size for each spectrogram for detection. Default is 1024.
--hop: Hop length for each spectrogram for detection. Default is 512.
--hide-conf: Hide confidences. Default is False. Action 'store_true'.
--half: Use FP16 half-precision inference. Action 'store_true'.
--sound: Enable sound. Default is False. Action 'store_true'.
--dnn: Use OpenCV DNN for ONNX inference. Action 'store_true'.
--vid-stride: Video frame-rate stride. Default is 1.
Exemple :
```bash
python3 detect.py --weights yolov5/runs/train/EXP_NB/weights/best.pt --img IMG_SIZE --conf 0.X --source PATH_TO_FOLDER_THAT_CONTAIN_WAV --save-txt --sound --sr X --sampleDur Y --window Z --hop W
```
* Sauvegarde les annotations en .txt ainsi que les images avec les bounding box dessus
>>>>>>> 729ca99066972cd2d914d6054b6e8885d8e9c856
```bash ```bash
python get_train_annot.py <filename_path> <path_to_data> <directory> [options] python get_train_annot.py <filename_path> <path_to_data> <directory> [options]
``` ```
<<<<<<< HEAD
# Arguments # Arguments
## Positional Arguments ## Positional Arguments
- filename_path: Path/name of the folder/file containing the annotations. If a file, use Raven format and add a Path column with the path to the .wav files. - filename_path: Path/name of the folder/file containing the annotations. If a file, use Raven format and add a Path column with the path to the .wav files.
...@@ -424,33 +236,15 @@ This script collects detections from `.txt` files and returns a complete datafra ...@@ -424,33 +236,15 @@ This script collects detections from `.txt` files and returns a complete datafra
# Usage # Usage
To run the script, use the following command: To run the script, use the following command:
=======
**WARNING** : Il faut adapter EXP_NB, qui correspond au numéro de l'entrainement *(exp1 pour le premier entrainement)*
--conf correspond à la confiance toléré par YOLO, c'est-à-dire à partir de quelle confiance d'une détection cette dernière est conservée, il faut donc modifier la valeur de X pour faire varier cette tolérence *(minimum : 0.0, maximum : 1)*
* Sauvegarde les annotations en .txt seulement avec la confiance de chaque détections (add --nosave)
```bash
python3 detect.py --weights yolov5/runs/train/EXP_NB/weights/best.pt --img IMG_SIZE --conf 0.X --source PATH_TO_SPECTROGRAM_TO_DETECT --save-txt --nosave --save-conf
```
<summary>Compilation des détections</summary>
<p>
</p>
>>>>>>> 729ca99066972cd2d914d6054b6e8885d8e9c856
```bash ```bash
python get_time_freq_detection.py <path_to_data> <directory> <names> [options] python get_time_freq_detection.py <path_to_data> <directory> <names> [options]
``` ```
<<<<<<< HEAD
# Arguments # Arguments
## Positional Arguments ## Positional Arguments
- path_to_data: Path to the folder that contains the .txt files. - path_to_data: Path to the folder that contains the .txt files.
- directory: Directory where the dataframe will be stored. - directory: Directory where the dataframe will be stored.
- names: Path to the YOLOv5 custom_data.yaml file. - names: Path to the YOLOv5 custom_data.yaml file.
=======
**WARNING** : Il est important d'ajouter sa propre liste de classes (ligne 31)
>>>>>>> 729ca99066972cd2d914d6054b6e8885d8e9c856
## Optional Arguments ## Optional Arguments
``` ```
...@@ -474,7 +268,6 @@ If you need more informations about YOLOv5, see: ...@@ -474,7 +268,6 @@ If you need more informations about YOLOv5, see:
<br /> <br />
```bash ```bash
<<<<<<< HEAD
python yolov5/train.py --imgsz <IMG_SIZE> --batch <BATCH_SIZE> --epochs <NB_EPOCHS> --data <custom_data.yaml> --weights yolov5/weights/yolov5l.pt --hyp <custom_hyp.yaml> --cache python yolov5/train.py --imgsz <IMG_SIZE> --batch <BATCH_SIZE> --epochs <NB_EPOCHS> --data <custom_data.yaml> --weights yolov5/weights/yolov5l.pt --hyp <custom_hyp.yaml> --cache
``` ```
<br /> <br />
...@@ -491,14 +284,6 @@ python detect.py --weights yolov5/runs/train/<EXP_NB>/weights/best.pt --imgsz <i ...@@ -491,14 +284,6 @@ python detect.py --weights yolov5/runs/train/<EXP_NB>/weights/best.pt --imgsz <i
<br /> <br />
- Detect on audio files without saving the detection images - Detect on audio files without saving the detection images
=======
cd ../
python3 get_time_freq_detection.py PATH_TO_THE_TXT DIRECTION_OF_THE_RESULT PATH_TO_THE_YAML_FILE -s SR --duration DURATION
```
<summary>Conversion des détection YOLO vers LabelMe</summary>
>>>>>>> 729ca99066972cd2d914d6054b6e8885d8e9c856
```bash ```bash
python detect.py --weights yolov5/runs/train/<EXP_NB>/weights/best.pt --imgsz <imgsz> --conf <conf> --source <PATH_TO_FOLDER_THAT_CONTAIN_WAV> --save-txt --sound --sr <SR> --sampleDur <SampleDur> --window <window> --hop <hop> --save-conf --nosave python detect.py --weights yolov5/runs/train/<EXP_NB>/weights/best.pt --imgsz <imgsz> --conf <conf> --source <PATH_TO_FOLDER_THAT_CONTAIN_WAV> --save-txt --sound --sr <SR> --sampleDur <SampleDur> --window <window> --hop <hop> --save-conf --nosave
...@@ -518,7 +303,6 @@ python detect.py --weights yolov5/runs/train/<EXP_NB>/weights/best.pt --imgsz <i ...@@ -518,7 +303,6 @@ python detect.py --weights yolov5/runs/train/<EXP_NB>/weights/best.pt --imgsz <i
``` ```
<br /> <br />
<<<<<<< HEAD
# Contact # Contact
If you have any questions, please contact me at the following e-mail address : stephane.chavin@univ-tln.fr If you have any questions, please contact me at the following e-mail address : stephane.chavin@univ-tln.fr
...@@ -528,8 +312,6 @@ If you have any questions, please contact me at the following e-mail address : s ...@@ -528,8 +312,6 @@ If you have any questions, please contact me at the following e-mail address : s
# Contributors # Contributors
<br /> <br />
=======
>>>>>>> 729ca99066972cd2d914d6054b6e8885d8e9c856
[<a href="@stephane.chavin"><img src="https://gitlab.lis-lab.fr/uploads/-/system/user/avatar/700/avatar.png" height="auto" width="50" style="border-radius:50%"></a>](https://gitlab.lis-lab.fr/stephane.chavin) [<a href="@paul.best"><img src="https://secure.gravatar.com/avatar/9476891fe83ae7102b73819cc74a89a76fb1f59e9fc7f96bcf4afbc60d734934?s=80&d=identicon" height="auto" width="50" style="border-radius:50%"></a>](https://gitlab.lis-lab.fr/paul.best) [<a href="@lisa.ferre"><img src="https://secure.gravatar.com/avatar/714493b1b540404b05e08795c1c17abdfc9db8dd1cafec2876051e00117bdc21?s=80&d=identicon" height="auto" width="50" style="border-radius:50%"></a>](https://gitlab.lis-lab.fr/lisa.ferre) [<a href="@nicolas.deloustal"><img src="https://secure.gravatar.com/avatar/32367421a8619488135bddb50ea0cfa9b89c9b9e915cd83501345867d79e3666?s=80&d=identicon&width=96" height="auto" width="50" style="border-radius:50%"></a>](https://gitlab.lis-lab.fr/nicolas.deloustal) [<a href="@stephane.chavin"><img src="https://gitlab.lis-lab.fr/uploads/-/system/user/avatar/700/avatar.png" height="auto" width="50" style="border-radius:50%"></a>](https://gitlab.lis-lab.fr/stephane.chavin) [<a href="@paul.best"><img src="https://secure.gravatar.com/avatar/9476891fe83ae7102b73819cc74a89a76fb1f59e9fc7f96bcf4afbc60d734934?s=80&d=identicon" height="auto" width="50" style="border-radius:50%"></a>](https://gitlab.lis-lab.fr/paul.best) [<a href="@lisa.ferre"><img src="https://secure.gravatar.com/avatar/714493b1b540404b05e08795c1c17abdfc9db8dd1cafec2876051e00117bdc21?s=80&d=identicon" height="auto" width="50" style="border-radius:50%"></a>](https://gitlab.lis-lab.fr/lisa.ferre) [<a href="@nicolas.deloustal"><img src="https://secure.gravatar.com/avatar/32367421a8619488135bddb50ea0cfa9b89c9b9e915cd83501345867d79e3666?s=80&d=identicon&width=96" height="auto" width="50" style="border-radius:50%"></a>](https://gitlab.lis-lab.fr/nicolas.deloustal)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment