Skip to content

Difference between SoftRas and Pytorch3d textured output #19

@aluo-x

Description

@aluo-x

To preface, it is very likely that I am doing something wrong, as I didn't closely look at the blending code in Pytorch3d. Would appreciate any advice on this particular topic.

Was comparing the silhouette and color output between SoftRas and Pytorch3d. The silhouette is very very similar, with a few pixels difference, perhaps due to some kind of rounding or offset issue.

But the textured (color) output is very different with black artifacts.

Links to mask & color output:
Imgur link

Minimum replication code for SoftRas:

import matplotlib.pyplot as plt
import os
import numpy as np
import imageio
import soft_renderer as sr
current_dir = "/home/aluo/tools/SoftRas/examples"
data_dir = os.path.join(current_dir, '../data')
import matplotlib.pyplot as plt
class args_obj():
    filename_input = os.path.join(data_dir, 'obj/spot/spot_triangulated.obj')
    output_dir = os.path.join(data_dir, 'results/output_render')
def main():
    args = args_obj()
    mesh = sr.Mesh.from_obj(args.filename_input, load_texture=True, texture_res=5, 
texture_type='surface')
    renderer = sr.SoftRenderer(camera_mode='look_at')
    os.makedirs(args.output_dir, exist_ok=True)
    renderer.transform.set_eyes_from_angles(2.7, 10, 20)
    mesh.reset_()
    gamma_pow = -3
    renderer.set_gamma(10**gamma_pow)
    renderer.set_sigma(10**(gamma_pow-1))
    images = renderer.render_mesh(mesh)
    image = images.detach().cpu().numpy()[0].transpose((1, 2, 0))
    plt.figure(figsize=(10, 10))
    plt.grid("off")
    plt.axis("off")
    plt.imshow(image[:,:,:3])
    plt.show()
    plt.figure(figsize=(10, 10))
    plt.grid("off")
    plt.axis("off")
    plt.imshow(image[:,:,-1])
    plt.show()
main()

For Pytorch3d (following the render_textured_meshes notebook)

blend_params = BlendParams(sigma=1e-4, gamma=1e-4)
raster_settings = RasterizationSettings(
    image_size=256, 
    blur_radius=np.log(1. / 1e-4 - 1.) * blend_params.sigma, 
    faces_per_pixel=100, 
    bin_size=0
)
renderer = MeshRenderer(
    rasterizer=MeshRasterizer(
        cameras=cameras, 
        raster_settings=raster_settings
    ),
    shader=TexturedPhongShader(
        device=device, 
        cameras=cameras,
        lights=lights
    )
)

images = renderer(mesh)
plt.figure(figsize=(10, 10))
plt.imshow(images[0, ..., :3].cpu().numpy())
plt.grid("off")
plt.axis("off")

plt.figure(figsize=(10, 10))
plt.imshow(images[0, ..., -1].cpu().numpy())
plt.grid("off")
plt.axis("off")

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions