simple code where an object of class "Meshes" is extended from 1 to a batch size > 1 via meshes.extend(N) causes:
File "/[...]/env/lib/python3.6/site-packages/pytorch3d/structures/utils.py", line 194, in padded_to_packed
x_packed = x.view(-1, D) # flatten padded
RuntimeError: view size is not compatible with input tensor's size and stride (at least one dimension spans across two contiguous subspaces). Use .reshape(...) instead.
code to replicate:
import torch
from pytorch3d.renderer import OpenGLPerspectiveCameras, BlendParams, \
RasterizationSettings, MeshRasterizer, MeshRenderer, TexturedSoftPhongShader, DirectionalLights
import numpy as np
from pytorch3d.io import load_objs_as_meshes
device = torch.device("cuda:0")
meshes = load_objs_as_meshes(["./models/cow_mesh/cow.obj"]).to(device)
meshes = meshes.extend(2)
cameras = OpenGLPerspectiveCameras(device=device)
blend_params = BlendParams(sigma=1e-4, gamma=1e-4, background_color=(0., 0., 0.))
raster_settings = RasterizationSettings(
blur_radius=np.log(1. / 1e-4 - 1.) * blend_params.sigma,
faces_per_pixel=100
)
lights = DirectionalLights(device=device)
renderer = MeshRenderer(
rasterizer=MeshRasterizer(
cameras=cameras, raster_settings=raster_settings
),
shader=TexturedSoftPhongShader(blend_params=blend_params, lights=lights)
)
images = renderer(meshes_world=meshes)
in other versions of my own code i get the error somewhere else, e.g.:
./renderer/mesh/texturing.py", line 56, in interpolate_texture_map
pixel_uvs = pixel_uvs.permute(0, 3, 1, 2, 4).view(N * K, H_out, W_out, 2)
This is likely due to the noncontiguity of the tensor. Try reshape instead as suggested by the RuntimeError message.
I can certainly change it in my version. However doesn't it sound like a bug that will occur often for many users?
Absolutely! This was just intended to unblock you!
I fixed the issues you report above with https://github.com/facebookresearch/pytorch3d/commit/6c48ff6ad9005cfc03704c77531a4a25d1c8d843. If you find similar issues please report them or even add a PR that fixes them if you prefer! Thank you again for reporting this :)
Absolutely! This was just intended to unblock you!
many thanks for the fix!
Most helpful comment
I can certainly change it in my version. However doesn't it sound like a bug that will occur often for many users?