yolozyk commited on
Commit
df91e2b
·
verified ·
1 Parent(s): 50d2227

Update src/generate_utils/generate.py

Browse files
Files changed (1) hide show
  1. src/generate_utils/generate.py +9 -17
src/generate_utils/generate.py CHANGED
@@ -26,8 +26,8 @@ class PressureGenerator:
26
  }
27
 
28
  def __init__(self,
29
- ckpt_dir="src/generate_utils/lib/ckpt/pressurepose_20251222_180032",
30
- smpl_model_dir="src/smpl_models",
31
  device="cpu"):
32
  """
33
  初始化生成器:加载配置、权重和 SMPL 模型。
@@ -58,13 +58,7 @@ class PressureGenerator:
58
  def _load_config(self):
59
  config_path = os.path.join(self.ckpt_dir, 'config.yaml')
60
  if not os.path.exists(config_path):
61
- from huggingface_hub import snapshot_download
62
- snapshot_download(
63
- "yolozyk/PaGe",
64
- local_dir="src/generate_utils/lib/ckpt/",
65
- local_dir_use_symlinks=False,
66
- ignore_patterns=["*.safetensors", ".gitattributes"],
67
- )
68
  with open(config_path, 'r') as f:
69
  return yaml.safe_load(f)
70
 
@@ -73,13 +67,7 @@ class PressureGenerator:
73
  ckpt_path = os.path.join(self.ckpt_dir, 'ckpts', 'best_model.pth')
74
 
75
  if not os.path.exists(ckpt_path):
76
- from huggingface_hub import snapshot_download
77
- snapshot_download(
78
- "yolozyk/PaGe",
79
- local_dir="src/generate_utils/lib/ckpt/",
80
- local_dir_use_symlinks=False,
81
- ignore_patterns=["*.safetensors", ".gitattributes"],
82
- )
83
 
84
  checkpoint = torch.load(ckpt_path, map_location=self.device)
85
  model.load_state_dict(checkpoint['model_state_dict'])
@@ -97,7 +85,7 @@ class PressureGenerator:
97
  return smpl
98
 
99
  @torch.no_grad()
100
- def generate(self, betas, transl, poses):
101
  """
102
  执行推理。
103
  输入参数应该是 Tensor, 维度需符合模型要求 (Batch Size, ...)。
@@ -116,6 +104,10 @@ class PressureGenerator:
116
  )
117
  vertices = output.vertices
118
 
 
 
 
 
119
  # 2. 预测压力图
120
  pred_pmap = self.cvae_model.inference(vertices)
121
 
 
26
  }
27
 
28
  def __init__(self,
29
+ ckpt_dir="generate_utils/lib/ckpt/pressurepose_20251222_180032",
30
+ smpl_model_dir="E:/pyku/smpl_models",
31
  device="cpu"):
32
  """
33
  初始化生成器:加载配置、权重和 SMPL 模型。
 
58
  def _load_config(self):
59
  config_path = os.path.join(self.ckpt_dir, 'config.yaml')
60
  if not os.path.exists(config_path):
61
+ raise FileNotFoundError(f"Config not found at {config_path}")
 
 
 
 
 
 
62
  with open(config_path, 'r') as f:
63
  return yaml.safe_load(f)
64
 
 
67
  ckpt_path = os.path.join(self.ckpt_dir, 'ckpts', 'best_model.pth')
68
 
69
  if not os.path.exists(ckpt_path):
70
+ raise FileNotFoundError(f"Checkpoint not found at {ckpt_path}")
 
 
 
 
 
 
71
 
72
  checkpoint = torch.load(ckpt_path, map_location=self.device)
73
  model.load_state_dict(checkpoint['model_state_dict'])
 
85
  return smpl
86
 
87
  @torch.no_grad()
88
+ def generate(self, betas, transl, poses, transfer=False):
89
  """
90
  执行推理。
91
  输入参数应该是 Tensor, 维度需符合模型要求 (Batch Size, ...)。
 
104
  )
105
  vertices = output.vertices
106
 
107
+ if transfer:
108
+ vertices[:, :, 1] = 1.80 - vertices[:, :, 1]
109
+ vertices[:, :, 2] = -vertices[:, :, 2]
110
+
111
  # 2. 预测压力图
112
  pred_pmap = self.cvae_model.inference(vertices)
113