face_distance is a float, also pass model through correctly to FaceFileLink

This commit is contained in:
2021-07-28 21:41:35 +10:00
parent bd28c0cf64
commit 220200f017

View File

@@ -261,7 +261,7 @@ class FaceRefimgLink(Base):
__tablename__ = "face_refimg_link" __tablename__ = "face_refimg_link"
face_id = Column(Integer, ForeignKey("face.id"), primary_key=True ) face_id = Column(Integer, ForeignKey("face.id"), primary_key=True )
refimg_id = Column(Integer, ForeignKey("refimg.id"), primary_key=True ) refimg_id = Column(Integer, ForeignKey("refimg.id"), primary_key=True )
face_distance = Column(Integer) face_distance = Column(Float)
def __repr__(self): def __repr__(self):
return f"<face_id: {self.face_id}, refimg_id={self.refimg_id}" return f"<face_id: {self.face_id}, refimg_id={self.refimg_id}"
@@ -975,7 +975,7 @@ def AddToJobImageCount(job, entry ):
return return
def JobRunAIOn(job): def JobRunAIOn(job):
AddLogForJob(job, f"INFO: Starting looking For faces in files job...") AddLogForJob(job, f"INFO: Starting job to look for faces in files...")
which_person=[jex.value for jex in job.extra if jex.name == "person"][0] which_person=[jex.value for jex in job.extra if jex.name == "person"][0]
if which_person == "all": if which_person == "all":
job.refimgs = session.query(Refimg).all() job.refimgs = session.query(Refimg).all()
@@ -1010,8 +1010,6 @@ def JobRunAIOn(job):
ProcessFilesInDir( job, entry, WrapperForScanFileForPerson, False ) ProcessFilesInDir( job, entry, WrapperForScanFileForPerson, False )
elif entry.type.name == 'Image': elif entry.type.name == 'Image':
which_file=session.query(Entry).join(File).filter(Entry.id==jex.value).first() which_file=session.query(Entry).join(File).filter(Entry.id==jex.value).first()
if DEBUG:
AddLogForJob( job, f'INFO: processing File: {entry.name}' )
ScanFileForPerson( job, which_file, force=False) ScanFileForPerson( job, which_file, force=False)
# processed this file, add 1 to count # processed this file, add 1 to count
job.current_file_num+=1 job.current_file_num+=1
@@ -1339,11 +1337,11 @@ def InitialValidationChecks():
FinishJob(job,"Finished Initial Validation Checks") FinishJob(job,"Finished Initial Validation Checks")
return return
def AddFaceToFile( locn_data, face_data, file_eid, model ): def AddFaceToFile( locn_data, face_data, file_eid, model_id ):
face = Face( face=face_data.tobytes(), locn=json.dumps(locn_data) ) face = Face( face=face_data.tobytes(), locn=json.dumps(locn_data) )
session.add(face) session.add(face)
session.commit() session.commit()
ffl = FaceFileLink( face_id=face.id, file_eid=file_eid, model_used=model ) ffl = FaceFileLink( face_id=face.id, file_eid=file_eid, model_used=model_id )
session.add(ffl) session.add(ffl)
session.commit() session.commit()
return face return face
@@ -1377,6 +1375,13 @@ def BestFaceMatch(dist, fid, threshold):
return which, lowest return which, lowest
def ScanFileForPerson( job, e, force=False ): def ScanFileForPerson( job, e, force=False ):
# get default_scan_model from settings (test this)
settings = session.query(Settings).first()
model=session.query(AIModel).get(settings.default_scan_model)
threshold = settings.default_threshold
if DEBUG:
AddLogForJob( job, f'INFO: processing File: {e.name} and threshold face distance of {threshold}' )
file_h = session.query(File).get( e.id ) file_h = session.query(File).get( e.id )
# if we are forcing this, delete any old faces (this will also delete linked tables), and reset faces_created_on to None # if we are forcing this, delete any old faces (this will also delete linked tables), and reset faces_created_on to None
if force: if force:
@@ -1384,21 +1389,15 @@ def ScanFileForPerson( job, e, force=False ):
DelFacesForFile( e.id ) DelFacesForFile( e.id )
file_h.faces_created_on = 0 file_h.faces_created_on = 0
# get default_scan_model from settings (test this)
settings = session.query(Settings).first()
model=settings.default_scan_model
threshold = settings.default_threshold
# optimise: dont rescan if we already have faces # optimise: dont rescan if we already have faces
if file_h.faces_created_on == 0: if file_h.faces_created_on == 0:
if DEBUG: if DEBUG:
AddLogForJob( job, f"DEBUG: {e.name} is missing unknown faces, generating them" ) AddLogForJob( job, f"DEBUG: {e.name} is missing unknown faces, generating them with model {model.name}" )
im = face_recognition.load_image_file(e.FullPathOnFS()) im = face_recognition.load_image_file(e.FullPathOnFS())
model=AIModel.query.get(model) face_locations = face_recognition.face_locations(im, model=model.name )
face_locations = face_recognition.face_locations(im, model=model.name)
unknown_encodings = face_recognition.face_encodings(im, known_face_locations=face_locations) unknown_encodings = face_recognition.face_encodings(im, known_face_locations=face_locations)
for locn, face in zip( face_locations, unknown_encodings ): for locn, face in zip( face_locations, unknown_encodings ):
AddFaceToFile( locn, face, e.id, model ) AddFaceToFile( locn, face, e.id, model.id )
file_h.faces_created_on = time.time() file_h.faces_created_on = time.time()
session.commit() session.commit()