Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add pathlib.Path support to read_image #2962

Closed
Yura52 opened this issue Nov 4, 2020 · 6 comments
Closed

Add pathlib.Path support to read_image #2962

Yura52 opened this issue Nov 4, 2020 · 6 comments

Comments

@Yura52
Copy link

Yura52 commented Nov 4, 2020

When I try to pass an object of pathlib.Path to torchvision.io.read_image, I get:

RuntimeError: image::read_file() Expected a value of type 'str' for argument '_0' but instead found type 'PosixPath'.
Position: 0
Value: PosixPath('<SOME PATH>')
Declaration: image::read_file(str _0) -> (Tensor _0)
Cast error details: Unable to cast Python instance to C++ type (compile in debug mode for details)

Casting the object to str fixes the problem. It would be nice to support the usual set of "path-like" types as input (str, bytes, pathlib.Path, ...)

python==3.8.3
torch==1.7.0
torchvision==0.8.1
@vfdev-5
Copy link
Collaborator

vfdev-5 commented Nov 4, 2020

@Yura52 thanks for the feature request. This seems reasonable, however there could be a blocker if we would like to use it with torchscript. We have to check.

@fmassa
Copy link
Member

fmassa commented Nov 5, 2020

As @vfdev-5 mentioned, we would like to support pathlib.Path, but it wouldn't support torchscript for pathlib.Path.

As you mentioned, this could be probably easily done by casting internally to str in

data = torch.ops.image.read_file(path)
and
torch.ops.image.write_file(filename, data)

and adding something like

path = str(path)

before the function calls.

@vict0rsch
Copy link

vict0rsch commented Jan 28, 2022

Any news on this front?

@LifeGains
Copy link

+1 support for this please

@eldar
Copy link

eldar commented Nov 4, 2022

would be nice to have.

@NicolasHug
Copy link
Member

I believe this was addressed by #8314

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants