| 21 | from utils.data_utils import CameraDataset |
| 22 | |
| 23 | class Scene: |
| 24 | |
| 25 | gaussians : GaussianModel |
| 26 | |
| 27 | def __init__(self, args : ModelParams, gaussians : GaussianModel, load_iteration=None, shuffle=True, resolution_scales=[1.0], num_pts=100_000, num_pts_ratio=1.0, time_duration=None): |
| 28 | """b |
| 29 | :param path: Path to colmap scene main folder. |
| 30 | """ |
| 31 | self.model_path = args.model_path |
| 32 | self.loaded_iter = None |
| 33 | self.gaussians = gaussians |
| 34 | self.white_background = args.white_background |
| 35 | |
| 36 | if load_iteration: |
| 37 | if load_iteration == -1: |
| 38 | self.loaded_iter = searchForMaxIteration(os.path.join(self.model_path, "point_cloud")) |
| 39 | else: |
| 40 | self.loaded_iter = load_iteration |
| 41 | print("Loading trained model at iteration {}".format(self.loaded_iter)) |
| 42 | |
| 43 | self.train_cameras = {} |
| 44 | self.test_cameras = {} |
| 45 | |
| 46 | # if os.path.exists(os.path.join(args.source_path, "sparse")): |
| 47 | # scene_info = sceneLoadTypeCallbacks["Colmap"](args.source_path, args.images, args.eval, num_pts_ratio=num_pts_ratio) |
| 48 | # elif os.path.exists(os.path.join(args.source_path, "transforms_train.json")): |
| 49 | # print("Found transforms_train.json file, assuming Blender data set!") |
| 50 | # scene_info = sceneLoadTypeCallbacks["Blender"](args.source_path, args.white_background, args.eval, num_pts=num_pts, time_duration=time_duration, extension=args.extension, num_extra_pts=args.num_extra_pts, frame_ratio=args.frame_ratio, dataloader=args.dataloader) |
| 51 | # else: |
| 52 | # assert False, "Could not recognize scene type!" |
| 53 | scene_info = sceneLoadTypeCallbacks["Blender"](args.source_path, args.white_background, args.eval, num_pts=num_pts, time_duration=time_duration, extension=args.extension, num_extra_pts=args.num_extra_pts, frame_ratio=args.frame_ratio, dataloader=args.dataloader) |
| 54 | |
| 55 | if not self.loaded_iter: |
| 56 | with open(scene_info.ply_path, 'rb') as src_file, open(os.path.join(self.model_path, "input.ply") , 'wb') as dest_file: |
| 57 | dest_file.write(src_file.read()) |
| 58 | json_cams = [] |
| 59 | camlist = [] |
| 60 | if scene_info.test_cameras: |
| 61 | camlist.extend(scene_info.test_cameras) |
| 62 | if scene_info.train_cameras: |
| 63 | camlist.extend(scene_info.train_cameras) |
| 64 | for id, cam in enumerate(camlist): |
| 65 | json_cams.append(camera_to_JSON(id, cam)) |
| 66 | with open(os.path.join(self.model_path, "cameras.json"), 'w') as file: |
| 67 | json.dump(json_cams, file) |
| 68 | |
| 69 | if shuffle: |
| 70 | random.shuffle(scene_info.train_cameras) # Multi-res consistent random shuffling |
| 71 | random.shuffle(scene_info.test_cameras) # Multi-res consistent random shuffling |
| 72 | |
| 73 | self.cameras_extent = scene_info.nerf_normalization["radius"] |
| 74 | |
| 75 | for resolution_scale in resolution_scales: |
| 76 | print("Loading Training Cameras") |
| 77 | self.train_cameras[resolution_scale] = cameraList_from_camInfos(scene_info.train_cameras, resolution_scale, args) |
| 78 | print("Loading Test Cameras") |
| 79 | self.test_cameras[resolution_scale] = cameraList_from_camInfos(scene_info.test_cameras, resolution_scale, args) |
| 80 |
no outgoing calls
no test coverage detected