DeepDetect uses an image connector to train and predict from images.

For a comprehensive list of parameters to the image input connector, see the API Connectors section.

For a complete tutorial on how to train from images, see here.

Training

Training from images in practice requires large amounts of data so the connector assumes they are available from the hard drive in the following manner:

  • Every class is a repository of images
  • The class name is the repository name

Pass the repository that contain all classes to DeeDetect and the connector will handle them.

Note that the Caffe library for deep learning requires that images are aggregated into databases as this yields to order of magnitude speed up in the per-batch training of neural networks. While DeepDetect handles this conversion for you, please note the following important points:

  • you may require twice the size of your initial dataset on disk
  • by using small images as entry to your neural net (and designing it for this purpose), you will gain much space and run way below the first requirement above
  • the image database built-up by DeepDetect is stored in the model repository, which in practice should be different than the initial dataset location
  • 224x224 is a common image size for some of the best dedicated neural nets (see the Model Templates section)
  • when using neural nets, each a fixed number of inputs, thus using the wrong image size generates an error

Below is a typical image training call:

curl -X POST "http://localhost:8080/train" -d '{
      "service":"imageserv",
      "async":true,
      "parameters":{
        "mllib":{
          "gpu":true,
          "net":{
            "batch_size":32
          },
          "solver":{
            "test_interval":500,
            "iterations":30000,
            "base_lr":0.001,
            "stepsize":1000,
            "gamma":0.9
          }
        },
        "input":{
          "connector":"image",
          "test_split":0.1,
          "shuffle":true,
          "width":224,
          "height":224
        },
        "output":{
          "measure":["acc","mcll","f1"]
        }
      },
      "data":["ilsvrc12"]
    }'

data specifies the location of the initial dataset repository and the connector options include shuffling the images, and building a test dataset from 10% of all the images at random.

See the tutorial on Training an Imagenet classifier in order to be successful with your training call on images.

Prediction

In prediction mode, the connector takes images from disk or from the network (e.g. the Web), as demonstrated in the Imagenet classifier tutorial.

Good practices with neural nets (Caffe) on images and DeepDetect:

  • predict over batches of images as this is faster than predicting on every image individually. The data array in the predict call allows you to do that:
curl -X POST "http://localhost:8080/predict" -d '{
      "service":"imageserv",
      "parameters":{
        "input":{
          "width":224,
          "height":224
        },
        "output":{
          "best":3
        }
      },
      "data":["cat.jpg","alley-italy.jpg","thai-market.jpg"]
    }'
  • the connector will resize your input images as instructed at service creation or in the predict call:
curl -X PUT "http://localhost:8080/services/imageserv" -d '{
      "mllib":"caffe",
      "description":"image classification service",
      "type":"supervised",
      "parameters":{
        "input":{
          "connector":"image",
          "width":224,
          "height":224
        },
        "mllib":{
          "template":"googlenet",
          "nclasses":1000
        }
      },
      "model":{
        "templates":"../templates/caffe/",
        "repository":"models/imgnet"
      }
    }'

The call above specifies a width and height of 224 for the service itself, so there’s no need to specify it in subsequent /predict calls.


DeepDetect documentation