Skip to content

如何使用xsmall版本模型可视化demo #78

@Mlin001

Description

@Mlin001

您好,我在使用训练的xsmall 模型运行可视化vis.py时,报错
Traceback (most recent call last):
File "demo/visagf.py", line 334, in
get_pose3D(video_path, output_dir)
File "/root/miniconda3/envs/motionagf/lib/python3.8/site-packages/torch/utils/_contextlib.py", line 115, in decorate_context
return func(*args, **kwargs)
File "demo/visagf.py", line 221, in get_pose3D
clips, downsample = turn_into_clips(keypoints)
File "demo/visagf.py", line 153, in turn_into_clips
return clips, downsample
UnboundLocalError: local variable 'downsample' referenced before assignment 我修改n_frames <= 27:可是依然报错,可能原因是当downsample在else: clips.append(keypoints_clip) 分支中没有被定义,以下是我的修改,不知道是否符合原代码处理逻辑
def turn_into_clips(keypoints):
clips = []
n_frames = keypoints.shape[1]

# 确保downsample总是有定义
downsample = np.arange(min(27, n_frames))

if n_frames <= 27:
    new_indices = resample(n_frames)
    clips.append(keypoints[:, new_indices, ...])
    if len(new_indices) > 0:
        downsample = np.unique(new_indices, return_index=True)[1]
else:
    for start_idx in range(0, n_frames, 27):
        keypoints_clip = keypoints[:, start_idx:start_idx + 27, ...]
        clip_length = keypoints_clip.shape[1]
        if clip_length != 27:
            new_indices = resample(clip_length)
            clips.append(keypoints_clip[:, new_indices, ...])
            if len(new_indices) > 0:
                downsample = np.unique(new_indices, return_index=True)[1]
        else:
            clips.append(keypoints_clip)
            downsample = np.arange(27)  # 当clip正好27帧时

return clips, downsample

原代码:
def turn_into_clips(keypoints):
clips = []
n_frames = keypoints.shape[1]
if n_frames <= 243:
new_indices = resample(n_frames)
clips.append(keypoints[:, new_indices, ...])
downsample = np.unique(new_indices, return_index=True)[1]
else:
downsample = None
for start_idx in range(0, n_frames, 27):
keypoints_clip = keypoints[:, start_idx:start_idx + 243, ...]
clip_length = keypoints_clip.shape[1]
if clip_length != 243:
new_indices = resample(clip_length)
clips.append(keypoints_clip[:, new_indices, ...])
downsample = np.unique(new_indices, return_index=True)[1]
else:
clips.append(keypoints_clip)
if start_idx + 243 >= n_frames:
# Last clip is exactly 27 frames, no resampling needed
downsample = np.arange(243)
return clips, downsample

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions