FangSen9000 commited on
Commit
0c05e55
·
1 Parent(s): 46a10a9

Official version v0.1

Browse files
README.md CHANGED
@@ -2,12 +2,44 @@
2
 
3
  The entire project is divided into two parts: `text_or_gloss2pose` and `pose2video`. "Pose" here refers to the skeleton pose video after drawing.
4
 
5
- - In the text2pose section, I first used the DWpose tool to extract the npz format pose information for each word video frame by frame, and then merged each frame's npz into a large npz file. That is to say, we know the consecutive poses corresponding to each word. These consecutive poses are stored in the merged npz file. (We can also use deep learning models to generate these poses, but for commercial-level accuracy, this original data Dict method will be much more accurate.)
6
 
7
- - In the pose2video section, we render the visualized poses of the skeletons generated by each word. I used the ControlNext-SVD model for this.
8
 
9
  # For Users
10
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
 
12
 
13
  # For developers
@@ -71,7 +103,7 @@ CUDA_VISIBLE_DEVICES=0 python ControlNeXt-SVD-v2/run_controlnext_optimized.py \
71
  --width 512 \
72
  --controlnext_path ControlNeXt-SVD-v2/pretrained/controlnet.bin \
73
  --unet_path ControlNeXt-SVD-v2/pretrained/unet.bin \
74
- --pose_video_path generated_pose_video/GOOD_AFTERNOON_25073_01435_20250803_222800.mp4 \
75
  --ref_image_path ref_img_dict/03.jpeg \
76
  --precision fp16 \
77
  --enable_xformers \
 
2
 
3
  The entire project is divided into two parts: `text_or_gloss2pose` and `pose2video`. "Pose" here refers to the skeleton pose video after drawing.
4
 
5
+ - In the text2pose section (`Expected 4 seconds / one video`), I first used the DWpose tool to extract the npz format pose information for each word video frame by frame, and then merged each frame's npz into a large npz file. That is to say, we know the consecutive poses corresponding to each word. These consecutive poses are stored in the merged npz file. (We can also use deep learning models to generate these poses, but for commercial-level accuracy, this original data Dict method will be much more accurate.)
6
 
7
+ - In the pose2video section (`Expected 4 minutes / one video`), we render the visualized poses of the skeletons generated by each word. I used the ControlNext-SVD model for this.
8
 
9
  # For Users
10
 
11
+ 1. cd StableSigner
12
+ 2. conda env create -f env/environment02_controlnext.yml
13
+ 3. run `conda activate controlnext`
14
+ 4. run `pip install -r env/requirements02_controlnext.txt`
15
+
16
+ first, change `good morning afternoon`, and run:
17
+
18
+ ```python
19
+ python text2pose.py --gloss "good morning afternoon" --npz-interpolation 20 --width 512 --height 768 --fps 30
20
+ ```
21
+
22
+ second, change `generated_pose_video/GOOD_MORNING_AFTERNOON_25073_36863_01435_20250803_233215.mp4` & `ref_img_dict/03.jpeg`, and run:
23
+
24
+ ```python
25
+ CUDA_VISIBLE_DEVICES=0 python ControlNeXt-SVD-v2/run_controlnext_optimized.py \
26
+ --pretrained_model_name_or_path stabilityai/stable-video-diffusion-img2vid-xt-1-1 \
27
+ --output_dir generated_sign_video \
28
+ --max_frame_num 240 \
29
+ --guidance_scale 3 \
30
+ --batch_frames 24 \
31
+ --sample_stride 2 \
32
+ --overlap 4 \
33
+ --height 768 \
34
+ --width 512 \
35
+ --controlnext_path ControlNeXt-SVD-v2/pretrained/controlnet.bin \
36
+ --unet_path ControlNeXt-SVD-v2/pretrained/unet.bin \
37
+ --pose_video_path generated_pose_video/GOOD_MORNING_AFTERNOON_25073_36863_01435_20250803_233215.mp4 \
38
+ --ref_image_path ref_img_dict/03.jpeg \
39
+ --precision fp16 \
40
+ --enable_xformers \
41
+ --decode_chunk_size 2
42
+ ```
43
 
44
 
45
  # For developers
 
103
  --width 512 \
104
  --controlnext_path ControlNeXt-SVD-v2/pretrained/controlnet.bin \
105
  --unet_path ControlNeXt-SVD-v2/pretrained/unet.bin \
106
+ --pose_video_path generated_pose_video/GOOD_MORNING_AFTERNOON_25073_36863_01435_20250803_233215.mp4 \
107
  --ref_image_path ref_img_dict/03.jpeg \
108
  --precision fp16 \
109
  --enable_xformers \
easy_dwpose/draw/__pycache__/controlnext.cpython-310.pyc CHANGED
Binary files a/easy_dwpose/draw/__pycache__/controlnext.cpython-310.pyc and b/easy_dwpose/draw/__pycache__/controlnext.cpython-310.pyc differ
 
generated_pose_video/{GOOD_AFTERNOON_25073_01435_20250803_222800.mp4 → GOOD_MORNING_AFTERNOON_25073_36863_01435_20250803_233215.mp4} RENAMED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:c09157720812d8c72b29fd76b701f60434ba1e5299aaec2054aa49f5fd97495a
3
- size 1003827
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:0fe3c60fcfffa5c18867d43d23c0c72ee4dfa7abe59b4e80d79de87ba2cffce5
3
+ size 1685778
generated_pose_video/HELLO_WORLD_27184_63831_20250803_165003_fade.mp4 DELETED
@@ -1,3 +0,0 @@
1
- version https://git-lfs.github.com/spec/v1
2
- oid sha256:94919506b7131e8313c931608196190092d523574f8858d77abaf384509e6717
3
- size 1667961
 
 
 
 
generated_sign_video/GOOD_AFTERNOON_25073_01435_20250803_222800.mp4 DELETED
@@ -1,3 +0,0 @@
1
- version https://git-lfs.github.com/spec/v1
2
- oid sha256:03ae3f09974b40e1aa8e74feb86b8712060537b8eb69bd24344b5104f4d406fe
3
- size 585379
 
 
 
 
generated_sign_video/GOOD_AFTERNOON_25073_01435_20250803_222800_combined.mp4 DELETED
@@ -1,3 +0,0 @@
1
- version https://git-lfs.github.com/spec/v1
2
- oid sha256:04d3f48926a2e3b26889f47d176d7a68c157bdb8f17ae9800b19146e3bda3507
3
- size 815754
 
 
 
 
generated_pose_video/GOOD_MORNING_AFTERNOON_25073_36863_01435_20250803_231751.mp4 → generated_sign_video/GOOD_MORNING_AFTERNOON_25073_36863_01435_20250803_233215.mp4 RENAMED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:761d087c399b83e83d0246c6eb84d5cefe7290a01ceb59f1bbab2a29e7a4bf26
3
- size 1688288
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:c63044ffcffb6d3b4882da43bffe6f61ff3b521c5ba5a1b9cc446a910f574e07
3
+ size 1029963
generated_pose_video/HELLO_27184_20250803_164908.mp4 → generated_sign_video/GOOD_MORNING_AFTERNOON_25073_36863_01435_20250803_233215_combined.mp4 RENAMED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:6351055b804acc5473154d575f65eab0946de032a266eb765a92312b8c0e8f12
3
- size 561551
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:668ed7a6757f8b029cb1c66745e0d580ddceb1547d639dd21bdf5809433f6c7e
3
+ size 1401238
utils/__pycache__/npz_interpolation.cpython-310.pyc CHANGED
Binary files a/utils/__pycache__/npz_interpolation.cpython-310.pyc and b/utils/__pycache__/npz_interpolation.cpython-310.pyc differ
 
utils/npz_interpolation.py CHANGED
@@ -64,18 +64,42 @@ def catmull_rom_spline(p0, p1, p2, p3, num_points, tension=0.5):
64
  """
65
  points = []
66
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
67
  for i in range(num_points):
68
  t = i / (num_points - 1)
69
  t2 = t * t
70
  t3 = t2 * t
71
 
72
- # Catmull-Rom basis functions
73
  v0 = -tension * t + 2 * tension * t2 - tension * t3
74
  v1 = 1 + (tension - 3) * t2 + (2 - tension) * t3
75
  v2 = tension * t + (3 - 2 * tension) * t2 + (tension - 2) * t3
76
  v3 = -tension * t2 + tension * t3
77
 
78
- point = v0 * p0 + v1 * p1 + v2 * p2 + v3 * p3
 
 
 
 
 
 
 
 
79
  points.append(point)
80
 
81
  return np.array(points)
@@ -159,7 +183,7 @@ def interpolate_pose_npz(npz1_data, npz2_data, num_frames=10, method='catmull-ro
159
  t_eased = ease_in_out_sine(t)
160
  interpolated = data1 * (1 - t_eased) + data2 * t_eased
161
  else:
162
- # For keypoints, use spline interpolation
163
  # Get control points
164
  prev_key = f"frame_{prev_frame_key1.split('_')[1]}_{component}"
165
  next_key = f"frame_{next_frame_key2.split('_')[1]}_{component}"
@@ -173,15 +197,30 @@ def interpolate_pose_npz(npz1_data, npz2_data, num_frames=10, method='catmull-ro
173
  interpolated = np.zeros_like(data1)
174
  for person_idx in range(data1.shape[0]):
175
  for joint_idx in range(data1.shape[1]):
176
- # Interpolate each joint
177
- points = catmull_rom_spline(
178
- p0[person_idx, joint_idx],
179
- p1[person_idx, joint_idx],
180
- p2[person_idx, joint_idx],
181
- p3[person_idx, joint_idx],
182
- num_points=num_frames
183
- )
184
- interpolated[person_idx, joint_idx] = points[i]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
185
  else:
186
  # Single dimension data
187
  t_eased = ease_in_out_sine(t)
 
64
  """
65
  points = []
66
 
67
+ # Check for invalid points (coordinates that are 0, -1, or out of reasonable bounds)
68
+ def is_valid_point(p):
69
+ if isinstance(p, np.ndarray):
70
+ # Check if any coordinate is -1, 0, or unreasonably large
71
+ return np.all(p > 0) and np.all(p < 2000) # Assuming 2000 is max reasonable coordinate
72
+ return False
73
+
74
+ # If endpoints are invalid, fall back to linear interpolation
75
+ if not is_valid_point(p1) or not is_valid_point(p2):
76
+ # Simple linear interpolation for invalid points
77
+ for i in range(num_points):
78
+ t = i / (num_points - 1)
79
+ point = p1 * (1 - t) + p2 * t
80
+ points.append(point)
81
+ return np.array(points)
82
+
83
  for i in range(num_points):
84
  t = i / (num_points - 1)
85
  t2 = t * t
86
  t3 = t2 * t
87
 
88
+ # Catmull-Rom basis functions with clamping to prevent overshoot
89
  v0 = -tension * t + 2 * tension * t2 - tension * t3
90
  v1 = 1 + (tension - 3) * t2 + (2 - tension) * t3
91
  v2 = tension * t + (3 - 2 * tension) * t2 + (tension - 2) * t3
92
  v3 = -tension * t2 + tension * t3
93
 
94
+ # Use valid control points or fall back to endpoints
95
+ p0_safe = p0 if is_valid_point(p0) else p1
96
+ p3_safe = p3 if is_valid_point(p3) else p2
97
+
98
+ point = v0 * p0_safe + v1 * p1 + v2 * p2 + v3 * p3_safe
99
+
100
+ # Clamp to reasonable bounds to prevent extreme values
101
+ point = np.clip(point, 0, 2000)
102
+
103
  points.append(point)
104
 
105
  return np.array(points)
 
183
  t_eased = ease_in_out_sine(t)
184
  interpolated = data1 * (1 - t_eased) + data2 * t_eased
185
  else:
186
+ # For keypoints, use spline interpolation with validation
187
  # Get control points
188
  prev_key = f"frame_{prev_frame_key1.split('_')[1]}_{component}"
189
  next_key = f"frame_{next_frame_key2.split('_')[1]}_{component}"
 
197
  interpolated = np.zeros_like(data1)
198
  for person_idx in range(data1.shape[0]):
199
  for joint_idx in range(data1.shape[1]):
200
+ # Check if both keypoints are valid (not -1 or 0)
201
+ kp1 = p1[person_idx, joint_idx]
202
+ kp2 = p2[person_idx, joint_idx]
203
+
204
+ # Skip interpolation for invalid keypoints
205
+ if np.any(kp1 <= 0) or np.any(kp2 <= 0):
206
+ # Use the valid keypoint or zero
207
+ if np.any(kp1 > 0):
208
+ interpolated[person_idx, joint_idx] = kp1
209
+ elif np.any(kp2 > 0):
210
+ interpolated[person_idx, joint_idx] = kp2
211
+ else:
212
+ interpolated[person_idx, joint_idx] = 0
213
+ else:
214
+ # Only interpolate valid keypoints
215
+ points = catmull_rom_spline(
216
+ p0[person_idx, joint_idx],
217
+ p1[person_idx, joint_idx],
218
+ p2[person_idx, joint_idx],
219
+ p3[person_idx, joint_idx],
220
+ num_points=num_frames,
221
+ tension=0.3 # Lower tension for less overshoot
222
+ )
223
+ interpolated[person_idx, joint_idx] = points[i]
224
  else:
225
  # Single dimension data
226
  t_eased = ease_in_out_sine(t)