delphifirst / FaceX

A high performance open source face landmarks detector, based on explicit shape regression algorithm.
Other
147 stars 96 forks source link

Solution for training code not working in Mac Os #11

Open edgie-m opened 7 years ago

edgie-m commented 7 years ago

Hi, I was able to run the code of alignment and training successfully on Mac Os. The only issue regarding the training code (in my case at least) was in the MapShape function in utils_train.cpp file. Just change the function MapShape to the following and the training will work (I had to cast the x and y values to int)

vector MapShape(cv::Rect original_face_rect, const vector original_landmarks, cv::Rect new_face_rect) { vector result; for (const cv::Point2d &landmark: original_landmarks) { result.push_back(landmark); result.back() -= cv::Point2d(original_face_rect.x, original_face_rect.y); result.back().x = result.back().x (int) ((float)(new_face_rect.width) / original_face_rect.width); result.back().y = result.back().y (int) ((float)(new_face_rect.height) / original_face_rect.height); result.back() += cv::Point2d(new_face_rect.x, new_face_rect.y); } return result; }

delphifirst commented 7 years ago

Thanks for your information. Do you know why we need to add the cast here? Does the compiler give an error in the original code?

edgie-m commented 7 years ago

Hi, no the project as it is compile correctly on mac os (using my own CMakeLists.txt). However when I run it the code crushes in main_train.cpp -> TrainModel -> CreateTestInitShapes line -> in the CreateTestInitShapes function the line "cv::kmeans(all_landmarks ...." causes memory leak (malloc: *** error for object : pointer being freed was not allocated). I can't figure out why. I need maybe to dig more in the cv::kmeans source code. When casting to int the error disappears. By the way I had the same issue when I run the training code on Android using JNI, it crushes at the same line with an error related to the memory. Do you have any ideas? The model I trained after casting to int doesn't seem to work.