updated job manager to (theoretically) work for ai, but i havent tested the comparison code yet

This commit is contained in:
c-d-p
2021-06-29 15:46:04 +10:00
parent 643208f35f
commit 818fdaa685

View File

@@ -952,8 +952,12 @@ def WrapperForScanFileForPerson(job, entry):
ppl=session.query(Person).all()
else:
ppl=session.query(Person).filter(Person.tag==which_person).all()
for person in ppl:
print( f"(wrapper) call == ScanFileForPerson( {entry.id}, {person.id}, force=False )" )
if entry.type.name == 'Image':
print( f"JobRunAIOn: file to process had id: {entry.id}" )
for person in ppl:
print( f"call == ScanFileForPerson( {entry.id}, {person.id}, force=False )" )
ScanFileForPerson( entry, person.id, force=False)
return
def JobRunAIOn(job):
@@ -970,7 +974,7 @@ def JobRunAIOn(job):
for jex in job.extra:
if 'eid-' in jex.name:
entry=session.query(Entry).get(jex.value)
print( f'en={entry}' )
print( f'en={entry.name}, {entry.type.name}' )
if entry.type.name == 'Directory':
ProcessFilesInDir( job, entry, WrapperForScanFileForPerson )
elif entry.type.name == 'Image':
@@ -978,10 +982,11 @@ def JobRunAIOn(job):
print( f"JobRunAIOn: file to process had id: {which_file.id}" )
for person in ppl:
print( f"call == ScanFileForPerson( {which_file.id}, {person.id}, force=False )" )
ScanFileForPerson( which_file, person.id, force=False)
else:
AddLogForJob( job, f'Not processing Entry: {entry.name} - not an image' )
print(" HARD EXITING to keep testing " )
exit( -1 )
#print(" HARD EXITING to keep testing " )
#exit( -1 )
FinishJob(job, "Finished Processesing AI")
return
@@ -1011,7 +1016,7 @@ def ProcessAI(job, e):
job.current_file_num+=1
return
file = e.FullPathOnFS()
file = e.FullPathOnFS()
stat = os.stat(file)
# find if file is newer than when we found faces before (fyi: first time faces_created_on == 0)
if stat.st_ctime > e.file_details.faces_created_on:
@@ -1101,7 +1106,7 @@ def compareAI(known_encoding, unknown_encoding):
def ProcessFilesInDir(job, e, file_func):
if DEBUG==1:
print( f"???? e={e}" )
print( f"DEBUG: ProcessFilesInDir: {e.FullPathOnFS()}")
# print( f"DEBUG: ProcessFilesInDir: {e.FullPathOnFS()}")
if e.type.name != 'Directory':
file_func(job, e)
else:
@@ -1411,32 +1416,39 @@ def UnmatchedFacesForFile( eid ):
return rows
### CAM: something like this -- HAVE NOT TRIED THIS IT WILL FAIL###
def ScanFileForPerson( eid, person_id, force=False ):
file_h = session.query(File).get( eid )
def ScanFileForPerson( e, person_id, force=False ):
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:
DelFacesForFile( eid )
DelFacesForFile( e.id )
file_h.faces_create_on = None
# optimise: dont rescan if we already have faces (we are just going to try
# to match (maybe?) a refimg
if not file_h.faces_created_on:
# CAM: TODO: add Face Rec code to get unknown encodings
print("------------- CAM -----------:\n")
im = face_recognition.load_image_file(e.FullPathOnFS())
print(im)
face_locations = face_recognition.face_locations(im)
print(f"FACE LOCATIONS: {face_locations}")
unknown_encodings = face_recognition.face_encodings(im, known_face_locations=face_locations)
print("AAAAAAAAAAAAAAAA " + str(len(unknown_encodings)))
for face in unknown_encodings:
new_face = Face( face_data = face )
session.add(new_face)
session.commit()
AddFaceToFile( new_face.id, eid )
AddFaceToFile( new_face.id, e.id )
now=datetime.now(pytz.utc)
file_h.face_created_on = now
## now look for person
refimgs = session.query(Refimg).join(PersonRefimgLink).filter(PersonRefimgLink.person_id==person_id).all()
uf = UnmatchedFacesForFile( eid )
uf = UnmatchedFacesForFile( e.id )
for face in uf:
for r in refimgs:
# CAM: TODO: add Face rec code to see if there is match
match = compareAI(r, uf)
if match:
print(f'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA WE MATCHED: {r}, {uf}')
MatchRefimgToFace( r.id, face.id )
return