Coder Social home page Coder Social logo

ndrplz / differentiable-renderer Goto Github PK

View Code? Open in Web Editor NEW
78.0 5.0 11.0 7.29 MB

Rastering algorithm to approximate the rendering of a 3D model silhouette in a fully differentiable way.

License: MIT License

Python 100.00%
differentiable-rendering rendering rendering-engine tensorflow tensorflow-models eccv-2018 python pytorch

differentiable-renderer's People

Contributors

ndrplz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

differentiable-renderer's Issues

how to set the camera parameters

Hi, thanks for your demo code.
I may wonder How can I set the camera parameters. I have a set of camera parameters:
rotation matrix: 3x3
translatioin: 3x1
focal_length: fx, fy
center_point: cx, cy
I can successfully project my 3D vetices to 2D plane using the paramters list above.
But I don't know how to use your renderer with these paramters, what does resolution_px, resolution_mm mean in your code, I can not get desired result if I only set the rotation and translation matrix (4x4) using my camera parameters.

Rendering a simple square

I was trying to render a simple square on grid of 5 x 5. I harcoded the coordinates of the two triangles in my square. But I am getting a output of all zeros. My aim is to actually render a mask given vertex coordinates in 2D and differentiably. Here is the code I am trying to run for rendering small square. What is wrong with this procedure?

import glob

import matplotlib.pyplot as plt
import numpy as np
import torch

from rastering import Rasterer
from rastering import RotoTranslation
from rastering import Vector


if __name__ == '__main__':
    device = 'cpu'
    if device not in ['cpu', 'cuda']:
        raise ValueError('Unknown device.')

    camera_pose = RotoTranslation(rotation=Vector(x=0., y=0., z=0.),
                                  translation=Vector(x=0., y=0., z=0.),
                                  angle_unit='degrees')
    print(camera_pose, '\n')

    # Toy dataset containing 5 random car meshes from Shapenetcore.
    mesh_dataset = [np.load(mesh_path) for mesh_path in glob.glob('data/*/*.npy')]

    print(mesh_dataset[0][:5])
    print([m.max() for m in mesh_dataset])
   

    mesh = np.array([[[0, 0, 0], [0, 1, 0], [1, 1, 0]],
             [[0, 0, 0], [1, 1, 0], [1, 0, 0]]]).astype(np.float32)

    print(mesh.shape, 'MESH')

    camera_intrinsics = {'resolution_px': (5, 5), 'diagonal_mm': 35, 'focal_len_mm': 30}
    renderer = Rasterer(meshes=[mesh], max_triangles=100, **camera_intrinsics)
    renderer.to(device)

    # Sample a bunch of models from the mesh dataset. There will be rendered in the same batch.
    n_mesh_to_render = 1
    #model_idxs = np.random.choice(np.arange(len(mesh_dataset)), size=n_mesh_to_render)
    model_idxs = np.array([0])

    # Load camera pose. In this case it is the same for all renderings.
    camera_matrix = camera_pose.matrix
    camera_matrices = np.tile(camera_matrix[None, ...], [n_mesh_to_render, 1, 1])

    render_output = renderer(torch.from_numpy(model_idxs).to(device),
                             torch.from_numpy(camera_matrices).to(device))

    for b in range(n_mesh_to_render):
        print(render_output)
        print(render_output[0].shape, 'OUTPUT SHAPE')
        plt.imshow(render_output[b].to('cpu').numpy(), cmap='gray')
        plt.waitforbuttonpress()

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.