This commit is contained in:
2024-12-12 21:58:18 +08:00
parent 02ae03d147
commit e394669ac2
2 changed files with 86 additions and 16 deletions
+30 -3
View File
@@ -1,4 +1,7 @@
import bz2
import os
import tempfile
import requests
import tqdm
import tarfile
@@ -62,6 +65,27 @@ def decompress(file_path, output_dir):
tar.extract(member, path=output_dir)
bar.update(1)
def decompress_bz2(file_path, output_dir):
# 确保输出目录存在
os.makedirs(output_dir, exist_ok=True)
print('解压 ' + file_path.split('/')[-1], '', output_dir)
# 获取.bz2文件的名称,不包含扩展名
output_filename = os.path.basename(file_path).rsplit('.bz2', 1)[0]
# 构建输出文件的完整路径
output_file_path = os.path.join(output_dir, output_filename)
# 检查输出文件是否已存在,如果存在则跳过解压
if os.path.exists(output_file_path):
print(output_filename, ' 已存在,跳过解压')
return
# 解压.bz2文件
with bz2.BZ2File(file_path, 'rb') as bz2_file, open(output_file_path, 'wb') as output_file:
output_file.write(bz2_file.read())
# 下载人脸数据集
face_dataset_url='http://vis-www.cs.umass.edu/fddb/originalPics.tar.gz'
face_dataset_path='cache/dataset/face/'
@@ -77,8 +101,11 @@ decompress(os.path.join(face_dataset_path,face_dataset_url.split('/')[-1]),face_
decompress(os.path.join(face_label_path,face_label_url.split('/')[-1]),face_label_path)
# 下载ResNet模型
model_url1='https://github.com/davisking/dlib-models/raw/master/shape_predictor_68_face_landmarks.dat'
model_url2='https://github.com/davisking/dlib-models/raw/master/dlib_face_recognition_resnet_model_v1.dat'
model_url1='https://github.com/davisking/dlib-models/raw/refs/heads/master/shape_predictor_68_face_landmarks.dat.bz2'
model_url2='https://github.com/davisking/dlib-models/raw/refs/heads/master/dlib_face_recognition_resnet_model_v1.dat.bz2'
model_path='models/'
download(model_url1,model_path)
download(model_url2,model_path)
download(model_url2,model_path)
decompress_bz2(os.path.join(model_path,model_url1.split('/')[-1]),model_path)
decompress_bz2(os.path.join(model_path,model_url2.split('/')[-1]),model_path)