Пример #1
0
    def save_generated_smpl(self, epoch, examples=3, render=True):
        """ Save generated SMPL parameters """
        if self.ex_data is None:
            self.ex_data = np.random.randn(examples, self._gen_dim)
        generated_params = self.generator.predict(self.ex_data)
        for i, params in enumerate(generated_params):
            np.save(
                "../gen_pose_params/gan_example.E{:03d}:{:02d}.npy".format(
                    epoch, i), params)

        if render:
            smpl = SMPLModel('../model.pkl')

            beta = np.zeros(shape=(10, ))
            trans = np.zeros(shape=(3, ))

            for i, pose_params in enumerate(generated_params):
                smpl.set_params(beta=beta, pose=pose_params, trans=trans)
                smpl.save_to_obj('../meshes/smpl_np.E{:03d}:{:02d}.obj'.format(
                    epoch, i))
    #not_trainable = []
    #trainable_params_indices = [index for index in range(85) if index not in not_trainable and index < 72]
    trainable_params_indices = [
        index for index in range(85)
        if index not in not_trainable and index < 66
    ]
    PARAMS_TO_OFFSET = [param_ids[index] for index in trainable_params_indices]
POSE_OFFSET = format_distractor_dict(POSE_OFFSET, PARAMS_TO_OFFSET)

# Generate the data from the SMPL parameters
smpl = SMPLModel(
    './keras_rotationnet_v2_demo_for_hidde/basicModel_f_lbs_10_207_0_v1.0.0.pkl'
)
zero_params = np.zeros(shape=(85, ))
zero_pc = smpl.set_params(beta=zero_params[72:82],
                          pose=zero_params[0:72].reshape((24, 3)),
                          trans=zero_params[82:85])
#print("zero_pc: " + str(zero_pc))

if USE_GENERATOR:
    update_generator = OptLearnerUpdateGenerator(data_samples,
                                                 RESET_PERIOD,
                                                 POSE_OFFSET,
                                                 PARAMS_TO_OFFSET,
                                                 batch_size=BATCH_SIZE,
                                                 smpl=smpl,
                                                 shuffle=True)
    X_data, Y_data = update_generator.yield_data()
    print("Y_data shapes: " + str([datum.shape for datum in Y_data]))
    X_indices = X_data[0]
    X_params = X_data[1]
Пример #3
0
DISTRACTOR = format_distractor_dict(DISTRACTOR, trainable_params)
if PARAMS_TO_OFFSET == "trainable_params":
    PARAMS_TO_OFFSET = trainable_params
elif PARAMS_TO_OFFSET == "all_pose_and_global_rotation":
    not_trainable = [0, 2]
    #not_trainable = []
    #trainable_params_indices = [index for index in range(85) if index not in not_trainable and index < 72]
    trainable_params_indices = [index for index in range(85) if index not in not_trainable and index < 66]
    PARAMS_TO_OFFSET = [param_ids[index] for index in trainable_params_indices]
POSE_OFFSET = format_distractor_dict(POSE_OFFSET, PARAMS_TO_OFFSET)

# Generate the data from the SMPL parameters
print("loading SMPL")
smpl = SMPLModel('./keras_rotationnet_v2_demo_for_hidde/basicModel_f_lbs_10_207_0_v1.0.0.pkl')
zero_params = np.zeros(shape=(85,))
zero_pc = smpl.set_params(beta=zero_params[72:82], pose=zero_params[0:72].reshape((24,3)), trans=zero_params[82:85])
#print("zero_pc: " + str(zero_pc))

# Generate and format the data
X_indices = np.array([i for i in range(data_samples)])
X_params = np.array([zero_params for i in range(data_samples)], dtype="float32")
if LOAD_DATA_DIR is not None:
    X_params, X_pcs = load_data(LOAD_DATA_DIR, num_samples=data_samples, load_silhouettes=False)
else:
    if not all(value == 0.0 for value in POSE_OFFSET.values()):
        num_test_samples = 5
        print("Offsetting parameters")
        X_params = offset_params(X_params, PARAMS_TO_OFFSET, POSE_OFFSET)
        X_params = X_params[:num_test_samples]
        print("X_params shape: " + str(X_params.shape))
        print("Rendering parameters")
#model = model_dir + "model.49-64.62.hdf5"
logs_dir = exp_dir + "logs/"
test_vis_dir = exp_dir + "test_vis/model.149-53.59.hdf5/"
control_dir = exp_dir + "/test_control_vis/"
if args.data is None:
    args.data = "../data/train/"

np.random.seed(10)

