partial fix/optimisation for refimgs, only recalc if file is newer than when we build the refimg encoding

This commit is contained in:
2021-01-23 21:21:29 +11:00
parent 6f2175c973
commit 469745ce3b
4 changed files with 14 additions and 4 deletions

View File

@@ -147,9 +147,10 @@ class Refimg(Base):
id = Column(Integer, Sequence('refimg_id_seq'), primary_key=True )
fname = Column(String(256), unique=True, nullable=False)
encodings = Column(LargeBinary)
created_on = Column(Float)
def __repr__(self):
return "<id: {}, fname: {}, encodings: {}>".format(self.id, self.fname, self.encodings )
return f"<id: {id}, fname: {fname}, created_on: {created_on}, encodings: {encodings}>"
class File_Person_Link(Base):
__tablename__ = "file_person_link"
@@ -545,10 +546,16 @@ def generateUnknownEncodings(im):
def generateKnownEncodings(person):
for refimg in person.refimg:
img = face_recognition.load_image_file('reference_images/'+refimg.fname)
file = 'reference_images/'+refimg.fname
stat = os.stat(file)
if refimg.created_on and stat.st_ctime < refimg.created_on:
print("DEBUG: skipping re-creating encoding for refimg because file has changed since we did this before")
continue
img = face_recognition.load_image_file(file)
location = face_recognition.face_locations(img)
encodings = face_recognition.face_encodings(img, known_face_locations=location)
refimg.encodings = encodings[0].tobytes()
refimg.created_on = time.time()
session.add(refimg)
session.commit()