TorchSharp icon indicating copy to clipboard operation
TorchSharp copied to clipboard

torchvision.io.read_image{,_async}(string filename, ...) prevents subsequent opening of the file for reading

Open hiyuh opened this issue 5 months ago • 0 comments

Describe the bug

  • SSIA.

To Reproduce

  • try to open an image file while processing torchvision.io.read_image{,_async}(string filename, ...).

Expected behavior

  • following stream must be opened w/ FileAccess.Read and FileShare.Read.
    • https://github.com/dotnet/TorchSharp/blob/6ceda5336102bfb1e20b65ece1686fa9a8bd9a20/src/TorchVision/IO/Image.cs#L139
    • https://github.com/dotnet/TorchSharp/blob/6ceda5336102bfb1e20b65ece1686fa9a8bd9a20/src/TorchVision/IO/Image.cs#L170
  • see also https://learn.microsoft.com/en-us/dotnet/api/system.io.file.open?view=net-8.0#system-io-file-open(system-string-system-io-filemode).

    Opens a FileStream on the specified path with read/write access with no sharing.

Please complete the following information:

  • OS: at least on Windows
  • Package: TorchVision
  • Version: 0.105.1 or earlier

Additional context

  • a possible workaround i can think of: use torchvision.io.read_image{,_async}(Stream stream, ...) w/ correctly opened stream.

hiyuh avatar Sep 04 '25 09:09 hiyuh