Example #1
0
    def growing(self,
                mesh: MeshInference,
                start: int,
                end: int,
                num_frames: int,
                zero_places: NoiseT = ()) -> factory.Noise:

        export_name = f'{self.opt.cp_folder}/inference/{mesh.mesh_name}/scene00'

        start, end = self.trim(start, end)
        if len(zero_places) == 1:
            zero_places = zero_places * (end - start + 1)
        z = self.get_z_sequence(mesh, end - start)
        for i in range(min(len(z), len(zero_places))):
            if zero_places[i]:
                z[i] = 0
        deltas = self.generator.grow_forward(mesh.copy(), z, end, start)
        mesh.export(f'{export_name}/{0:02d}')
        for i in range(end - start + 1):
            base_vs, cur_delta = mesh.vs.clone(), deltas[i]
            for j in range(num_frames):
                mesh.vs = base_vs + cur_delta * (j + 1) / num_frames
                mesh.export(f'{export_name}/{(num_frames * i + j + 1):02d}')
                print(
                    f'done: {num_frames * i + j + 1}/{num_frames * (end - start + 1)}'
                )
            if i < end - start:
                mesh.upsample()
        return z
Example #2
0
    def grow_forward(self, m: MeshInference, z: List[Union[T, float]],
                     level: int, start_level: int) -> TS:
        def grow_level(z_, level_) -> T:
            nonlocal m
            features = m(z_, self.opt.noise_before)
            out = self.levels[level_](features, m.gfmm)
            m, displacement = m.grow_add(out)
            return displacement

        displacements: TS = []

        with torch.no_grad():
            for j, i in enumerate(range(start_level, level)):
                displacements.append(grow_level(z[j], i))
                m = m.upsample()
            displacements.append(grow_level(z[-1], level))
        return displacements