ndrplz / differentiable-renderer Goto Github PK
View Code? Open in Web Editor NEWRastering algorithm to approximate the rendering of a 3D model silhouette in a fully differentiable way.
License: MIT License
Rastering algorithm to approximate the rendering of a 3D model silhouette in a fully differentiable way.
License: MIT License
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.
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()
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.