yfeng95 / face3d

Python tools for 3D face: 3DMM, Mesh processing(transform, camera, light, render), 3D face representations.
2.65k stars 611 forks source link

Not enough randomness in the shape of faces #15

Open yueqiw opened 5 years ago

yueqiw commented 5 years ago

Hi,

Great repo, very helpful! One issue I had when generating random faces is that the shapes of random faces are very similar to each other. It'd be great if we can get more diverse faces.

The faces become more diverse after I made the following changes. Basically, I use shape_para * self.model['shapeEV'] rather than shape_para alone in calculating the axis. This is adapted from the Matlab code in the BFM model. (This change somehow breaks the fitting process, though.)

    def get_shape_para(self, type = 'random'):
        if type == 'zero':
            sp = np.zeros((self.n_shape_para, 1))
        elif type == 'random':
            sp = np.random.randn(self.n_shape_para, 1)   # normally distributed random numbers
        return sp

    def generate_vertices(self, shape_para, exp_para):

        vertices = self.model['shapeMU'] + \
                    self.model['shapePC'].dot(shape_para * self.model['shapeEV']) + \
                    self.model['expPC'].dot(exp_para)
        vertices = np.reshape(vertices, [int(3), int(len(vertices)/3)], 'F').T
        return vertices
xinwen-cs commented 5 years ago

Hi, Have you solve it? I cannot generate face with enough distinction too. They look nearly the same.

yueqiw commented 5 years ago

@xinwen-cs The above solution helped to some extent. You can look at the Matlab code from the BFM model to understand how the calculation works.