# Generate the data from the SMPL parameters
smpl = SMPLModel(
    './keras_rotationnet_v2_demo_for_hidde/basicModel_f_lbs_10_207_0_v1.0.0.pkl'
)
zero_params = np.zeros(shape=(85, ))
zero_pc = smpl.set_params(beta=zero_params[72:82],
                          pose=zero_params[0:72].reshape((24, 3)),
                          trans=zero_params[82:85])
#print("zero_pc: " + str(zero_pc))
base_params = 0.2 * (np.random.rand(85) - 0.5)
base_pc = smpl.set_params(beta=base_params[72:82],
                          pose=base_params[0:72].reshape((24, 3)),
                          trans=base_params[82:85])

data_samples = 1000
X_indices = np.array([i for i in range(data_samples)])
X_params = 0.2 * np.random.rand(data_samples, 85)
#X_params = np.array([zero_params for i in range(data_samples)], dtype="float64")
X_params[:, 59] = 2 * np.pi * (np.random.rand(data_samples) - 0.5)
#X_pcs = np.array([zero_pc for i in range(data_samples)], dtype="float64")
#X_params = np.array([base_params for i in range(data_samples)], dtype="float32")
#X_pcs = np.array([base_pc for i in range(data_samples)], dtype="float32")
Пример #5
0
class MainWindow(QMainWindow):
    def __init__(self, parent=None):
        super(MainWindow, self).__init__(parent=parent)
        # GUI
        self.ui = Ui_SmplViewer()
        self.ui.setupUi(self)

        # SMPL object
        self.smpl = SMPLModel('./smpl_data/male_model.pkl')

        # initialize the sliders
        self.poseSliders = []
        self.shapeSliders = []
        for item in self.ui.__dict__:
            if 'horizontalSlider' in item:
                self.poseSliders.append(self.ui.__dict__[item])
            if 'verticalSlider' in item:
                self.shapeSliders.append(self.ui.__dict__[item])

        # set events
        for i in range(len(self.poseSliders)):
            self.poseSliders[i].setMinimum(-8)
            self.poseSliders[i].setMaximum(8)
            self.poseSliders[i].valueChanged[int].connect(self.changevalue)

        for i in range(len(self.shapeSliders)):
            self.shapeSliders[i].setMinimum(0)
            self.shapeSliders[i].setMaximum(10)
            self.shapeSliders[i].valueChanged[int].connect(self.changevalue)

        self.ui.pushButton.clicked.connect(self.pushButton_Click)

    def loadScene(self):
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
        glMatrixMode(GL_PROJECTION)
        glLoadIdentity()
        x, y, width, height = glGetDoublev(GL_VIEWPORT)
        gluPerspective(
            45,  # field of view in degrees
            width / float(height or 1),  # aspect ratio
            .25,  # near clipping plane
            200,  # far clipping plane
        )

        glMatrixMode(GL_MODELVIEW)
        glLoadIdentity()

        gluLookAt(1.8, 1.8, 1.8, 0, 0, 0, 0, 1, 0)

    def paintGL(self):

        self.loadScene()
        for face in self.smpl.faces:
            glColor3f(1, 1, 0.4)
            glBegin(GL_TRIANGLES)
            x_0, y_0, z_0 = self.smpl.verts[face[0]]
            x_1, y_1, z_1 = self.smpl.verts[face[1]]
            x_2, y_2, z_2 = self.smpl.verts[face[2]]
            glVertex3f(x_0, y_0, z_0)
            glVertex3f(x_1, y_1, z_1)
            glVertex3f(x_2, y_2, z_2)
            glEnd()

        self.setupRC()

    def setupViewer(self):
        self.ui.openGLWidget.initializeGL()
        self.ui.openGLWidget.paintGL = self.paintGL
        timer = QTimer(self)
        timer.timeout.connect(self.ui.openGLWidget.update)
        timer.start(5)

    def setupRC(self):
        # Light values and coordinates
        ambientLight = [0.4, 0.4, 0.4, 1.0]
        diffuseLight = [0.7, 0.7, 0.7, 1.0]
        specular = [0.9, 0.9, 0.9, 1.0]
        lightPos = [-0.03, 0.15, 0.1, 1.0]
        specref = [0.6, 0.6, 0.6, 1.0]

        glEnable(GL_DEPTH_TEST)  # Hidden surface removal
        glEnable(GL_CULL_FACE)  # Do not calculate inside of solid object
        glFrontFace(GL_CCW)

        glEnable(GL_LIGHTING)

        # Setup light 0
        glLightModelfv(GL_LIGHT_MODEL_AMBIENT, ambientLight)
        glLightfv(GL_LIGHT0, GL_AMBIENT, ambientLight)
        glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuseLight)
        glLightfv(GL_LIGHT0, GL_SPECULAR, specular)

        # Position and turn on the light
        glLightfv(GL_LIGHT0, GL_POSITION, lightPos)
        glEnable(GL_LIGHT0)

        # Enable color tracking
        glEnable(GL_COLOR_MATERIAL)

        # Set Material properties to follow glColor values
        glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE)

        # All materials hereafter have full specular reflectivity with a moderate shine
        glMaterialfv(GL_FRONT, GL_SPECULAR, specref)
        glMateriali(GL_FRONT, GL_SHININESS, 64)

    def changevalue(self, value):
        pose_vals = []
        shape_vals = []
        for i in range(24):
            vector = np.zeros(3)
            vector[0] = 3 * self.poseSliders[3 * i + 0].value() / 8
            vector[1] = 3 * self.poseSliders[3 * i + 1].value() / 8
            vector[2] = 3 * self.poseSliders[3 * i + 2].value() / 8
            pose_vals.append(vector)

        for item in self.shapeSliders:
            shape_vals.append(item.value())

        pose_vals = np.array(pose_vals)
        shape_vals = np.array(shape_vals)
        trans_vals = np.zeros(3)
        self.smpl.set_params(pose=pose_vals, beta=shape_vals, trans=trans_vals)

    # save the model
    def pushButton_Click(self):
        mesh = trimesh.Trimesh(vertices=self.smpl.verts,
                               faces=self.smpl.faces,
                               process=False)
        output_path = self.ui.lineEdit.text()
        mesh.export(output_path)
        print('Saved to %s' % output_path)
