Skip to content

Commit

Permalink
[ADD] Complete the README
Browse files Browse the repository at this point in the history
  • Loading branch information
BenCretois committed Jul 30, 2024
1 parent 86d2ff0 commit 8cf5ca9
Show file tree
Hide file tree
Showing 7 changed files with 638 additions and 5 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.venv/
__pycache__/
data/
detectron2/*
output/
tiles/
63 changes: 59 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,67 @@

This repository contained code for training and using a model for detecting reindeer on satellite images. The repository is currently a **WORK IN PROGRESS**.

## How to use it?
## Installation

1. Install the dependencies:
In this repository we are using [detectron2](https://github.com/facebookresearch/detectron2). To install it follow the procedure:

- Create a virtual environment:

```bash
python3 -m venv .venv
source .venv/bin/activate
```

- Install detectron2 and the other dependancies:

```
# FIX for installing detectron2, see: https://github.com/Dao-AILab/flash-attention/issues/253
FLASH_ATTENTION_SKIP_CUDA_BUILD=TRUE pip install flash-attn --no-build-isolation
# Install dependancies
git clone https://github.com/facebookresearch/detectron2.git
pip install -e detectron2
pip install -r requirements.txt
```


- Activate the virtual environment

```bash
pip install poetry
poetry install
source .venv/bin/activate
```

## Import from LabelStudio

We are using [LabelStudio] to annotate the images. After annonating the images in LabelStudio you can **export** annotations and images as a `.zip` file and extract it in a folder `./data/annotations`.

Then, follow the pipeline!

## Create the training dataset dataset

```bash
python3 dataset.py
```
This will create a `tiles` folder containing the tiles of the processed satellite images. The path to the processed satellite images that are to be processed should be updated in the `config.yaml` file.

## Train detectron2

```bash
python3 train.py
```

The script should create a folder `output` that contains `model_final.pth`, the logs and other files that `Detectron2` creates.

## Predict

```bash
python3 predict.py
```

The script will load the model that has been trained in the previous step to make the predictions. The script will create a folder `./predict/image` containing the predicted bounding boxes and `./predict/json` containing the a `.json` file per image documenting all the bounding box coordinates.

In the `config.yaml` file you can choose to plot the predictions (parameter `TRUE / FALSE`). If `TRUE` plots of the satellite pictures with annotations should be created in `predict/image/`.

![Model prediction for a satellite picture](./predict/image/pred_crop.png)


13 changes: 12 additions & 1 deletion config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

ANNOTATION_PATH: "./data/annotations/result.json"
IMAGES_FOLDER_PATH: "./data/annotations/"

TILE_ANNOTATION_PATH: "./tiles/new_annotations.json"
TILE_FOLDER_PATH: "./tiles"

###################
Expand All @@ -12,4 +14,13 @@ TILE_FOLDER_PATH: "./tiles"

TILE_SIZE: 1024
OVERLAP: 100
PLOT_ANNOTATION: True
PLOT_ANNOTATION: False

###############
# PREDICTIONS #
###############

CONFIG_FILE: "COCO-Detection/faster_rcnn_R_50_FPN_3x.yaml"
MODEL_WEIGHTS: "./output/model_final.pth" # Path to the trained model weights
OUTPUT_FOLDER: "./predict/"
PLOT_PREDICTION: True
Binary file added predict/image/DSC00961_pred.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added predict/image/pred_crop.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 8cf5ca9

Please sign in to comment.