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
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.
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.
*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
<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.
--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
- 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)