Пример #6
0
epochs = params["MODEL"]["EPOCHS"]
steps_per_epoch = params["MODEL"]["STEPS_PER_EPOCH"]
validation_steps = params["MODEL"]["VALIDATION_STEPS"]
save_period = params["MODEL"]["SAVE_PERIOD"]
pred_period = params["MODEL"]["PRED_PERIOD"]
""" Data generation """

np.random.seed(10)

# Generate the data from the SMPL parameters
smpl = SMPLModel(
    './keras_rotationnet_v2_demo_for_hidde/basicModel_f_lbs_10_207_0_v1.0.0.pkl'
)
zero_params = np.zeros(shape=(85, ))
zero_pc = smpl.set_params(beta=zero_params[72:82],
                          pose=zero_params[0:72].reshape((24, 3)),
                          trans=zero_params[82:85])
#print("zero_pc: " + str(zero_pc))
base_params = 0.2 * (np.random.rand(85) - 0.5)
base_pc = smpl.set_params(beta=base_params[72:82],
                          pose=base_params[0:72].reshape((24, 3)),
                          trans=base_params[82:85])

data_samples = 1000
X_indices = np.array([i for i in range(data_samples)])
X_params = 0.2 * np.random.rand(data_samples, 85)
#X_params = np.array([zero_params for i in range(data_samples)], dtype="float64")
X_params[:, 1] = 2 * np.pi * (np.random.rand(data_samples) - 0.5)
#X_pcs = np.array([zero_pc for i in range(data_samples)], dtype="float64")
#X_params = np.array([base_params for i in range(data_samples)], dtype="float32")
#X_pcs = np.array([base_pc for i in range(data_samples)], dtype="float32")
Пример #7
0
from render_mesh import Mesh

# Generate the silhouettes from the SMPL parameters
smpl = SMPLModel(
    './keras_rotationnet_v2_demo_for_hidde/./basicModel_f_lbs_10_207_0_v1.0.0.pkl'
)

# Artificial sample data
sample_pose = 0.0 * (np.random.rand(smpl.pose_shape[0], smpl.pose_shape[1]) -
                     0.5)
sample_beta = 0.0 * (np.random.rand(smpl.beta_shape[0]) - 0.5)
sample_trans = np.zeros(smpl.trans_shape[0])
#sample_trans = 0.1 * (np.random.rand(smpl.trans_shape[0]) - 0.5)

sample_y = np.array([sample_pose.ravel(), sample_beta, sample_trans])
sample_pc = smpl.set_params(sample_pose, sample_beta, sample_trans)

#pc_subset = sample_pc[5020:5150]
#pc_subset = sample_pc[5400:5600]
#pc_subset = sample_pc[5020:5600]
#pc_subset = sample_pc[1850:2100]
pc_subset = sample_pc[[1850, 1600, 2050, 5350, 5050, 5500]]


def render_silhouette(pc,
                      dim=(256, 256),
                      morph_mask=None,
                      show=True,
                      title="silhouette"):
    """ Create a(n orthographic) silhouette out of a 2D slice of the pointcloud """
    x_sf = dim[0] - 1