deepdetect icon indicating copy to clipboard operation
deepdetect copied to clipboard

How to train a object detection model by deepdetect?

Open wjhtinger opened this issue 6 years ago • 2 comments

Is there a example? Now the example is only for Classification

wjhtinger avatar Mar 20 '19 03:03 wjhtinger

Sure, it is actually pretty easy.

  • First setup your dataset, the format is described here: https://www.deepdetect.com/platform/docs/#object-detection

It's basically a text file with image path and bounding box file path. A bounding box file lists the object class and coordinates for each image independently.

The platform is made available soon, in the meantime, you can train with the server as shown below.

  • Setup a pre-trained model for transfer learning

It is recommended to finetune a pre-trained model instead of training from scratch, especially if you don't have many thousand samples.

To do so, create a model directory (called model_dir below), download the pretrained model from https://deepdetect.com/downloads/platform/pretrained/ssd_300/VGG_ILSVRC_16_layers_fc_reduced.caffemodel, and put it into the model directory.

  • Create the service via PUT /services/detectjob
 {
  "mllib": "caffe",
  "description": "object detection model",
  "type": "supervised",
  "parameters": {
    "input": {
      "connector": "image",
      "width": 512,
      "height": 512,
      "bw": false,
      "db": true,
      "bbox": true
    },
    "mllib": {
      "template": "ssd_300",
      "finetuning": true,
      "nclasses": 7,
      "weights": ".caffemodel",
      "rotate": false,
      "mirror": true,
      "noise": {
        "all_effects": true,
        "prob": 0.001
      },
      "distort": {
        "all_effects": true,
        "prob": 0.5
      },
      "gpu": true,
    }
  },
  "model": {
    "templates": "../templates/caffe/",
    "repository": "/path/to/model_dir/",
    "create_repository": true
  }
}

This should get you:

 {
  "status": {
    "code": 201,
    "msg": "Created"
  }
}
  • Start training job with POST /train
{
  "service": "detectjob",
  "async": true,
  "parameters": {
    "input": {
      "shuffle": true,
      "db": true,
      "db_width": 512,
      "db_height": 512
    },
    "mllib": {
      "gpu": true,
      "resume": false,
      "net": {
        "batch_size": 32,
        "test_batch_size": 1
      },
      "solver": {
        "test_initialization": false,
        "iterations": 90000,
        "test_interval": 2000,
        "snapshot": 2000,
        "base_lr": 0.0001,
        "solver_type": "RMSPROP",
        "iter_size": 1
      },
      "bbox": true
    },
    "output": {
      "measure": [
        "map"
      ]
    }
  },
  "data": [
    "/path/to/train.txt",
    "/path/to//test.txt"
  ]
}

should get you:

{
  "status": {
    "code": 201,
    "msg": "Created"
  },
  "head": {
    "method": "/train",
    "job": 1,
    "status": "running"
  }
}

beniz avatar Mar 20 '19 06:03 beniz

Just adding a tip for others, if you get "Solver creation error", be sure that bbox:true is set on the service setup call.

dgtlmoon avatar Aug 18 '20 11:08 dgtlmoon