mirror of
https://github.com/serengil/deepface.git
synced 2025-07-23 10:20:03 +00:00
workaround for interrupted weights
This commit is contained in:
parent
5c6e9be50a
commit
c2464a5c55
@ -7,6 +7,19 @@ from keras.preprocessing import image
|
|||||||
import cv2
|
import cv2
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
import gdown
|
import gdown
|
||||||
|
import hashlib
|
||||||
|
|
||||||
|
def findFileHash(file):
|
||||||
|
BLOCK_SIZE = 65536 # The size of each read from the file
|
||||||
|
|
||||||
|
file_hash = hashlib.sha256() # Create the hash object, can use something other than `.sha256()` if you wish
|
||||||
|
with open(file, 'rb') as f: # Open the file to read it's bytes
|
||||||
|
fb = f.read(BLOCK_SIZE) # Read from the file. Take in the amount declared above
|
||||||
|
while len(fb) > 0: # While there is still data being read from the file
|
||||||
|
file_hash.update(fb) # Update the hash
|
||||||
|
fb = f.read(BLOCK_SIZE) # Read the next block from the file
|
||||||
|
|
||||||
|
return file_hash.hexdigest()
|
||||||
|
|
||||||
def initializeFolder():
|
def initializeFolder():
|
||||||
|
|
||||||
@ -20,6 +33,34 @@ def initializeFolder():
|
|||||||
os.mkdir(home+"/.deepface/weights")
|
os.mkdir(home+"/.deepface/weights")
|
||||||
print("Directory ",home,"/.deepface/weights created")
|
print("Directory ",home,"/.deepface/weights created")
|
||||||
|
|
||||||
|
#----------------------------------
|
||||||
|
"""
|
||||||
|
#avoid interrupted file download
|
||||||
|
|
||||||
|
weight_hashes = [
|
||||||
|
['age_model_weights.h5', '0aeff75734bfe794113756d2bfd0ac823d51e9422c8961125b570871d3c2b114']
|
||||||
|
, ['facenet_weights.h5', '90659cc97bfda5999120f95d8e122f4d262cca11715a21e59ba024bcce816d5c']
|
||||||
|
, ['facial_expression_model_weights.h5', 'e8e8851d3fa05c001b1c27fd8841dfe08d7f82bb786a53ad8776725b7a1e824c']
|
||||||
|
, ['gender_model_weights.h5', '45513ce5678549112d25ab85b1926fb65986507d49c674a3d04b2ba70dba2eb5']
|
||||||
|
, ['openface_weights.h5', '5b41897ec6dd762cee20575eee54ed4d719a78cb982b2080a87dc14887d88a7a']
|
||||||
|
, ['race_model_single_batch.h5', 'eb22b28b1f6dfce65b64040af4e86003a5edccb169a1a338470dde270b6f5e54']
|
||||||
|
, ['vgg_face_weights.h5', '759266b9614d0fd5d65b97bf716818b746cc77ab5944c7bffc937c6ba9455d8c']
|
||||||
|
]
|
||||||
|
|
||||||
|
for i in weight_hashes:
|
||||||
|
|
||||||
|
weight_file = home+"/.deepface/weights/"+i[0]
|
||||||
|
expected_hash = i[1]
|
||||||
|
|
||||||
|
#check file exits
|
||||||
|
if os.path.isfile(weight_file) == True:
|
||||||
|
current_hash = findFileHash(weight_file)
|
||||||
|
if current_hash != expected_hash:
|
||||||
|
print("hash violated for ", i[0],". It's going to be removed.")
|
||||||
|
os.remove(weight_file)
|
||||||
|
"""
|
||||||
|
#----------------------------------
|
||||||
|
|
||||||
def findThreshold(model_name, distance_metric):
|
def findThreshold(model_name, distance_metric):
|
||||||
|
|
||||||
threshold = 0.40
|
threshold = 0.40
|
||||||
|
Loading…
x
Reference in New Issue
Block a user