- For ease of use it's recommended to use the provided docker-compose.yml.
CPU Support: Use the latest tag.
services:
image_video_classification:
image: ghcr.io/doppeltilde/image_video_classification:latest
ports:
- "8000:8000"
volumes:
- models:/root/.cache/huggingface/hub:rw
environment:
- DEFAULT_MODEL_NAME
- BATCH_SIZE
- ACCESS_TOKEN
- DEFAULT_SCORE
- USE_API_KEYS
- API_KEYS
restart: unless-stopped
volumes:
models:NVIDIA GPU Support: Use the latest-cuda tag.
services:
image_video_classification_cuda:
image: ghcr.io/doppeltilde/image_video_classification:latest-cuda
ports:
- "8000:8000"
volumes:
- models:/root/.cache/huggingface/hub:rw
environment:
- DEFAULT_MODEL_NAME
- BATCH_SIZE
- ACCESS_TOKEN
- DEFAULT_SCORE
- USE_API_KEYS
- API_KEYS
restart: unless-stopped
deploy:
resources:
reservations:
devices:
- driver: nvidia
count: all
capabilities: [ gpu ]
volumes:
models:- Create a
.envfile and set the preferred values.
DEFAULT_MODEL_NAME=Falconsai/nsfw_image_detection
BATCH_SIZE=5
DEFAULT_SCORE=0.7
ACCESS_TOKEN=
# False == Public Access
# True == Access Only with API Key
USE_API_KEYS=False
# Comma seperated api keys
API_KEYS=abc,123,xyzAny model designed for image classification and compatible with huggingface transformers should work.
- https://huggingface.co/Falconsai/nsfw_image_detection
- https://huggingface.co/LukeJacob2023/nsfw-image-detector
- https://huggingface.co/nateraw/vit-age-classifier
Note
Please be aware that the initial classification process may require some time, as the model is being downloaded.
Tip
Interactive API documentation can be found at: http://localhost:8000/docs
POST request to the /api/image-classification endpoint.
curl -X 'POST' \
'http://localhost:8000/api/image-classification?model_name=Falconsai/nsfw_image_detection' \
-H 'accept: application/json' \
-H 'Content-Type: multipart/form-data' \
-F 'file=@file.jpg'POST request to the /api/multi-image-classification endpoint.
curl -X 'POST' \
'http://localhost:8000/api/multi-image-classification?model_name=Falconsai/nsfw_image_detection' \
-H 'accept: application/json' \
-H 'Content-Type: multipart/form-data' \
-F 'files=@0.PNG;type=image/png' \
-F 'files=@1.JPG;type=image/jpeg' \
-F 'files=@1.gif;type=image/gif'You can utilize query parameters, if the standard classification isn't sufficient or you need a more nuanced response.
Optional parameters:
-
model_namesList[str] -
labelsList[str] -
scorefloat -
return_on_first_matching_labelbool (default: false) -
fast_modebool (default: false) -
skip_frames_percentageint (default: 5)
POST request to the /api/image-query-classification endpoint.
curl -X 'POST' \
'http://localhost:8000/api/image-query-classification?model_names=Falconsai%2Fnsfw_image_detection' \
-H 'accept: application/json' \
-H 'Content-Type: multipart/form-data' \
-F 'file=@1.jpeg;type=image/jpeg'POST request to the /api/multi-image-query-classification endpoint.
curl -X 'POST' \
'http://localhost:8000/api/multi-image-query-classification?model_names=Falconsai%2Fnsfw_image_detection' \
-H 'accept: application/json' \
-H 'Content-Type: multipart/form-data' \
-F 'files=@1.png;type=image/png' \
-F 'files=@2.jpeg;type=image/jpeg' \
-F 'files=@3.gif;type=image/gif'POST request to the /api/video-classification endpoint.
curl -X 'POST' \
'http://localhost:8000/api/video-classification?model_names=Falconsai%2Fnsfw_image_detection' \
-H 'accept: application/json' \
-H 'Content-Type: multipart/form-data' \
-F 'file=@1.mp4;type=video/mp4'Tip
You can find code examples in the examples folder.
Notice: This project was initally created to be used in-house, as such the development is first and foremost aligned with the internal requirements.