3

I am trying to reproduce the examples dnn_mmod_train_find_cars_ex.cpp and dnn_mmod_find_cars_ex.cpp described originally in the author's blog, but got stuck with training a shape predictor to predict object boxes. This step is skipped in the examples, even if shape_predictor is included in a pre-trained model. Here is my code, where shape_predictor isn't working:

#include <iostream>
#include <dlib/dnn.h>
#include <dlib/image_io.h>
#include <dlib/image_processing.h>
#include <dlib/data_io.h>

using namespace std;
using namespace dlib;



// The rear view vehicle detector network
template <long num_filters, typename SUBNET> using con5d = con<num_filters,5,5,2,2,SUBNET>;
template <long num_filters, typename SUBNET> using con5  = con<num_filters,5,5,1,1,SUBNET>;
template <typename SUBNET> using downsampler  = relu<affine<con5d<32, relu<affine<con5d<32, relu<affine<con5d<16,SUBNET>>>>>>>>>;
template <typename SUBNET> using rcon5  = relu<affine<con5<55,SUBNET>>>;
using net_type = loss_mmod<con<1,9,9,1,1,rcon5<rcon5<rcon5<downsampler<input_rgb_image_pyramid<pyramid_down<6>>>>>>>>;

// ----------------------------------------------------------------------------------------

int main(int argc, char** argv) try
{
    const std::string data_directory = argv[1];
    net_type net;

    deserialize("mmod_net.dat") >> net;

    std::vector<matrix<rgb_pixel>> images_train;
    std::vector<std::vector<full_object_detection>> boxes_train;
    load_image_dataset(images_train, boxes_train, data_directory+"/training.xml");

    shape_predictor_trainer trainer;
    trainer.set_num_threads(2);
    trainer.be_verbose();

    shape_predictor sp = trainer.train(net(images_train), boxes_train);


    cout << "Fiished. Hit enter to end program" << endl;
    cin.get();
}
catch(std::exception& e)
{
    cout << e.what() << endl;
}

Here you can download mmod_net.dat. It is the same net that was trained in the example but serialized in a separate file without shape_predictor. The training dataset is available here.

How to train the shape_predictor in these examples?

sudo
  • 548
  • 1
  • 4
  • 16
Stanpol
  • 966
  • 1
  • 10
  • 20

0 Answers0