Skip to content

BrandonScottt/torchserve-face-detection

Repository files navigation

torchserve-face-detection

This repository demonstrates deploying a face detection model using TorchServe, along with a PostgreSQL database and API services managed via Docker.


PostgreSQL Setup with Docker

Run PostgreSQL container:

docker run --name postgres -p 5432:5432 -e POSTGRES_PASSWORD=fotoyu -e POSTGRES_DB=mydb -d postgres

##Check Database in Docker

docker exec -it postgres bash psql -U postgres \c mydb # Connect to your database (replace with mydb) \d # List tables and relations SELECT * FROM <table_name>; # Query data from a table

Docker Network Inspection

docker network inspect bridge docker inspect <container_name> | findstr IPAddress

Running the Image POST API

Build and run server container

docker build . -t test-server docker run -t --name publish -p 3000:3000 test-server

Build and run consumer container:

docker build . -t test-consume docker run -t --name consume test-consume

TorchServe Model Packaging and Deployment

Build TorchServe .mar Model Archive

torch-model-archiver
--model-name mymodel
--version 1.0
--serialized-file mtcnn.pth
--model-file model.py
--handler my_handler.py
--extra-files face_detection.py

Start TorchServe with the Model

torchserve --start --ncs --model-store model_store --models mymodel=face_detect_model.mar

Run Inference on TorchServe

curl localhost:8080/predictions/mymodel -T img1.jpg

Using Python Requests (in docker)

import requests

image_path = "<image_path>" result = requests.post( "http://host.docker.internal:8080/predictions/mymodel", files={'data': open(image_path, 'rb')} )

print(result.json())

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published