Giter Site home page Giter Site logo

Comments (1)

plmsmile avatar plmsmile commented on September 3, 2024

I found the reason is that num_frames//4, num_frames//2. And I update two methods of edit_sequences.py then the problem disappear.

def alter_sequence_shape(source_path, out_path, flame_model_fname, pc_idx=0, pc_range=(0,3)):
    '''
    Load existing animation sequence in "zero pose" and change the identity dependent shape over time.
    :param source_path:         path of the animation sequence (files must be provided in OBJ file format)
    :param out_path:            output path of the altered sequence
    :param flame_model_fname:   path of the FLAME model
    :param pc_idx               Identity shape parameter to be varied in [0,300) as FLAME provides 300 shape paramters
    :param pc_range             Tuple (start/end, max/min) defining the range of the shape variation.
                                i.e. (0,3) varies the shape from 0 to 3 stdev and back to 0
    '''

    if pc_idx < 0 or pc_idx >= 300:
        print('shape parameter index out of range [0,300)')
        return

    if not os.path.exists(out_path):
        os.makedirs(out_path)

    # Load sequence files
    sequence_fnames = sorted(glob.glob(os.path.join(source_path, '*.obj')))
    num_frames = len(sequence_fnames)
    if num_frames == 0:
        print('No sequence meshes found')
        return

    # Load FLAME head model
    model = load_model(flame_model_fname)
    model_parms = np.zeros((num_frames, 300))

    # Generate interpolated shape parameters for each frame
    half_n = int(num_frames / 2)
    x1, y1 = [0, half_n], pc_range
    x2, y2 = [half_n, num_frames], pc_range[::-1]

    xsteps1 = np.arange(0, half_n)
    xsteps2 = np.arange(half_n, num_frames)

    model_parms[:, pc_idx] = np.hstack((np.interp(xsteps1, x1, y1), np.interp(xsteps2, x2, y2)))

    predicted_vertices = np.zeros((num_frames, model.v_template.shape[0], model.v_template.shape[1]))

    for frame_idx in range(num_frames):
        model.v_template[:] = Mesh(filename=sequence_fnames[frame_idx]).v
        model.betas[:300] = model_parms[frame_idx]
        predicted_vertices[frame_idx] = model.r

    output_sequence_meshes(predicted_vertices, Mesh(model.v_template, model.f), out_path)


def alter_sequence_head_pose(source_path, out_path, flame_model_fname, pose_idx=3, rot_angle=np.pi/6):
    '''
    Load existing animation sequence in "zero pose" and change the head pose (i.e. rotation around the neck) over time.
    :param source_path:         path of the animation sequence (files must be provided in OBJ file format)
    :param out_path:            output path of the altered sequence
    :param flame_model_fname:   path of the FLAME model
    :param pose_idx:            head pose parameter to be varied in [3,6)
    :param rot_angle:           maximum rotation angle in [0,2pi)
    '''

    if pose_idx < 3 or pose_idx >= 6:
        print('pose parameter index out of range [3,6)')
        return

    if not os.path.exists(out_path):
        os.makedirs(out_path)

    # Load sequence files
    sequence_fnames = sorted(glob.glob(os.path.join(source_path, '*.obj')))
    num_frames = len(sequence_fnames)
    if num_frames == 0:
        print('No sequence meshes found')
        return

    # Load FLAME head model
    model = load_model(flame_model_fname)
    model_parms = np.zeros((num_frames, model.pose.shape[0]))

    # Generate interpolated pose parameters for each frame
    num_4 = int(num_frames//4)
    num_2 = int(num_frames//2)
    x1, y1 = [0, num_4], [0, rot_angle]
    x2, y2 = [num_4, num_2], [rot_angle, 0]
    x3, y3 = [num_2, 3*num_4], [0, -rot_angle]
    x4, y4 = [3*num_4, num_frames], [-rot_angle, 0]

    xsteps1 = np.arange(0, num_4)
    xsteps2 = np.arange(num_4, num_2)
    xsteps3 = np.arange(num_2, 3*num_4)
    xsteps4 = np.arange(3*num_4, num_frames)

    model_parms[:, pose_idx] = np.hstack((np.interp(xsteps1, x1, y1),
                                   np.interp(xsteps2, x2, y2),
                                   np.interp(xsteps3, x3, y3),
                                   np.interp(xsteps4, x4, y4)))

    predicted_vertices = np.zeros((num_frames, model.v_template.shape[0], model.v_template.shape[1]))

    for frame_idx in range(num_frames):
        model.v_template[:] = Mesh(filename=sequence_fnames[frame_idx]).v
        model.pose[:] = model_parms[frame_idx]
        predicted_vertices[frame_idx] = model.r

    output_sequence_meshes(predicted_vertices, Mesh(model.v_template, model.f), out_path)

from voca.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.