我正在尝试重现作者dnn_mmod_train_find_cars_ex.cpp中最初描述的示例dnn_mmod_find_cars_ex.cpp和blog,但仍然坚持训练形状预测器来预测对象框。即使shape_predictor包含在预先训练的模型中,也会在示例中跳过此步骤。 这是我的代码,其中shape_predictor不起作用:
#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;
}
您可以在这里下载mmod_net.dat。它与示例中训练的网络相同,但在没有shape_predictor的单独文件中序列化。训练数据集可用here。
如何训练这些例子中的shape_predictor?