chenlei commited on
Commit
ef9d2e2
·
1 Parent(s): 9eb3d31
preprocess/openpose/annotator/openpose/__init__.py CHANGED
@@ -17,6 +17,7 @@ from .hand import Hand
17
  from .face import Face
18
  from annotator.util import annotator_ckpts_path
19
  import requests
 
20
 
21
  body_model_path = "https://huggingface.co/lllyasviel/Annotators/resolve/main/body_pose_model.pth"
22
  hand_model_path = "https://huggingface.co/lllyasviel/Annotators/resolve/main/hand_pose_model.pth"
@@ -45,18 +46,34 @@ def draw_pose(pose, H, W, draw_body=True, draw_hand=True, draw_face=True):
45
 
46
  class OpenposeDetector:
47
  def __init__(self):
48
- body_modelpath = "/home/user/app/checkpoints/openpose/ckpts/body_pose_model.pth"
49
  # hand_modelpath = os.path.join(annotator_ckpts_path, "hand_pose_model.pth")
50
  # face_modelpath = os.path.join(annotator_ckpts_path, "facenet.pth")
51
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
52
  if not os.path.exists(body_modelpath):
 
 
 
 
53
  # from basicsr.utils.download_util import load_file_from_url
54
  # load_file_from_url(body_model_path, model_dir=annotator_ckpts_path)
55
- response = requests.get(body_model_path)
56
- #下载该文件
57
- with open("body_pose_model.pth", "wb") as f:
58
- f.write(response.content)
59
- print("body_pose_model.pth下载完成")
60
 
61
  # if not os.path.exists(hand_modelpath):
62
  # from basicsr.utils.download_util import load_file_from_url
 
17
  from .face import Face
18
  from annotator.util import annotator_ckpts_path
19
  import requests
20
+ import shutil
21
 
22
  body_model_path = "https://huggingface.co/lllyasviel/Annotators/resolve/main/body_pose_model.pth"
23
  hand_model_path = "https://huggingface.co/lllyasviel/Annotators/resolve/main/hand_pose_model.pth"
 
46
 
47
  class OpenposeDetector:
48
  def __init__(self):
49
+ body_modelpath = os.path.join(annotator_ckpts_path, "body_pose_model.pth")
50
  # hand_modelpath = os.path.join(annotator_ckpts_path, "hand_pose_model.pth")
51
  # face_modelpath = os.path.join(annotator_ckpts_path, "facenet.pth")
52
+ #判断body_modelpath是否是一个目录
53
+ if os.path.isdir(body_modelpath):
54
+ print("body_modelpath是一个目录")
55
+ #删除目录
56
+ shutil.rmtree(body_modelpath)
57
+ print("body_modelpath目录删除完成")
58
+
59
+
60
+ if not os.path.exists(annotator_ckpts_path):
61
+ #创建目录
62
+ os.makedirs(annotator_ckpts_path)
63
+ #从url下载文件
64
+ response = requests.get(body_model_path)
65
+ with open(body_modelpath, "wb") as f:
66
+ f.write(response.content)
67
+ print("body_pose_model.pth下载完成")
68
+
69
+ #判断文件是否存在
70
  if not os.path.exists(body_modelpath):
71
+ print("body_pose_model.pth下载失败")
72
+
73
+
74
+
75
  # from basicsr.utils.download_util import load_file_from_url
76
  # load_file_from_url(body_model_path, model_dir=annotator_ckpts_path)
 
 
 
 
 
77
 
78
  # if not os.path.exists(hand_modelpath):
79
  # from basicsr.utils.download_util import load_file_from_url