BachiLi / redner

Differentiable rendering without approximation.

Home Page:https://people.csail.mit.edu/tzumao/diffrt/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Cuda out of memory in medium resolution image rendering

Skorkmaz88 opened this issue · comments

System is RTX 2070 , 6GB GPU Ram, Windows 10 -64 bit, Pytorch 1.5 , there are not so many vertices in the scene either.


import numpy as np
import matplotlib.pyplot as plt
from scipy import ndimage as ndi
import torch
import pyredner
import torch.optim as optim
import numpy as np
import matplotlib.pyplot as plt
import skimage 
from matplotlib.pyplot import imshow
from skimage import feature
from skimage import data, segmentation, color, filters, io
import pickle

rect_size = 32 * 1
step_size = 1
total_points_in_dim_x = rect_size + 1 
total_points_in_dim_y = rect_size

vertices = torch.tensor([])
indices = torch.tensor([] , dtype = torch.int32)
normals =  torch.tensor([])

for j in range(total_points_in_dim_y):
    for i in range(total_points_in_dim_x):
        vertices = torch.cat((vertices, torch.tensor([[i / 1.0, j / 1.0, 0.0]]) ))
        normals = torch.cat((normals, torch.tensor([[0.0, 0.0, -1.0]])))

        
for j in range(total_points_in_dim_y - 2 ):
    for i in range(total_points_in_dim_x - 1):
    
        grid_y_0 = j  * total_points_in_dim_x
        grid_y_1 = 0
        grid_y_2 = (j  + 1) *  total_points_in_dim_x
        grid_y_3 = 0
        grid_y_4 = j * total_points_in_dim_x
        if j > 0:
            grid_y_0 = j  * total_points_in_dim_x
            grid_y_1 = (j + 1)  *  total_points_in_dim_x -1
            #grid_y_2 = j * 2 - 1
            grid_y_3 = j * total_points_in_dim_x
    
        
        indices = torch.cat((indices, torch.tensor([[ grid_y_0  + i ,  
                                                      grid_y_0  + i + 1,
                                                     i  + grid_y_2]], 
                                                   dtype = torch.int32)))
        
        indices = torch.cat((indices, torch.tensor([[i  + grid_y_2 ,
                                                      grid_y_0  + i + 1,
                                                     i  + grid_y_2 + 1]],
                                                dtype = torch.int32)))

        
normals = abs(pyredner.compute_vertex_normal(vertices, indices)) * -1.0
m = pyredner.Material()


#uvs = pyredner.compute_uvs(vertices, indices)
#normals = pyredner.compute_vertex_normal(vertices,indices)
obj = pyredner.Object(vertices = vertices,
                                      indices = indices,
                                      normals = normals,
                                      material = m)

cam = pyredner.automatic_camera_placement([obj], resolution = (1280,1280))
light = pyredner.generate_quad_light(position = cam.position,
                                     look_at = torch.zeros(3),
                                     size = torch.tensor([0.9, 0.9]),
                                     intensity = torch.tensor([36000.0, 36000.0, 36000.0]))
scene = pyredner.Scene(objects = [obj, light], camera = cam)
img = pyredner.render_pathtracing(scene, seed=1)
imshow(img.cpu())