This is a minimal example that runs a pretrained Faster R-CNN (ResNet-50 FPN) on a local image and saves an annotated image with bounding boxes and labels.
.
├── data/ # Place your input image(s) here
├── src/
│ ├── __init__.py
│ └── detect.py # Main script
├── requirements.txt
├── README.md
└── venv/ # (optional) Virtual environment lives here
- Create a virtual environment (recommended)
- Windows (PowerShell):
python -m venv venv
./venv/Scripts/Activate.ps1
- macOS / Linux:
python3 -m venv venv
source venv/bin/activate
- Install dependencies
pip install -r requirements.txt
-
Put an image in the
data/folder, for exampledata/input.jpg. -
Run the detector:
python -m src.detect --image data/input.jpg --output data/output.jpg --score-thresh 0.6
Adjust appearance of boxes and labels:
- Increase line width:
python -m src.detect --image data/input.jpg --output data/output.jpg --score-thresh 0.6 --line-width 10
- Check
data/output.jpgfor the annotated result. If no detections are above the threshold, the original image will be saved and you will see a console message stating so.
- Change
--score-threshto control how many boxes are shown. - Use a different output path (e.g.,
--output data/dog_boxes.jpg).
