GithubHelp home page GithubHelp logo

Comments (2)

shivamsaboo17 avatar shivamsaboo17 commented on July 22, 2024

I tried to just run a forward pass like this to render a simple square. But I am getting segmentation fault. I am trying with 2d images hence I used z coordinate as 0 in vertices.

"""
Example 2. Optimizing vertices.
"""
from __future__ import division
import os
import argparse
import glob

import torch
import torch.nn as nn
import numpy as np
from skimage.io import imread, imsave
import tqdm
import imageio

import neural_renderer as nr

current_dir = os.path.dirname(os.path.realpath(__file__))
data_dir = os.path.join(current_dir, 'data')

class Model(nn.Module):
    def __init__(self):
        super(Model, self).__init__()

        # load .obj
        #vertices, faces = nr.load_obj(filename_obj)
        vertices = torch.from_numpy(np.array([[0, 0, 0], [0, 1, 0], [1, 0, 0], [1, 1, 0]]).reshape(4, 3).astype(np.float32)).float()
        faces = torch.from_numpy(np.array([[0, 1, 2], [0, 2, 3]]).reshape(2, 3).astype(np.int64)).int()
        self.vertices = nn.Parameter(vertices[None, :, :])
        self.register_buffer('faces', faces[None, :, :])
        texture_size = 2
        textures = torch.ones(1, self.faces.shape[1], texture_size, texture_size, texture_size, 3, dtype=torch.float32)
        self.register_buffer('textures', textures)
        print(self.vertices.shape)
        print(self.faces.shape)

        # create textures
        #texture_size = 2
        #textures = torch.ones(1, self.faces.shape[1], texture_size, texture_size, texture_size, 3, dtype=torch.float32)
        #self.register_buffer('textures', textures)

        # load reference image
        #image_ref = torch.from_numpy(imread(filename_ref).astype(np.float32).mean(-1) / 255.)[None, ::]
        #self.register_buffer('image_ref', image_ref)

        # setup renderer
        renderer = nr.Renderer(camera_mode='look_at')
        self.renderer = renderer

    def forward(self):
        self.renderer.eye = nr.get_points_from_angles(0, 0, 0)
        image = self.renderer(self.vertices, self.faces, textures=self.textures, mode=None)
        #loss = torch.sum((image - self.image_ref[None, :, :])**2)
        return image

model = Model().cuda()
img = model()
print(img.shape)

from neural_renderer.

emlcpfx avatar emlcpfx commented on July 22, 2024

@shivamsaboo17 were you trying to render a UV pass like this? Did you figure it out?

image

from neural_renderer.

Related Issues (20)

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.