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

Changing torchvision namespace into a static class? #729

Closed
kaiidams opened this issue Sep 14, 2022 · 2 comments · Fixed by #731
Closed

Changing torchvision namespace into a static class? #729

kaiidams opened this issue Sep 14, 2022 · 2 comments · Fixed by #731

Comments

@kaiidams
Copy link
Contributor

kaiidams commented Sep 14, 2022

Quite a few code starts from torchvision instead of importing objects by from torchvision... import xxx

https://pytorch.org/tutorials/intermediate/torchvision_tutorial.html

model = torchvision.models.detection.fasterrcnn_resnet50_fpn(weights="DEFAULT")

Now in TorchSharp, we have TorchSharp.torchvision namespace.

namespace TorchSharp.torchvision
{
    public static partial class models
    {

Can we make this a class TorchSharp.torchvision like we did for TorchSharp.torch class?

namespace TorchSharp
{
    public static partial class torchvision
    {
        public static partial class models
        {

I believe that we have to do like these in C#

using TorchSharp.torchvision;
...
models.detection.fasterrcnn_resnet50_fpn();

or

using static TorchSharp.torchvision.models.detection;
...
fasterrcnn_resnet50_fpn();
@NiklasGustafsson
Copy link
Contributor

NiklasGustafsson commented Sep 15, 2022

Any time a named scope directly contains methods, or is nested within a scope that contains methods, whether instance factories or other, it needs to be a static class. If that is the case with 'torchvision,' it should definitely be a static class.

Thus, it depends on what methods would be found directly under the 'torchvision' named scope.

@kaiidams
Copy link
Contributor Author

PyTorch torchvision has four methods

  • torchvision.set_image_backend(backend)
  • torchvision.get_image_backend()
  • torchvision.set_video_backend(backend)
  • torchvision.get_video_backend()

TorchSharp has Imager as an argument of torchvision.io.read_image() instead of having those four methods.
So currently TorchSharp doesn't have any methods under the torchvision named scope.

A namespace has to start from the top. Currently we cannot write like this in the user code.

using TorchSharp;
...
torchvision.io.read_image()

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

Successfully merging a pull request may close this issue.

2 participants