yifita / DSS

Differentiable Surface Splatting
438 stars 31 forks source link

Several errors #12

Closed chx125ck closed 2 years ago

chx125ck commented 2 years ago

When running python scripts/create_mvr_data_from_mesh.py --points example_data/mesh/yoga6.ply --output example_data/images --num_cameras 128 --image-size 512 --tri_color_light --point_lights --has_specular, the following error pops up. Traceback (most recent call last): File "scripts/create_mvr_data_from_mesh.py", line 190, in for c_idx, cams in tqdm(camera_sampler): ValueError: too many values to unpack (expected 2)

The error above was fixed by removing c_idx, then the following error pops up.

Traceback (most recent call last): File "scripts/create_mvr_data_from_mesh.py", line 206, in images = renderer.shader( File "/home/chx/anaconda3/envs/pytorch3d/lib/python3.8/site-packages/torch/nn/modules/module.py", line 722, in _call_impl result = self.forward(*input, **kwargs) File "/home/chx/anaconda3/envs/pytorch3d/lib/python3.8/site-packages/pytorch3d/renderer/mesh/shader.py", line 377, in forward images = hard_rgb_blend(colors, fragments, blend_params) File "/home/chx/anaconda3/envs/pytorch3d/lib/python3.8/site-packages/pytorch3d/renderer/blending.py", line 77, in hard_rgb_blend return torch.cat([pixel_colors, alpha], dim=-1) # (N, H, W, 4) RuntimeError: Tensors must have same number of dimensions: got 4 and 5

The error was caused by the ambient color of the light created by get_tri_color_lights_for_view in common.py having one more dimension and can be solved by reducing one dimension of the ambient color.

When running python train_mvr.py --config configs/dss.yml, the error pops up in the log ERROR - Could not plot gradient: TypeError("transform_points_screen() got multiple values for argument 'eps'"). The error is fixed by replacing pts_ndc = _cams.transform_points_screen(pts_world.view( 1, -1, 3), ((W, H),), eps=1e-17).view(-1, 3)[..., :2] pts_grad_ndc = _cams.transform_points_screen( (pts_world + pts_world_grad).view(1, -1, 3), ((W, H),), eps=1e-8).view(-1, 3)[..., :2] at line 531 in trainer.py with pts_ndc = _cams.transform_points_screen(pts_world.view( 1, -1, 3), eps=1e-17, image_size=((W, H),)).view(-1, 3)[..., :2] pts_grad_ndc = _cams.transform_points_screen( (pts_world + pts_world_grad).view(1, -1, 3), eps=1e-8, image_size=((W, H),)).view(-1, 3)[..., :2]

Then the following error appears, Traceback (most recent call last): File "train_mvr.py", line 199, in eval_dict = trainer.evaluate_3d( File "/home/chx/Forest/DSS/DSS/training/trainer.py", line 167, in evaluate_3d if not pointcloud.is_empty: AttributeError: 'PointClouds3D' object has no attribute 'is_empty'

and after defining is_empty for PointClouds3D in cloud.py, Traceback (most recent call last): File "train_mvr.py", line 199, in eval_dict = trainer.evaluate_3d( File "/home/chx/Forest/DSS/DSS/training/trainer.py", line 169, in evaluate_3d np.array(pointcloud.vertices)[None, ...], global_step=it) AttributeError: 'PointClouds3D' object has no attribute 'vertices' which I solved by defining vertices to be "points" that is passed into the constructor of PointCloud3D and I am unsure whether that is correct.

After fixing the errors above, the following error appears, Traceback (most recent call last): File "train_mvr.py", line 205, in metric_val = eval_dict[model_selection_metric] KeyError: 'chamfer'

I printed out eval_dict {'chamfer_point': 0.027734989300370216, 'chamfer_normal': 0.5018584728240967} and I am not sure how to fix this.

lxxue commented 2 years ago

Hi, I just tried the example out and I didn't encounter the error except for the first one (c_idx). Since the second error is from pytorch3d, I guess this might be a pytorch3d version problem. I am using pytorch3d 0.2.5 and maybe you can try that out?

chx125ck commented 2 years ago

Yes, regarding the second error, I was using pytorch3d 0.5.0 and changing to 0.2.5 solves the problem.

Any ideas on the other errors?

lxxue commented 2 years ago

Hi, sorry for the late reply. I didn't encounter the error ERROR - Could not plot gradient: TypeError("transform_points_screen() got multiple values for argument 'eps'"). so I thought all other errors will be fixed by changing the version of pytorch3d.

I check the environment.yml file and I believe pytorch3d 0.4.0 would be the version Yifan was using. But mine 0.2.5 seems to work as well.

For the error AttributeError: 'PointClouds3D' object has no attribute 'is_empty', I would suggest changing is_empty to isempty() as per pytorch3d doc.

For the error AttributeError: 'PointClouds3D' object has no attribute 'vertices', I would suggest changing np.array(pointcloud.vertices)[None, ...] to pointcloud.points_padded() as per pytorch3d doc and tensorboard doc.

For the last error, I modify the model_selection_metric in default.yaml to chamfer_point and change the code in line 198 from

            if model_selection_metric == 'chamfer':

to

            if 'chamfer' in model_selection_metric:

The results look good to me. I will double check these modifications and push the fixes afterwards. Thanks for pointing these out!

chx125ck commented 2 years ago

Thank you

chx125ck commented 2 years ago

I also find several errors when running without -- tri_color_light, Traceback (most recent call last): File "scripts/create_mvr_data_from_mesh.py", line 199, in lights = get_light_for_view(cams, point_lights=opt.point_lights, has_specular=opt.has_specular) TypeError: get_light_for_view() got an unexpected keyword argument 'point_lights' which is caused by the fact that get_light_for_view only takes cams and has_specular as input (while point_lights is actually used in the function)

and

Traceback (most recent call last): File "scripts/create_mvr_data_from_mesh.py", line 199, in lights = get_light_for_view(cams, point_lights=opt.point_lights, has_specular=opt.has_specular) File "/home/chx/Forest/DSS/common.py", line 95, in get_light_for_view if opt.has_specular: NameError: name 'opt' is not defined which can be fixed by simply removing the opt.

and

Traceback (most recent call last): File "scripts/create_mvr_data_from_mesh.py", line 199, in lights = get_light_for_view(cams, point_lights=opt.point_lights, has_specular=opt.has_specular) File "/home/chx/Forest/DSS/common.py", line 103, in get_light_for_view elev = math.pi / 180.0 * elev NameError: name 'math' is not defined because get_light_for_view function does not have the import statements at the beginning of get_tri_color_lights_for_view.

and

Traceback (most recent call last): File "scripts/create_mvr_data_from_mesh.py", line 199, in lights = get_light_for_view(cams, point_lights=opt.point_lights, has_specular=opt.has_specular) File "/home/chx/Forest/DSS/common.py", line 112, in get_light_for_view light_directions = cams.get_world_to_view_transform().inverse().transform_points(light_directions) File "/home/chx/Forest/pytorch3d-0.2.5/pytorch3d/transforms/transform3d.py", line 313, in transform_points points_out = _broadcast_bmm(points_batch, composed_matrix) File "/home/chx/Forest/pytorch3d-0.2.5/pytorch3d/transforms/transform3d.py", line 681, in _broadcast_bmm return a.bmm(b) RuntimeError: Expected object of device type cuda but got device type cpu for argument #0 'result' in call to _th_bmm_out which I fixed by replacing elev = torch.FloatTensor(((random.randint(10, 90),),)) azim = torch.FloatTensor(((random.randint(0, 360)),)) with elev = torch.tensor(((30, 30, 30),),device=cams.device) azim = torch.tensor(((-60, 60, 180),),device=cams.device)

lxxue commented 2 years ago

Thanks for these! Sorry our code is little bit messy as we were merging it from our dev version. Will fix these bugs when my GPU is idle :)