From 2cdf010bb957a2b236dbf15e4f440c817aecb765 Mon Sep 17 00:00:00 2001 From: haosenwang1018 Date: Wed, 25 Feb 2026 03:03:17 +0000 Subject: [PATCH] fix: replace 19 bare excepts with except Exception --- convert_3dgs.py | 2 +- gaussian_renderer/__init__.py | 4 ++-- metrics.py | 2 +- scene/dataset_readers.py | 28 ++++++++++++++-------------- train.py | 2 +- 5 files changed, 19 insertions(+), 19 deletions(-) diff --git a/convert_3dgs.py b/convert_3dgs.py index bbb1d2e..321d209 100755 --- a/convert_3dgs.py +++ b/convert_3dgs.py @@ -28,7 +28,7 @@ try: from fused_ssim import fused_ssim FUSED_SSIM_AVAILABLE = True -except: +except Exception: FUSED_SSIM_AVAILABLE = False def render_sets(dataset : ModelParams, opt : OptimizationParams, iteration : int, pipe : PipelineParams, pruning_ratio : float = 0.6): diff --git a/gaussian_renderer/__init__.py b/gaussian_renderer/__init__.py index a3e3708..0a52b8b 100755 --- a/gaussian_renderer/__init__.py +++ b/gaussian_renderer/__init__.py @@ -161,7 +161,7 @@ def render(viewpoint_camera, pc : GaussianModel, pipe, bg_color : torch.Tensor, if retain_grad: try: screenspace_points.retain_grad() - except: + except Exception: pass @@ -237,7 +237,7 @@ def render3dgs(viewpoint_camera, pc : GaussianModel, pipe, bg_color : torch.Tens screenspace_points = torch.zeros_like(pc.get_xyz, dtype=pc.get_xyz.dtype, requires_grad=True, device="cuda") + 0 try: screenspace_points.retain_grad() - except: + except Exception: pass # Set up rasterization configuration diff --git a/metrics.py b/metrics.py index ba85d85..0b029b6 100755 --- a/metrics.py +++ b/metrics.py @@ -96,7 +96,7 @@ def evaluate(model_paths): json.dump(full_dict[scene_dir], fp, indent=True) with open(scene_dir + "/per_view.json", 'w') as fp: json.dump(per_view_dict[scene_dir], fp, indent=True) - except: + except Exception: print("Unable to compute metrics for model", scene_dir) if __name__ == "__main__": diff --git a/scene/dataset_readers.py b/scene/dataset_readers.py index 84482b5..c187546 100755 --- a/scene/dataset_readers.py +++ b/scene/dataset_readers.py @@ -173,7 +173,7 @@ def fetchPly(path): positions = np.vstack([vertices['x'], vertices['y'], vertices['z']]).T try: colors = np.vstack([vertices['red'], vertices['green'], vertices['blue']]).T / 255.0 - except: + except Exception: colors = np.random.rand(positions.shape[0], positions.shape[1]) normals = np.vstack([vertices['nx'], vertices['ny'], vertices['nz']]).T return BasicPointCloud(points=positions, colors=colors, normals=normals) @@ -298,17 +298,17 @@ def readEvalSceneInfo(path, model_path, images, eval, llffhold=8): print("Converting point3d.bin to .ply, will happen only the first time you open the scene.") try: xyz, rgb, _ = read_points3D_binary(bin_path) - except: + except Exception: try: xyz, rgb, _ = read_points3D_text(txt_path) - except: + except Exception: print("Failed to load point cloud data") xyz, rgb = None, None if xyz is not None: storePly(ply_path, xyz, rgb) try: pcd = fetchPly(ply_path) - except: + except Exception: pcd = None else: print("Skipping point cloud loading as GT poses are not available") @@ -383,7 +383,7 @@ def readFreeSceneInfo(path, images, eval, llffhold=8): cameras_intrinsic_file = os.path.join(path, "sparse/0", "cameras.bin") cam_extrinsics = read_extrinsics_binary(cameras_extrinsic_file) cam_intrinsics = read_intrinsics_binary(cameras_intrinsic_file) - except: + except Exception: cameras_extrinsic_file = os.path.join(path, "sparse/0", "images.txt") cameras_intrinsic_file = os.path.join(path, "sparse/0", "cameras.txt") cam_extrinsics = read_extrinsics_text(cameras_extrinsic_file) @@ -411,7 +411,7 @@ def readFreeSceneInfo(path, images, eval, llffhold=8): print("Converting point3d.bin to .ply, will happen only the first time you open the scene.") try: xyz, rgb, _ = read_points3D_binary(bin_path) - except: + except Exception: xyz, rgb, _ = read_points3D_text(txt_path) storePly(ply_path, xyz, rgb) @@ -431,7 +431,7 @@ def readTanksSceneInfo(path, images, eval, llffhold=8): cameras_intrinsic_file = os.path.join(path, "sparse/0", "cameras.bin") cam_extrinsics = read_extrinsics_binary(cameras_extrinsic_file) cam_intrinsics = read_intrinsics_binary(cameras_intrinsic_file) - except: + except Exception: cameras_extrinsic_file = os.path.join(path, "sparse/0", "images.txt") cameras_intrinsic_file = os.path.join(path, "sparse/0", "cameras.txt") cam_extrinsics = read_extrinsics_text(cameras_extrinsic_file) @@ -463,7 +463,7 @@ def readTanksSceneInfo(path, images, eval, llffhold=8): print("Converting point3d.bin to .ply, will happen only the first time you open the scene.") try: xyz, rgb, _ = read_points3D_binary(bin_path) - except: + except Exception: xyz, rgb, _ = read_points3D_text(txt_path) storePly(ply_path, xyz, rgb) @@ -497,7 +497,7 @@ def readHikeSceneInfo(path, images, eval, llffhold=10): print("Converting point3d.bin to .ply, will happen only the first time you open the scene.") try: xyz, rgb, _ = read_points3D_binary(bin_path) - except: + except Exception: xyz, rgb, _ = read_points3D_text(txt_path) storePly(ply_path, xyz, rgb) @@ -523,14 +523,14 @@ def readCustomSceneInfo(path, images, eval, llffhold=8): cam_extrinsics = read_extrinsics_binary(cameras_extrinsic_file) cam_intrinsics = read_intrinsics_binary(cameras_intrinsic_file) has_camera_data = True - except: + except Exception: try: cameras_extrinsic_file = os.path.join(path, "sparse/0", "images.txt") cameras_intrinsic_file = os.path.join(path, "sparse/0", "cameras.txt") cam_extrinsics = read_extrinsics_text(cameras_extrinsic_file) cam_intrinsics = read_intrinsics_text(cameras_intrinsic_file) has_camera_data = True - except: + except Exception: print("No valid camera data found in sparse folder, proceeding without camera poses") has_camera_data = False @@ -567,18 +567,18 @@ def readCustomSceneInfo(path, images, eval, llffhold=8): try: xyz, rgb, _ = read_points3D_binary(bin_path) storePly(ply_path, xyz, rgb) - except: + except Exception: try: xyz, rgb, _ = read_points3D_text(txt_path) storePly(ply_path, xyz, rgb) - except: + except Exception: print("No valid point cloud data found, proceeding without point cloud") ply_path = None if ply_path and os.path.exists(ply_path): try: pcd = fetchPly(ply_path) - except: + except Exception: print("Failed to load point cloud from PLY file") pcd = None ply_path = None diff --git a/train.py b/train.py index 59f3e3c..fda1f24 100755 --- a/train.py +++ b/train.py @@ -49,7 +49,7 @@ from fused_ssim import fused_ssim FUSED_SSIM_AVAILABLE = True print("fused ssim available") -except: +except Exception: FUSED_SSIM_AVAILABLE = False print("fused ssim not available")