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

2
BUGs
View File

@@ -1,6 +1,6 @@
### Next: 15
BUG-11: Ai ref img jobs are not able to be "re-run"
- only need to calc refimgs once (so timestamp in refimg and check it)
DONE - only need to calc refimgs once (so timestamp in refimg and check it)
- if we re-run a process AI job and no file changes, then don't process (as above)
- if we do see a new file/updated file, should delete all FPLs then insert new
-- probably should insert new into a file.people.append(...), rather than FPL direct

4
TODO
View File

@@ -1,5 +1,7 @@
## DB
NEW_FILE -> add, has_unidentified_face
should FPL really be EPL?
FILE -> add, has_unidentified_face
?has_face?,
AI_SCAN:

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()

View File

@@ -25,6 +25,7 @@ create table PERSON ( ID integer, TAG varchar(48), FIRSTNAME varchar(48), SURNAM
constraint PK_PERSON_ID primary key(ID) );
create table REFIMG ( ID integer, FNAME varchar(256), ENCODINGS bytea,
CREATED_ON fLOAT,
constraint PK_REFIMG_ID primary key(ID) );
create table FILE_PERSON_LINK ( FILE_ID integer, PERSON_ID integer,