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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bringing TorchVision models into C++ API #15639

Closed
ShahriarRezghi opened this issue Dec 31, 2018 · 8 comments
Closed

Bringing TorchVision models into C++ API #15639

ShahriarRezghi opened this issue Dec 31, 2018 · 8 comments
Labels
module: cpp Related to C++ API

Comments

@ShahriarRezghi
Copy link

ShahriarRezghi commented Dec 31, 2018

馃殌 Feature

Hi. I wanted to bring TorchVision models into C++ API.

Motivation

I was working on a project with the C++ front-end and I wanted to test networks like AlexNet and VGG and ResNet and inception to see the difference in accuracy. I searched a bit and I found out that I must make a Torch script module from a TorchVision model but the problem is that I want to train with the C++ front-end and script modules are either in train or eval mode and this cannot be changed after exporting.

Pitch

I want to implement and bring these models into the C++ API.

Alternatives

One of the alternatives can be exporting a model in both train and eval mode and training the train module and somehow copy the weights of them to eval module and get predictions from there.

Additional context

I read the source code of TorchVision and was able to implement and test AlexNet and VGG and implement ResNet.

@ezyang
Copy link
Contributor

ezyang commented Jan 3, 2019

This seems reasonable, though I'd say this would probably live in pytorch/vision in that case https://github.com/pytorch/vision (or maybe a separate repo? Not sure.) cc @fmassa @soumith

@ailzhang ailzhang added the module: cpp Related to C++ API label Jan 7, 2019
@ShahriarRezghi
Copy link
Author

Hi @ezyang
I'm sorry but it has been 17 days since I opened this suggestion and there has been no progress so far. I don't know if it's OK to remind you of this issue or not so I'm sorry in advance.

@soumith
Copy link
Member

soumith commented Jan 17, 2019

As Edward mentioned, it's a pretty good suggestion, but we should put them in https://github.com/pytorch/vision and not in https://github.com/pytorch/pytorch

Go ahead and start working on it, and thank you :)

@fmassa
Copy link
Member

fmassa commented Jan 17, 2019

Yes, this is a good thing to have!

One thing that would be worth keeping in mind is how to keep both the C++ and the Python version of the models in sync.

@ShahriarRezghi
Copy link
Author

Hi @soumith
I will fork https://github.com/pytorch/vision and put the code inside vision/torchvision/cmodels and put the cmake file inside vision//torchvision and run cmake from vision/setup.py.
Is this the correct way to do this?

@ShahriarRezghi
Copy link
Author

ShahriarRezghi commented Jan 17, 2019

@fmassa
By keeping them in sync you mean updating c++ side when python side changes or them being compatible like one reading the saved model file of another?

@fmassa
Copy link
Member

fmassa commented Jan 17, 2019

@ShahriarSS I meant when Python code changes, it would be good to have a way of checking that the C++ code should change as well

@ShahriarRezghi
Copy link
Author

@fmassa Sorry I misunderstood. I am trying to write the code that matches the python code so it will be easy to change the code when the python code changes.
And also I pressed the close button accidentally when commenting this message

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
module: cpp Related to C++ API
Projects
None yet
Development

No branches or pull requests

5 participants