Skip to main content

2 posts tagged with "Docker"

View All Tags

· 2 min read
Pajman Samadi
summary
  • An AI model for lung segmentation in CXR images, deploying with FastAPI.
  • Use DVC for data version control, and dockerizing web-app.
  • Deploy projects w/ K8s.

This app uses FastAPI as backend. Check repository on GitHub.

Usage for app.py

First install required libraries by running:

pip install -r requirements.txt

To run the application run following command in src dir:

uvicorn app:app --reload

or

chmod +x app.sh
./app.sh

Tutorial for app.py

app.gif

Tutorial

main page

http://localhost:8000/

main.png

fastapi documentation

http://localhost:8000/docs

docs.png

show results

http://localhost:8000/imshow

imshow.png


DVC

pip install dvc dvc-gdrive

# pull weights from Google Drive
dvc pull

in weights directory

weights
├── cxr_resunet.tflite
├── cxr_resunet.tflite.dvc
├── cxr_unet.tflite
└── cxr_unet.tflite.dvc

Docker

# Build image
docker build -t IMAGE_NAME:TAG_NAME .
docker run -p 8000:8000 -d IMAGE_NAME:TAG_NAME

Or

# for amd64 systems
docker run -d -p 8000:8000 pejmans21/ls-fastapi:0.1.0

#### OR

# for arm64 systems
docker run -d -p 8000:8000 pejmans21/ls-fastapi:aarch64

Kubernetes

kubectl apply -f ls-fastapi-k8s-config.yaml

to see output

kubectl port-forward service/lsapi-service 8000

Now check http://127.0.0.1:8000/

Stop process

kubectl delete -f ls-fastapi-k8s-config.yaml

· One min read
Pajman Samadi
summary
  • Repository on GitHub.
  • A FaceRecognition module written with facenet pytorch.
  • Use Django as the web framework.
  • Dockerized project.

Module

from face_encoder import FaceEncoder

# Load the module
FE = FaceEncoder('/path/to/main_folder_people/', img_size=160, recognition_threshold=0.3)

# Read images in people folder to create a database
encodes_db = FE.db_prepare(show_face=True, save_file=True, encoding_file_path='./data/encodes_db.pt')

"""--- Different ways to send an input to get results ---"""

# Image path as string
image = FE.recognizer('/path/to/image', encodes_db, pil_write=True)
# PIL.Image
image = FE.recognizer(Image.open('/path/to/image'), encodes_db, pil_write=True)
# numpy image
image = FE.recognizer(np.array(unknown_image), encodes_db, pil_write=True)

Colab

For testing the module yourself, open the prepared jupyter notebook in colab via the following link

Open In Colab

Usage

First: install requirements.txt

$ pip3 install -r requirements.txt

then in your local computer to start Django server run following commands in your terminal:

1- makemigrations

$ python3 manage.py makemigrations

2- migrate

$ python3 manage.py migrate

Optional

  • createsuperuser
$ python3 manage.py createsuperuser

3- runserver

$ python manage.py runserver 0.0.0.0:8000

Docker

$ docker-compose up --build

UI

img