Skip to content

Commit 1872e02

Browse files
bottlerfacebook-github-bot
authored andcommitted
path_manager in obj_io
Summary: Use PathManager for checking file existence, rather than assuming the path is a local file, in a couple of cases. Reviewed By: patricklabatut Differential Revision: D29734621 fbshipit-source-id: e2236a7c2c50ba6916936a4d786abd601205b519
1 parent 9e8d91e commit 1872e02

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

pytorch3d/io/mtl_io.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ def _bilinear_interpolation_grid_sample(
398398

399399

400400
def _parse_mtl(
401-
f, path_manager: PathManager, device: Device = "cpu"
401+
f: str, path_manager: PathManager, device: Device = "cpu"
402402
) -> Tuple[MaterialProperties, TextureFiles]:
403403
material_properties = {}
404404
texture_files = {}
@@ -456,7 +456,7 @@ def _load_texture_images(
456456
if material_name in texture_files:
457457
# Load the texture image.
458458
path = os.path.join(data_dir, texture_files[material_name])
459-
if os.path.isfile(path):
459+
if path_manager.exists(path):
460460
image = (
461461
_read_image(path, path_manager=path_manager, format="RGB") / 255.0
462462
)
@@ -475,7 +475,7 @@ def _load_texture_images(
475475

476476

477477
def load_mtl(
478-
f,
478+
f: str,
479479
*,
480480
material_names: List[str],
481481
data_dir: str,
@@ -487,7 +487,7 @@ def load_mtl(
487487
and specular light (Ka, Kd, Ks, Ns).
488488
489489
Args:
490-
f: a file-like object of the material information.
490+
f: path to the material information.
491491
material_names: a list of the material names found in the .obj file.
492492
data_dir: the directory where the material texture files are located.
493493
device: Device (as str or torch.tensor) on which to return the new tensors.

pytorch3d/io/obj_io.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,7 @@ def _parse_obj(f, data_dir: str):
499499

500500
def _load_materials(
501501
material_names: List[str],
502-
f,
502+
f: Optional[str],
503503
*,
504504
data_dir: str,
505505
load_textures: bool,
@@ -511,7 +511,7 @@ def _load_materials(
511511
512512
Args:
513513
material_names: a list of the material names found in the .obj file.
514-
f: a file-like object of the material information.
514+
f: path to the material information.
515515
data_dir: the directory where the material texture files are located.
516516
load_textures: whether textures should be loaded.
517517
device: Device (as str or torch.device) on which to return the new tensors.
@@ -529,7 +529,7 @@ def _load_materials(
529529
warnings.warn("No mtl file provided")
530530
return None, None
531531

532-
if not os.path.isfile(f):
532+
if not path_manager.exists(f):
533533
warnings.warn(f"Mtl file does not exist: {f}")
534534
return None, None
535535

0 commit comments

Comments
 (0)