Ejemplo n.º 1
0
    def set_look_at_parameters(self, azimuth, elevation, distance):

        camera_projection_mtx = perspectiveprojectionnp(self.camera_fov_y, 1.0)
        camera_projection_mtx = torch.FloatTensor(camera_projection_mtx).cuda()

        camera_view_mtx = []
        camera_view_shift = []
        for a, e, d in zip(azimuth, elevation, distance):
            mat, pos = compute_camera_params(a, e, d)
            camera_view_mtx.append(mat)
            camera_view_shift.append(pos)
        camera_view_mtx = torch.stack(camera_view_mtx).cuda()
        camera_view_shift = torch.stack(camera_view_shift).cuda()

        self.camera_params = [
            camera_view_mtx, camera_view_shift, camera_projection_mtx
        ]
Ejemplo n.º 2
0
    coef = 5
    p = p * coef

    ##########################################################
    campos = np.array([0, 0, 1.5], dtype=np.float32)  # where camera it is
    camcenter = np.array([0, 0, 0],
                         dtype=np.float32)  # where camra is looking at
    camup = np.array([-1, 1, 0], dtype=np.float32)  # y axis of camera view
    camviewmtx, camviewshift = lookatnp(campos.reshape(3, 1),
                                        camcenter.reshape(3, 1),
                                        camup.reshape(3, 1))
    camviewshift = -np.dot(camviewmtx.transpose(), camviewshift)

    camfovy = 45 / 180.0 * np.pi
    camprojmtx = perspectiveprojectionnp(camfovy, 1.0 * 1.0 / 1.0)

    #####################################################
    tfp_px3 = torch.from_numpy(p)
    tfp_px3.requires_grad = True

    tff_fx3 = torch.from_numpy(f)

    tfuv_tx2 = torch.from_numpy(uv)
    tfuv_tx2.requires_grad = True
    tfft_fx3 = torch.from_numpy(ft)

    tftex_thxtwx3 = torch.from_numpy(np.ascontiguousarray(texturenp))
    tftex_thxtwx3.requires_grad = True

    tfcamviewmtx = torch.from_numpy(camviewmtx)
Ejemplo n.º 3
0
images_set_valid = kal.dataloader.ShapeNet.Images(root ='../../datasets/',categories =args.categories , \
 download = True, train = False,  split = .7, views=1, transform= preprocess )
dataloader_val = DataLoader(images_set_valid,
                            batch_size=args.batchsize,
                            shuffle=False,
                            num_workers=8)
"""
Model settings 
"""
mesh = kal.rep.TriangleMesh.from_obj('386.obj', enable_adjacency=True)
mesh.cuda()
normalize_adj(mesh)

initial_verts = mesh.vertices.clone()
camera_fov_y = 49.13434207744484 * np.pi / 180.0
cam_proj = perspectiveprojectionnp(camera_fov_y, 1.0)
cam_proj = torch.FloatTensor(cam_proj).cuda()

model = Encoder(4, 5, args.batchsize, 137, mesh.vertices.shape[0]).cuda()

optimizer = optim.Adam(model.parameters(), lr=args.lr)
renderer = Dib_Renderer(137, 137, mode='VertexColor')

# Create log directory, if it doesn't already exist
args.logdir = os.path.join(args.logdir, args.expid)
if not os.path.isdir(args.logdir):
    os.makedirs(args.logdir)
    print('Created dir:', args.logdir)

# Log all commandline args
with open(os.path.join(args.logdir, 'args.txt'), 'w') as f: