/cerebro

Template for future AI endpoints

Primary LanguagePython

Deploy YOLO

This fork uses Replicate's 🐣 Cog system to quickly deploy Ultralytic's 🚀 PyTorch implementation of YOLOv5.

See Cog and YOLOv5 for full documentation on training, testing and deployment.

Quickstart

Convenience script for Ubuntu
# Install and run pretrained Cog
sudo utils/Install.sh
# Test endpoint
python3 utils/Endpoint.py
Prerequisites

Install Docker and then install the newest version of Cog

# Use Docker convenience script if you dare
curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh get-docker.sh
# Download and configure Cog binary
sudo curl -o /usr/local/bin/cog -L https://github.com/replicate/cog/releases/latest/download/cog_`uname -s`_`uname -m`
sudo chmod +x /usr/local/bin/cog
(Optional) CPU Configuration

If you want to deploy with a CPU change line 2 in cog.yml to false:

build:
  gpu: false
Inference

Test the pretrained model with

cog predict -i image=@data/images/zidane.jpg

This will output a JSON list of all detections by default:

{
  'status': 'succeeded',
  'output': '[
    {
      "xmin":751.9083251953,
      "ymin":45.5722045898,
      "xmax":1148.5522460938,
      "ymax":716.2182006836,
      "confidence":0.8750465512,
      "class":0,
      "name":"person"
    },
    ...
  ]'
}

You can also add an additional format argument to change the label output

cog predict -i image=@data/images/zidane.jpg -i format=yolo
Deployment

STARTER: Deploy the model locally at http://localhost:5000 using the below premade scripts.

# To run on GPU
docker/run_gpu.sh
# OR to run on CPU
docker/run_cpu.sh
# Send test image once the container is running
curl http://localhost:5000/predict -X POST -F input=@docs/zidane.jpg

You should see the same JSON output from the Inference step.

ADVANCED: Deploy in the cloud using the Cloudflare Tunnel guide

To-do

  • Add more label types
  • Simplify JSON extraction
  • Bridge to Jetson platform
  • Training tutorial with Roboflow