Ask Your Question
0

Avoid retraining a model when executing a program?

asked 2019-08-15 13:06:51 -0600

ev3670 gravatar image

updated 2019-08-15 14:06:48 -0600

I've started using OpenCV for some image processing projects and I'm wondering if there's a way to save time when it comes to processing test images against a database of faces.

Issue: 10 pictures of each subject A, B, and C exist in folders on the desktop and each subject has their own identifier as to who the subject is in a list. The program navigates to the first subject folder, trains on their face and name from the list, then moves to the next subject, rinse and repeat until complete. Once the training process is done, a test image is then given to the program to see who it thinks the subject is (Person A, B, or C). The test image is the only thing that changes each time the script is run.

So far it's fairly successful at predicting who each subject is, but the training time alone makes up a fair bit of the execution time.

Question: Is there a way to make it so the model doesn't have to retrain every single time? I figured this is what the cascade files (haarcascade_frontalface_default.xml,lbpcascade_frontalface.xml, etc.) are for in terms of prediction accuracy, but I haven't been able to find a clear cut answer for a newbie like myself. Would each subject need their own .xml cascade file?

I'm fairly new to ML and image processing so even pointing me to a similar post, forum, or book would be awesome. Thanks!

Edit: I should mention that I currently use the EigenFaceRecognizer on the test images in the prediction stage after the model has been trained on the images of each of the subjects.

edit retag flag offensive close merge delete

Comments

1

btw, we do have a face recognition module, please have a look.

berak gravatar imageberak ( 2019-08-15 14:09:47 -0600 )edit

Yes, I made the edit just a few minutes ago to include this.

ev3670 gravatar imageev3670 ( 2019-08-15 14:12:16 -0600 )edit

can it be, that your question now boils down to a single: "how to save a trained facerecognizer ?"

berak gravatar imageberak ( 2019-08-15 14:14:10 -0600 )edit

We're getting there. I want to save the trained facerecognizer to avoid having to run it every time the script is executed. So if a test image of Subject A was fed to it it would be recognized fairly quickly. Right now my run-time with 3 subjects is about 40 seconds in total. I'd like to believe there's a way to make this process much quicker.

ev3670 gravatar imageev3670 ( 2019-08-15 14:23:01 -0600 )edit

it has load() and save() methods, if you didn't discover it yet ... ;)

train it once, save the model, next time, load it instead of retraining, pretty obvious, no ?

berak gravatar imageberak ( 2019-08-15 14:32:01 -0600 )edit
2

I reread the documentation and saw this. Thank you for pointing me in the right direction! I suppose this can be closed since there are other "how to save facerecognizer" questions on here.

ev3670 gravatar imageev3670 ( 2019-08-15 14:37:05 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
1

answered 2019-08-15 13:37:34 -0600

berak gravatar image

updated 2019-08-15 14:07:44 -0600

imho, this is an entirely broken idea.

cascades can only be used for detection, not to discriminate individuals.

before doing any further steps, please readup on machine learning, and recent ideas in face recognition.

opencv's dnn module has nice support for facenet, please have a look at that instead.

edit flag offensive delete link more

Comments

Some time ago i had the idea of using overfitting to only detect one particular face- do you think this could make sense in any way?

holger gravatar imageholger ( 2019-08-15 13:55:52 -0600 )edit

@holger, overfitting what, exactly ?

berak gravatar imageberak ( 2019-08-15 14:04:21 -0600 )edit
1

overfit(use fine tuning / transfer learning from a face detection model) the face you want to detect - yeah maybe really absurd. Because over fitting means lack of generalization - so that would be some kind of face "template matching" then.

holger gravatar imageholger ( 2019-08-15 14:58:06 -0600 )edit

not ever gonna work, it will overfit to the conditions of those specific images, not only the face ... in the end it will be very difficult to detect anything with that overfitted model. Its just not made for that :D

StevenPuttemans gravatar imageStevenPuttemans ( 2019-08-19 09:14:12 -0600 )edit
1

Yes - It will learn the background too - you are right - i forgot about this. Hmm dont hit me but i think something in that area should still work - but as long as is don't have a poc - this is just some weird thoughts XD

holger gravatar imageholger ( 2019-08-19 14:35:45 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2019-08-15 13:06:51 -0600

Seen: 289 times

Last updated: Aug 15 '19