From 0955231a06b3b09d5f31557627ff9735523becaa Mon Sep 17 00:00:00 2001 From: Jonas Kulhanek Date: Wed, 11 Oct 2023 09:48:25 +0200 Subject: [PATCH] Prevent image files to be open --- metrics.py | 2 ++ scene/dataset_readers.py | 9 +++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/metrics.py b/metrics.py index f7393a4..6d3de14 100644 --- a/metrics.py +++ b/metrics.py @@ -31,6 +31,8 @@ def readImages(renders_dir, gt_dir): renders.append(tf.to_tensor(render).unsqueeze(0)[:, :3, :, :].cuda()) gts.append(tf.to_tensor(gt).unsqueeze(0)[:, :3, :, :].cuda()) image_names.append(fname) + gt.close() + render.close() return renders, gts, image_names def evaluate(model_paths): diff --git a/scene/dataset_readers.py b/scene/dataset_readers.py index 2a6f904..6718123 100644 --- a/scene/dataset_readers.py +++ b/scene/dataset_readers.py @@ -96,7 +96,9 @@ def readColmapCameras(cam_extrinsics, cam_intrinsics, images_folder): image_path = os.path.join(images_folder, os.path.basename(extr.name)) image_name = os.path.basename(image_path).split(".")[0] - image = Image.open(image_path) + image_fs = Image.open(image_path) + image = image_fs.copy() + image_fs.close() cam_info = CameraInfo(uid=uid, R=R, T=T, FovY=FovY, FovX=FovX, image=image, image_path=image_path, image_name=image_name, width=width, height=height) @@ -199,6 +201,9 @@ def readCamerasFromTransforms(path, transformsfile, white_background, extension= image_path = os.path.join(path, cam_name) image_name = Path(cam_name).stem + image_fs = Image.open(image_path) + image = image_fs.copy() + image_fs.close() image = Image.open(image_path) im_data = np.array(image.convert("RGBA")) @@ -257,4 +262,4 @@ def readNerfSyntheticInfo(path, white_background, eval, extension=".png"): sceneLoadTypeCallbacks = { "Colmap": readColmapSceneInfo, "Blender" : readNerfSyntheticInfo -} \ No newline at end of file +}