Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add yolox export script for training and inference #1351

Merged
merged 1 commit into from Nov 1, 2021

Conversation

Bycob
Copy link
Contributor

@Bycob Bycob commented Oct 5, 2021

Requires a modified version of the model available here: https://github.com/jolibrain/YOLOX/tree/jit_script

TODO:

  • inference example
  • training example
  • Move modified repo to github/jolibrain
  • Change template from "fasterrcnn" to something else

Inference example

git clone --branch jit_script https://github.com/jolibrain/YOLOX [YOLOX_LOCATION]
pip3 install loguru thop opencv-python tabulate

# from dede root
# download weights from YOLOX readme https://github.com/jolibrain/YOLOX
python3 tools/torch/trace_yolox.py -v yolox-s --yolox_path [YOLOX_LOCATION] -o /opt/platform/models/training/yolox_coco --weights yolox_s.pth --num_classe 80

# create service
curl -X PUT 'http://localhost:8500/services/yolox_coco' -d '{
    "description": "JIT YoloX on coco dataset",
    "mllib": "torch",
    "model": {
        "repository": "/opt/platform/models/training/yolox_coco/"
    },
    "parameters": {
        "input": {
            "connector": "image",
            "width":640,
            "height":640,
            "rgb":true
        },
        "mllib":{
            "template":"yolox",
            "gpu":true,
            "gpuid":0,
            "num_classes":80
        },
        "output": {
            "bbox": true
        }
    },
    "mltype": "detection",
    "type": "supervised"
}'

echo \

curl -X POST 'http://localhost:8500/predict/' -d '{
 "service": "yolox_coco",
 "parameters": {
  "input": {},
  "output": {
   "bbox":true,
   "confidence_threshold": 0.5
  },
  "mllib": {
   "gpu": true
  }
 },
 "data": [
  "/opt/platform/data/images/cat.jpg"
 ]
}'

Training example

# export model with a pretrained backbone
python3 tools/torch/trace_yolox.py -v yolox-s --yolox_path [YOLOX_LOCATION] -o /opt/platform/models/training/yolox_cars --backbone_weights yolox_s.pth --num_classe 2

# create service
curl -X PUT 'http://localhost:8500/services/yolox_cars' -d '{                                                                                                                                      
    "description": "Torch traced YoloX on cars with pretrained backbone",
    "mllib": "torch",
    "model": {
        "repository": "/opt/platform/models/training/yolox_cars/"
    },
    "parameters": {
        "input": {
            "connector": "image",
            "width":512,
            "height":512,
            "rgb":true,
            "bbox":true,
            "db":true
        },
        "mllib":{
            "template":"yolox",
            "nclasses":2,
            "gpu":true,
            "gpuid":0
        },
        "output": {
            "bbox": true,
            "store_config": true
        }
    },
    "mltype": "detection",
    "type": "supervised"
}'

# run training
curl -X POST 'http://localhost:8500/train' -d '{
   "service":"yolox_cars",
   "parameters":{
      "input":{
         "db":true
      },
      "output":{
         "measure":[
            "map"
         ]
      },
      "mllib":{
         "solver":{
            "iterations":15000,
            "base_lr":1e-4,
            "finetune":true,
            "iter_size":4,
            "solver_type":"ADAM",
            "test_interval":100,
            "snapshot": 2000
         },
         "net":{
            "batch_size":8
         },
         "mirror":true,
         "rotate":true,
         "geometry":0.5,
         "zoom_in":true,
         "persp_horizontal":true,
         "persp_vertical":true
      }
   },
   "data":[
      "/opt/platform/examples/cars/train.txt",
      "/opt/platform/examples/cars/test.txt"
   ]
}'

@beniz beniz merged commit 0b2f20b into jolibrain:master Nov 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants