0

I am using OpenImaj for face recognition. Due to the long time it takes train the data at runtime, I am saving the already trained data to system to use it later.

I am using the below code to save the trained data

IOUtils.writeToFile(faceEngine, new File("traineddata.txt"));

Please how do I read the data back to the faceEngine object when the software loads?

The faceEngine object is created this way

FKEFaceDetector faceDetector = new FKEFaceDetector(new HaarCascadeDetector(40));`
EigenFaceRecogniser<KEDetectedFace, Person> faceRecogniser = EigenFaceRecogniser.create(20, new RotateScaleAligner(), 1, DoubleFVComparison.CORRELATION, 0.9f);
FaceRecognitionEngine<KEDetectedFace, Person> faceEngine = FaceRecognitionEngine.create(faceDetector, faceRecogniser);

How do I load the traineddata.txt file?

asbachb
  • 543
  • 3
  • 17
Emperor
  • 81
  • 1
  • 9

1 Answers1

0

You should be able to load the FaceRecognitionEngine<KEDetectedFace, Person> object again with IOutils.readFromFile.

(see http://openimaj.org/apidocs/src-html/org/openimaj/io/IOUtils.html#line.1071)

asbachb
  • 543
  • 3
  • 17
  • How do I pass the file to the faceEngine object because I tried `faceEngine.readBinary(IOUtils.readFromFile(traineddata));` and I am getting some errors WARNING: An illegal reflective access operation has occurred WARNING: Illegal reflective access by com.esotericsoftware.reflectasm.AccessClassLoader (file:/C:/Users/Emperor/.m2/repository/com/esotericsoftware/kryo/kryo/2.21/kryo-2.21.jar) to method java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int) WARNING: Please consider reporting this to the maintainers of com.esotericsoftware.reflectasm.AccessClassLoader – Emperor Jul 31 '22 at 09:49
  • @Emperor From my understanding of javadoc it should be `FaceRecognitionEngine faceEngine = IOUtils.readFromFile(new File("traineddata.txt"));` – asbachb Jul 31 '22 at 09:58
  • The `traineddata` variable has already been declared before `File traineddata = new File("data/traineddata.txt");` – Emperor Jul 31 '22 at 10:01
  • My snippet was based on the code you posted above. If in meanwhile you extracted that file reference into a separate variable you need to adjust the code for sure. – asbachb Jul 31 '22 at 10:06
  • Okay. I did `faceEngine = IOUtils.readFromFile(new File("traineddata.txt"));` and I got error WARNING: An illegal reflective access operation has occurred WARNING: Illegal reflective access by com.esotericsoftware.reflectasm.AccessClassLoader (file:/C:/Users/Emperor/.m2/repository/com/esotericsoftware/kryo/kryo/2.21/kryo-2.21.jar) to method java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int) – Emperor Jul 31 '22 at 10:30
  • So it does not work this way? I'd assume that a warning should not prevent the code from working. Which java version you're using? – asbachb Aug 01 '22 at 14:28
  • Java 11. I also get an error at the end of the warning `java.lang.RuntimeException: java.lang.ClassNotFoundException: org.openimaj.image.processing.face.recognition.FaceRecognitionEngine` – Emperor Aug 02 '22 at 19:09