Skip to content

Commit

Permalink
updated face_recognizer to include save and restore trained faces
Browse files Browse the repository at this point in the history
  • Loading branch information
iasonth95 authored and MatthijsBurgh committed Mar 19, 2024
1 parent 6cb50c4 commit ba3fbec
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ if __name__ == "__main__":

# Add arguments
parser.add_argument("image", type=str, help="Image")
parser.add_argument("-d", "--db", type=argparse.FileType("r"), help="Load already trained faces db from file")
parser.add_argument("-d", "--db", type=argparse.FileType("rb"), help="Load already trained faces db from file")
args = parser.parse_args()

sys.exit(main(**vars(args)))
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ if __name__ == '__main__':
parser = ArgumentParser(description='Train openface from a database of images')

parser.add_argument('modeldir', action=ReadableDir, help='Directory with folders for each category')
parser.add_argument('outfile', type=FileType('w'), help='Where to output the trained faces database')
parser.add_argument('outfile', type=FileType('wb'), help='Where to output the trained faces database')

parser.add_argument('-v', '--verbose', action='store_true')

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import torch
from facenet_pytorch import MTCNN, InceptionResnetV1
import numpy as np

import pickle

class TrainedFace:
"""
Expand Down Expand Up @@ -179,3 +179,9 @@ def train(self, face_representation: np.ndarray, name: str) -> None:
rospy.loginfo(
f"Label: {trained_face.get_label()}, Representations: {len(trained_face.get_representations())}"
)

def save_trained_faces(self, file_name):
pickle.dump(self._trained_faces, file_name)

def restore_trained_faces(self, file_name):
self._trained_faces = pickle.load(file_name)

0 comments on commit ba3fbec

Please sign in to comment.