Simple test project: Django application with API for images and their annotations.
- Install Docker
- Run
docker-compose up
from project directory - Locally send API requests to
http://localhost:8000
(no authentication required for simplicity)
- Create image:
curl -v -F [email protected] -F annotation='{"labels": []}' http://localhost:8000/images/
- Update image annotation:
curl -H 'Content-Type: application/json' -X PUT -d '{"annotation": {"labels": []}}' http://localhost:8000/images/8/
- Get image data (url and annotation):
curl -X GET "http://localhost:8000/images/8/"
- Get image data in export format:
curl -X GET "http://localhost:8000/images/8/?format=export"
- Get image url:
curl -X GET "http://localhost:8000/images/8/url/"
This project uses specific schema for image annotations (defined in images.schemas.IMAGE_ANNOTATION_SCHEMA
). Main question during development was how to store this annotation.
We can use two different approaches: store everything as plain json or create separate tables for each entity in annotation.
Reasons to store annotation in json field:
- Annotations are self-contained (no links between images) and operated on the whole (document approach), not by specific labels (RDBMS approach).
- Annotations are relatively small (up to 100 labels) and all operations can be easily done in-memory by Python.
- No need for complex cross-image joins, aggregation or even gathering annotations for all images (e.g. for list view).
- Easy writing and updating.
Should project requirement change, database schema must be migrated to separate tables to store annotation.
docker exec -it image-annotation_backend_1 bash
python manage.py test