face_distance is a float, also pass model through correctly to FaceFileLink
This commit is contained in:
@@ -261,7 +261,7 @@ class FaceRefimgLink(Base):
|
||||
__tablename__ = "face_refimg_link"
|
||||
face_id = Column(Integer, ForeignKey("face.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):
|
||||
return f"<face_id: {self.face_id}, refimg_id={self.refimg_id}"
|
||||
@@ -975,7 +975,7 @@ def AddToJobImageCount(job, entry ):
|
||||
return
|
||||
|
||||
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]
|
||||
if which_person == "all":
|
||||
job.refimgs = session.query(Refimg).all()
|
||||
@@ -1010,8 +1010,6 @@ def JobRunAIOn(job):
|
||||
ProcessFilesInDir( job, entry, WrapperForScanFileForPerson, False )
|
||||
elif entry.type.name == 'Image':
|
||||
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)
|
||||
# processed this file, add 1 to count
|
||||
job.current_file_num+=1
|
||||
@@ -1339,11 +1337,11 @@ def InitialValidationChecks():
|
||||
FinishJob(job,"Finished Initial Validation Checks")
|
||||
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) )
|
||||
session.add(face)
|
||||
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.commit()
|
||||
return face
|
||||
@@ -1377,6 +1375,13 @@ def BestFaceMatch(dist, fid, threshold):
|
||||
return which, lowest
|
||||
|
||||
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 )
|
||||
# if we are forcing this, delete any old faces (this will also delete linked tables), and reset faces_created_on to None
|
||||
if force:
|
||||
@@ -1384,21 +1389,15 @@ def ScanFileForPerson( job, e, force=False ):
|
||||
DelFacesForFile( e.id )
|
||||
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
|
||||
if file_h.faces_created_on == 0:
|
||||
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())
|
||||
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)
|
||||
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()
|
||||
session.commit()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user