Skip to content

Commit

Permalink
Merge pull request #3 from drajsel/fix-requests-exception
Browse files Browse the repository at this point in the history
Make the dlib download request within a with statement
  • Loading branch information
aqeelanwar authored Sep 4, 2020
2 parents 734ac78 + 1cb7b7d commit 9390199
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions utils/aux_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,17 @@ def download_dlib_model():
print_orderly("Get dlib model", 60)
dlib_model_link = "http://dlib.net/files/shape_predictor_68_face_landmarks.dat.bz2"
print("Downloading dlib model...")
r = requests.get(dlib_model_link, stream=True)
print("Zip file size: ", np.round(len(r.content) / 1024 / 1024, 2), "MB")
destination = (
"dlib_models" + os.path.sep + "shape_predictor_68_face_landmarks.dat.bz2"
)
if not os.path.exists(destination.rsplit(os.path.sep, 1)[0]):
os.mkdir(destination.rsplit(os.path.sep, 1)[0])
print("Saving dlib model...")
with open(destination, "wb") as fd:
for chunk in r.iter_content(chunk_size=32678):
fd.write(chunk)
with requests.get(dlib_model_link, stream=True) as r:
print("Zip file size: ", np.round(len(r.content) / 1024 / 1024, 2), "MB")
destination = (
"dlib_models" + os.path.sep + "shape_predictor_68_face_landmarks.dat.bz2"
)
if not os.path.exists(destination.rsplit(os.path.sep, 1)[0]):
os.mkdir(destination.rsplit(os.path.sep, 1)[0])
print("Saving dlib model...")
with open(destination, "wb") as fd:
for chunk in r.iter_content(chunk_size=32678):
fd.write(chunk)
print("Extracting dlib model...")
with bz2.BZ2File(destination) as fr, open(
"dlib_models/shape_predictor_68_face_landmarks.dat", "wb"
Expand Down

0 comments on commit 9390199

Please sign in to comment.