问题
i'm trying to train train_shape_predictor_ex for detecting following image in indian bill. i'm using 34 different images both clicked and scanned. model is trained succesfully with
taining error = 0
testing error = 0.35468-6
i have tried changing oversampling parameter from 300 to 12000 but still same results. what am i doing wrong?
drawing code - from image loading to drawing step:
image_window win;
frontal_face_detector detector = get_frontal_face_detector();
shape_predictor pose_model;
deserialize("sp.dat") >> pose_model;
while (!win.is_closed())
{
cv::Mat temp;
cap >> temp;
cv_image<bgr_pixel> cimg(temp);
std::vector<rectangle> faces = detector(cimg);
std::vector<full_object_detection> shapes;
for (unsigned long i = 0; i < faces.size(); ++i)
{
full_object_detection shape = pose_model(cimg, faces[i]);
std::vector<rectangle> dets = detector(cimg);
shapes.push_back(pose_model(cimg, faces[i]));
win.clear_overlay();
win.set_image(cimg);
win.add_overlay(dets, rgb_pixel(255, 0, 0));
win.add_overlay(render_face_detections(shapes));
}
}
回答1:
As I see now - you are trying to train custom shape_predictor that will only have 14 points while using Dlib's render_face_detections function that require Dlib's face shape that has 68 points. render_face_detections will not draw your shape correctly and should throw an exception.
To make your shape prediction work, please ensure that you follow this conditions:
- The meaning of each point should be the same on each image. Do not put point #0 on ear on first image and #0 on the tip of nose on the second image
- Object bounding box should not be hand-drawn if you have small dataset. If you use face detector for testing shape predictor - ensure that your training/testing images bounding boxes are made by detecting face with the same face detector. Yes, you can hand-draw whis bounding boxes, but please make sure that they have the same size and position as if they will be detected. The way how you put box on the training set should be identical the way how you will get it in a future.
- There is no requirement to fit all points inside face bounding box. Really it can have any size and position, even static 10x10 box for each face on the tip of nose (or full bill rect) will work - but you should have enough training samples. And follow previous condition
- Use as many images as possible. 34 images is not enough for training shape predictor - if will simply remember them in its internal memory and will not work in a future. Dlib's shape predictor is trained with about 2-3k images.
- You can generate new images by distorting original ones - scale, resize, add noise...
- Do not use Dlib's testing and drawing functions if your shape predictor does not have 68 points with the same meaning as dlib's face shape predictor. You can use its source code and make your functions as you need
来源:https://stackoverflow.com/questions/39953755/improper-training-result-dlib