Open zerotosingularity opened 6 years ago
Tried '1.0.0.dev20181112' pytorch-nightly, but the issue remains.
11/30/18 FYI, the tutorial and the source links have been updated, so that you don't need to apply the source mods mentioned above. But the problem of the of the runs not generating matching data still remains.
@tlc thanks for the update. Is there a way to get informed on whether that issue (export to caffe2) is being addressed? Or is there something I can do myself?
Hi Came for the same Bug, i'm in Manjaro, get the example from https://pytorch.org/tutorials/advanced/super_resolution_with_caffe2.html?highlight=mobile
i don't know what to do. But if i can help in something, letme know
Can anyone point to any working example of a real world model that transfers well from PyTorch to Caffe2?
Yes you may follow exactly the same steps for alexnet conversion from pytorch to caffe2. Which gives the same outputs as expected both in pytorch and caffe2 backend. Here is the link: https://pytorch.org/docs/stable/onnx.html. This issue with superres might be due to some ops like pixel_shuffle, because other ops are common with Alexnet such as (conv2d, relu).
It works fine if you change the network:
#dummy supperres model
class SuperResolutionNet(nn.Module):
def __init__(self, upscale_factor, inplace=False):
super(SuperResolutionNet, self).__init__()
self.relu = nn.ReLU(inplace=inplace)
self.conv1 = nn.Conv2d(1, 64, (5, 5), (1, 1), (2, 2))
self.conv2 = nn.Conv2d(64, 64, (3, 3), (1, 1), (1, 1))
self.conv3 = nn.Conv2d(64, 32, (3, 3), (1, 1), (1, 1))
self.conv4 = nn.Conv2d(32, 1, (3, 3), (1, 1), (1, 1))
self.pixel_shuffle = nn.Upsample(scale_factor=upscale_factor, mode='nearest')
self._initialize_weights()
def forward(self, x):
x = self.relu(self.conv1(x))
x = self.relu(self.conv2(x))
x = self.relu(self.conv3(x))
x = self.pixel_shuffle(self.conv4(x))
return x
def _initialize_weights(self):
init.orthogonal_(self.conv1.weight, init.calculate_gain('relu'))
init.orthogonal_(self.conv2.weight, init.calculate_gain('relu'))
init.orthogonal_(self.conv3.weight, init.calculate_gain('relu'))
init.orthogonal_(self.conv4.weight)
# Create the super-resolution model by using the above model definition.
torch_model = SuperResolutionNet(upscale_factor=3)
Yes you may follow exactly the same steps for alexnet conversion from pytorch to caffe2. Which gives the same outputs as expected both in pytorch and caffe2 backend. Here is the link: https://pytorch.org/docs/stable/onnx.html. This issue with superres might be due to some ops like pixel_shuffle, because other ops are common with Alexnet such as (conv2d, relu).
It works fine if you change the network:
#dummy supperres model class SuperResolutionNet(nn.Module): def __init__(self, upscale_factor, inplace=False): super(SuperResolutionNet, self).__init__() self.relu = nn.ReLU(inplace=inplace) self.conv1 = nn.Conv2d(1, 64, (5, 5), (1, 1), (2, 2)) self.conv2 = nn.Conv2d(64, 64, (3, 3), (1, 1), (1, 1)) self.conv3 = nn.Conv2d(64, 32, (3, 3), (1, 1), (1, 1)) self.conv4 = nn.Conv2d(32, 1, (3, 3), (1, 1), (1, 1)) self.pixel_shuffle = nn.Upsample(scale_factor=upscale_factor, mode='nearest') self._initialize_weights() def forward(self, x): x = self.relu(self.conv1(x)) x = self.relu(self.conv2(x)) x = self.relu(self.conv3(x)) x = self.pixel_shuffle(self.conv4(x)) return x def _initialize_weights(self): init.orthogonal_(self.conv1.weight, init.calculate_gain('relu')) init.orthogonal_(self.conv2.weight, init.calculate_gain('relu')) init.orthogonal_(self.conv3.weight, init.calculate_gain('relu')) init.orthogonal_(self.conv4.weight) # Create the super-resolution model by using the above model definition. torch_model = SuperResolutionNet(upscale_factor=3)
I have replaced nn.PixelShuffle with nn.Upsample and the test passed. It's great. But I'm curious if tensorrt does not support PixelShuffle op, why not cause an error??? A wrong output answer may puzzled us.
📚 Documentation
Following the "Transfering a Model from PyTorch to Caffe2 and Mobile using ONNX" I get the following exception:
when running
(with the documentation specifically asking to contact the team when this happens. :))
I have been able to reproduce the error on both Ubuntu 16.04 and Google Colab. Note that I have not install onnx-caffe2 and updated the source code following PR-348.
This is the environment on Ubuntu 16.004
Conda env:
Pip list: