FangSen9000 commited on
Commit
71f4e02
·
1 Parent(s): 9f38809

Fix prompt2gloss import and refine outputs

Browse files
One-to-All-Animation/video-generation/inference_1.3b.py CHANGED
@@ -366,6 +366,7 @@ def unified_worker(rank, world_size, task_list, ckpt_path, use_direct_paths=Fals
366
 
367
  alpha = 0.6
368
  frames_combined = []
 
369
 
370
  src_uint8 = ((pose_tensor / 2 + 0.5).clamp(0, 1) * 255
371
  )[0].byte().permute(1, 2, 3, 0).numpy() # (T,H,W,C)
@@ -378,6 +379,7 @@ def unified_worker(rank, world_size, task_list, ckpt_path, use_direct_paths=Fals
378
  blended = (alpha * src + (1 - alpha) * pred).round().astype(np.uint8)
379
  concat = np.concatenate([blended, pred.astype(np.uint8)], axis=1) # (H,2W,C)
380
  frames_combined.append(concat)
 
381
 
382
  imageio.mimwrite(
383
  final_video_path,
@@ -386,6 +388,15 @@ def unified_worker(rank, world_size, task_list, ckpt_path, use_direct_paths=Fals
386
  quality=5
387
  )
388
 
 
 
 
 
 
 
 
 
 
389
  print(f"[GPU {rank}] 完成视频: {final_video_path}")
390
  del pipe
391
  torch.cuda.empty_cache()
 
366
 
367
  alpha = 0.6
368
  frames_combined = []
369
+ frames_pred = []
370
 
371
  src_uint8 = ((pose_tensor / 2 + 0.5).clamp(0, 1) * 255
372
  )[0].byte().permute(1, 2, 3, 0).numpy() # (T,H,W,C)
 
379
  blended = (alpha * src + (1 - alpha) * pred).round().astype(np.uint8)
380
  concat = np.concatenate([blended, pred.astype(np.uint8)], axis=1) # (H,2W,C)
381
  frames_combined.append(concat)
382
+ frames_pred.append(pred.astype(np.uint8))
383
 
384
  imageio.mimwrite(
385
  final_video_path,
 
388
  quality=5
389
  )
390
 
391
+ final_pred_path = os.path.join(output_root, f"{job_name}_ref_{ref_cfg}_pose_{pose_cfg}_pred.mp4")
392
+ if not os.path.exists(final_pred_path):
393
+ imageio.mimwrite(
394
+ final_pred_path,
395
+ frames_pred,
396
+ fps=pose_fps,
397
+ quality=5
398
+ )
399
+
400
  print(f"[GPU {rank}] 完成视频: {final_video_path}")
401
  del pipe
402
  torch.cuda.empty_cache()
pipeline03_pose2video.sh CHANGED
@@ -6,44 +6,144 @@ source /research/cbim/vast/sf895/miniforge3/bin/activate one-to-all
6
  ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
7
  VIDEO_GEN_DIR="${ROOT_DIR}/One-to-All-Animation/video-generation"
8
 
9
- POSE_VIDEO="${POSE_VIDEO:-HELLO_GOOD_MORNING_20251215_142658_openpose_style.mp4}"
10
  REF_IMAGE="${REF_IMAGE:-${ROOT_DIR}/ref_img_dict/man.jpg}"
11
- GPU_ID="${GPU_ID:-1}"
12
  REF_CFG="${REF_CFG:-2.5}"
13
  POSE_CFG="${POSE_CFG:-1.5}"
14
  STAGE1_OUT_DIR="${STAGE1_OUT_DIR:-${ROOT_DIR}/generated_sign_video}"
15
  STAGE2_OUT_DIR="${STAGE2_OUT_DIR:-${ROOT_DIR}/generated_sign_video_refine}"
 
 
 
16
 
17
- echo "Stage1: pose2video"
18
- (
19
- cd "${VIDEO_GEN_DIR}"
20
- ONE_TO_ALL_OUTPUT_DIR="${STAGE1_OUT_DIR}" \
21
- CUDA_VISIBLE_DEVICES="${GPU_ID}" \
22
- python inference_1.3b.py --pose_video "${POSE_VIDEO}" --ref_image "${REF_IMAGE}"
23
- )
24
-
25
- pose_base="$(basename "${POSE_VIDEO}")"
26
- pose_base="${pose_base%.*}"
27
- ref_base="$(basename "${REF_IMAGE}")"
28
- ref_base="${ref_base%.*}"
29
-
30
- stage1_pattern="${STAGE1_OUT_DIR}"/*_ref_${REF_CFG}_pose_${POSE_CFG}/"ref_${ref_base}_vid_${pose_base}_ref_${REF_CFG}_pose_${POSE_CFG}.mp4"
31
- stage1_video="$(ls -t ${stage1_pattern} 2>/dev/null | head -n 1 || true)"
32
- if [[ -z "${stage1_video}" ]]; then
33
- echo "Stage1 output not found. Pattern: ${stage1_pattern}" >&2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
34
  exit 1
35
  fi
36
 
37
- echo "Stage2: refine on ${stage1_video}"
38
- (
39
- cd "${VIDEO_GEN_DIR}"
40
- ./infer_refine.sh \
41
- --input "${stage1_video}" \
42
- --ref "${REF_IMAGE}" \
43
- --ref-cfg "${REF_CFG}" \
44
- --pose-cfg "${POSE_CFG}" \
45
- --out-dir "${STAGE2_OUT_DIR}" \
46
- --gpu "${GPU_ID}"
47
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
48
 
49
  echo "Done."
 
6
  ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
7
  VIDEO_GEN_DIR="${ROOT_DIR}/One-to-All-Animation/video-generation"
8
 
9
+ POSE_VIDEO="${POSE_VIDEO:-}"
10
  REF_IMAGE="${REF_IMAGE:-${ROOT_DIR}/ref_img_dict/man.jpg}"
11
+ GPU_ID="${GPU_ID:-}"
12
  REF_CFG="${REF_CFG:-2.5}"
13
  POSE_CFG="${POSE_CFG:-1.5}"
14
  STAGE1_OUT_DIR="${STAGE1_OUT_DIR:-${ROOT_DIR}/generated_sign_video}"
15
  STAGE2_OUT_DIR="${STAGE2_OUT_DIR:-${ROOT_DIR}/generated_sign_video_refine}"
16
+ STAGE1_ONLY=0
17
+ STAGE2_ONLY=0
18
+ STAGE2_INPUT=""
19
 
20
+ usage() {
21
+ cat <<'USAGE'
22
+ Usage:
23
+ pipeline03_pose2video.sh --pose-video <pose.mp4> --ref-image <ref.jpg> [options]
24
+
25
+ Options:
26
+ --pose-video PATH Pose video for stage1 (or refine input if --stage2-only).
27
+ --ref-image PATH Reference image for both stages.
28
+ --stage1-out PATH Output dir for stage1 (default: generated_sign_video).
29
+ --stage2-out PATH Output dir for stage2 (default: generated_sign_video_refine).
30
+ --stage1-only Run only stage1.
31
+ --stage2-only Run only stage2 (uses --pose-video as refine input unless --stage2-input is provided).
32
+ --stage2-input PATH Explicit input video/frames for stage2 only.
33
+ --gpu ID GPU id (default: auto-pick free GPU).
34
+ --ref-cfg FLOAT Image guidance scale (default: 2.5).
35
+ --pose-cfg FLOAT Pose guidance scale (default: 1.5).
36
+ -h, --help Show this help.
37
+ USAGE
38
+ }
39
+
40
+ while [[ $# -gt 0 ]]; do
41
+ case "$1" in
42
+ --pose-video) POSE_VIDEO="$2"; shift 2;;
43
+ --ref-image) REF_IMAGE="$2"; shift 2;;
44
+ --stage1-out) STAGE1_OUT_DIR="$2"; shift 2;;
45
+ --stage2-out) STAGE2_OUT_DIR="$2"; shift 2;;
46
+ --stage1-only) STAGE1_ONLY=1; shift 1;;
47
+ --stage2-only) STAGE2_ONLY=1; shift 1;;
48
+ --stage2-input) STAGE2_INPUT="$2"; shift 2;;
49
+ --gpu) GPU_ID="$2"; shift 2;;
50
+ --ref-cfg) REF_CFG="$2"; shift 2;;
51
+ --pose-cfg) POSE_CFG="$2"; shift 2;;
52
+ -h|--help) usage; exit 0;;
53
+ *) echo "Unknown option: $1"; usage; exit 1;;
54
+ esac
55
+ done
56
+
57
+ if [[ "${STAGE1_ONLY}" -eq 1 && "${STAGE2_ONLY}" -eq 1 ]]; then
58
+ echo "Cannot use --stage1-only and --stage2-only together." >&2
59
  exit 1
60
  fi
61
 
62
+ pick_free_gpu() {
63
+ if command -v nvidia-smi >/dev/null 2>&1; then
64
+ local best
65
+ best="$(nvidia-smi --query-gpu=index,memory.free --format=csv,noheader,nounits 2>/dev/null | \
66
+ awk -F',' '{gsub(/ /,"",$2); if($2>max){max=$2; idx=$1}} END{print idx}')"
67
+ if [[ -n "${best}" ]]; then
68
+ echo "${best}"
69
+ return
70
+ fi
71
+ fi
72
+ echo "0"
73
+ }
74
+
75
+ if [[ -z "${GPU_ID}" ]]; then
76
+ GPU_ID="$(pick_free_gpu)"
77
+ echo "Using GPU: ${GPU_ID}"
78
+ fi
79
+
80
+ if [[ "${STAGE2_ONLY}" -eq 1 ]]; then
81
+ if [[ -z "${STAGE2_INPUT}" ]]; then
82
+ if [[ -n "${POSE_VIDEO}" ]]; then
83
+ STAGE2_INPUT="${POSE_VIDEO}"
84
+ echo "Stage2-only: using --pose-video as refine input."
85
+ else
86
+ echo "Stage2-only requires --stage2-input (or --pose-video)." >&2
87
+ exit 1
88
+ fi
89
+ fi
90
+ else
91
+ if [[ -z "${POSE_VIDEO}" ]]; then
92
+ echo "Stage1 requires --pose-video." >&2
93
+ exit 1
94
+ fi
95
+ fi
96
+
97
+ run_stage1() {
98
+ echo "Stage1: pose2video"
99
+ (
100
+ cd "${VIDEO_GEN_DIR}"
101
+ ONE_TO_ALL_OUTPUT_DIR="${STAGE1_OUT_DIR}" \
102
+ CUDA_VISIBLE_DEVICES="${GPU_ID}" \
103
+ python inference_1.3b.py --pose_video "${POSE_VIDEO}" --ref_image "${REF_IMAGE}"
104
+ )
105
+ }
106
+
107
+ resolve_stage1_output() {
108
+ local pose_base ref_base stage1_pattern stage1_video
109
+ pose_base="$(basename "${POSE_VIDEO}")"
110
+ pose_base="${pose_base%.*}"
111
+ ref_base="$(basename "${REF_IMAGE}")"
112
+ ref_base="${ref_base%.*}"
113
+
114
+ stage1_pattern="${STAGE1_OUT_DIR}"/*_ref_${REF_CFG}_pose_${POSE_CFG}/"ref_${ref_base}_vid_${pose_base}_ref_${REF_CFG}_pose_${POSE_CFG}.mp4"
115
+ stage1_video="$(ls -t ${stage1_pattern} 2>/dev/null | head -n 1 || true)"
116
+ if [[ -z "${stage1_video}" ]]; then
117
+ echo "Stage1 output not found. Pattern: ${stage1_pattern}" >&2
118
+ exit 1
119
+ fi
120
+ echo "${stage1_video}"
121
+ }
122
+
123
+ run_stage2() {
124
+ local input_video="$1"
125
+ echo "Stage2: refine on ${input_video}"
126
+ (
127
+ cd "${VIDEO_GEN_DIR}"
128
+ ./infer_refine.sh \
129
+ --input "${input_video}" \
130
+ --ref "${REF_IMAGE}" \
131
+ --ref-cfg "${REF_CFG}" \
132
+ --pose-cfg "${POSE_CFG}" \
133
+ --out-dir "${STAGE2_OUT_DIR}" \
134
+ --gpu "${GPU_ID}"
135
+ )
136
+ }
137
+
138
+ if [[ "${STAGE2_ONLY}" -ne 1 ]]; then
139
+ run_stage1
140
+ if [[ "${STAGE1_ONLY}" -eq 1 ]]; then
141
+ echo "Done (stage1 only)."
142
+ exit 0
143
+ fi
144
+ STAGE2_INPUT="$(resolve_stage1_output)"
145
+ fi
146
+
147
+ run_stage2 "${STAGE2_INPUT}"
148
 
149
  echo "Done."
prompt2gloss/__init__.py ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ """Prompt2Gloss package helpers."""
2
+
3
+ from .prompt2gloss import build_input # re-export for plugin importer
4
+
5
+ __all__ = ["build_input"]