How it is coded
The code is provided in the repository in the chap4
folder as diff_render.py
. The mesh model of the teapot is provided in the data
subfolder as teapot.obj
. We will run through the code as follows:
- The code in
diff_render.py
starts by importing the needed packages:import os import torch import numpy as np import torch.nn as nn import matplotlib.pyplot as plt from skimage import img_as_ubyte from pytorch3d.io import load_obj from pytorch3d.structures import Meshes from pytorch3d.renderer import ( FoVPerspectiveCameras, look_at_view_transform, look_at_rotation, RasterizationSettings, MeshRenderer, MeshRasterizer, BlendParams, SoftSilhouetteShader, HardPhongShader, PointLights, TexturesVertex, )
- In the next step, we declare a PyTorch device. If you have GPUs, then the device will be created to use GPUs. Otherwise, the device has to use CPUs:
if torch.cuda.is_available(): Â Â Â Â device = torch.device("cuda:0") else: Â Â Â ...