Skip to content

Commit

Permalink
fix: Readme for mmdetection-3 and fix dino with expections (#494)
Browse files Browse the repository at this point in the history
* fix: Readme for mmdetection-3 and fix dino with expections

* Fix

* Fixes

* Fix

* Fix

* Fix
  • Loading branch information
makseq authored Apr 10, 2024
1 parent 3e949ac commit 6234415
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 18 deletions.
3 changes: 2 additions & 1 deletion label_studio_ml/examples/grounding_dino/dino.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,8 @@ def multiple_tasks(self, tasks):
ls_host=LABEL_STUDIO_HOST,
task_id=task.get('id')
)
except:
except Exception as e:
logger.error(f"Error getting local path: {e}")
img_path = raw_img_path

image_paths.append(img_path)
Expand Down
91 changes: 74 additions & 17 deletions label_studio_ml/examples/mmdetection-3/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
# Object detection with bounding boxes using MMDetection

https://mmdetection.readthedocs.io/en/latest/

This example demonstrates how to use the MMDetection model with Label Studio to annotate images with bounding boxes.
The model is based on the YOLOv3 architecture with MobileNetV2 backbone and trained on the COCO dataset.

![screenshot.png](screenshot.png)

# Quick usage

For quick usage run docker-compose in your working directory:
Expand Down Expand Up @@ -45,43 +54,91 @@ In this example, you can combine multiple labels into one Label Studio label. Fo

# Run without docker

> These steps provided by @raash1d [in this issue](https://github.com/heartexlabs/label-studio-ml-backend/issues/167#issuecomment-1495061050). Note: the patch from the comment is already applied, except hardcoding of label_config into kwargs.
**It's highly recomended to use docker, it allows to avoid lots of problems!**
**It's highly recommended to use docker, it allows to avoid lots of problems!**

1. Clone the Label Studio ML Backend repository in your directory of choice

```
git clone https://github.com/heartexlabs/label-studio-ml-backend
cd label-studio-ml-backend/label_studio_ml/examples/mmdetection-3
```

2. Create a virtual environment using venv and install all dependencies using pip

```
python -m venv ml-backend
source ml-backend/bin/activate
pip install -r requirements.txt
```

3. Install and Download mmdet related dependencies in the virtual environment
```
mim install mmengine
3. Install all dependencies

```bash

# Set environment variables
export PYTORCH="1.13.0"
export CUDA="11.6"
export CUDNN="8"

# To fix GPG key error when running apt-get update
apt-key adv --fetch-keys https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/3bf863cc.pub
apt-key adv --fetch-keys https://developer.download.nvidia.com/compute/machine-learning/repos/ubuntu1804/x86_64/7fa2af80.pub

# Update the base OS
apt-get update
apt install -y git

# Install system dependencies for opencv-python
apt-get install -y libgl1 libglib2.0-0

# Upgrade pip
pip install -U pip

# Install base requirements
pip install -r requirements-base.txt

# Install custom requirements
pip install -r requirements.txt

# Mim install commands
pip install mim
mim install mmengine==0.10.3
mim install mmdet==3.3.0
mim download mmdet --config yolov3_mobilenetv2_8xb24-320-300e_coco --dest .
mim install mmcv==2.0.0rc3
```

4. Export required variables
4. Set the environment variables

```bash
# set the log level for the model server
export LOG_LEVEL=DEBUG
# specify the model directory (likely you don't need to change this)
export MODEL_DIR=
# mmdetection model parameters
export CHECKPOINT_FILE=yolov3_mobilenetv2_320_300e_coco_20210719_215349-d18dff72.pth
export CONFIG_FILE=yolov3_mobilenetv2_8xb24-320-300e_coco.py
export DEVICE=cpu
export SCORE_THRESHOLD=0.5

# Specify the Label Studio URL and API key to access
# uploaded, local storage and cloud storage files.
# Do not use 'localhost' as it does not work within Docker containers.
# Use prefix 'http://' or 'https://' for the URL always.
# Determine the actual IP using 'ifconfig' (Linux/Mac) or 'ipconfig' (Windows).
export LABEL_STUDIO_URL=<your-ls-hostname>
export LABEL_STUDIO_API_KEY=<your-ls-api-key>
```

4. Run the following command to start your ML backend

```
export checkpoint_file=yolov3_mobilenetv2_320_300e_coco_20210719_215349-d18dff72.pth
export config_file=yolov3_mobilenetv2_8xb24-320-300e_coco.py
label-studio-ml start --root-dir .. mmdetection-3
```

5. Run the following command to start your ML backend
or using gunicorn for a Python web app

```
label-studio-ml start --root-dir .. mmdetection-3 --kwargs hostname=http://<ip.of.your.label.studio.server>:8080 access_token=<access_token> [score_threshold=0.5] [--check]
gunicorn --preload --bind :9090 --workers 1 --threads 1 --timeout 0 _wsgi:app
```

* Use this guide to find out your access token: https://labelstud.io/guide/api.html
* If you're running label studio and the ML backend on the same machine, then the IP of your label studio server could also be "localhost". Try it, I haven't tested this.
* `score_threshold` and `--check` are optional.
* You can use and increased value of `score_threshold` parameter when you see a lot of unwanted detections or lower its value if you don't see any detections.
* The `--check` parameter allows you to check if all requirements to run the backend have been fulfilled
* You can use and increased value of `SCORE_THRESHOLD` parameter when you see a lot of unwanted detections or lower its value if you don't see any detections.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 6234415

Please sign in to comment.