Package: gluon2pytorch
gluon2pytorchGluon to PyTorch model convertor with script generation.Installationgit clone https://github.com/nerox8664/gluon2pytorch
cd gluon2pytorch
pip install -e .or you can usepip:pip install gluon2pytorchHow to useIt's the convertor of Gluon graph to a Pytorch model file + weights.Firstly, we need to load (or create) Gluon Hybrid model:class ReLUTest(mx.gluon.nn.HybridSequential):
    def __init__(self):
        super(ReLUTest, self).__init__()
        from mxnet.gluon import nn
        with self.name_scope():
            self.conv1 = nn.Conv2D(3, 32)
            self.relu = nn.Activation('relu')

    def hybrid_forward(self, F, x):
        x = F.relu(self.relu(self.conv1(x)))
        return x


if __name__ == '__main__':
    net = ReLUTest()
    
    # Make sure it's hybrid and initialized
    net.hybridize()
    net.collect_params().initialize()The next step - call the converter:pytorch_model = gluon2pytorch(net, [(1, 3, 224, 224)], dst_dir=None, pytorch_module_name='ReLUTest')Finally, we can check the differenceinput_np = np.random.uniform(-1, 1, (1, 3, 224, 224))

    gluon_output = net(mx.nd.array(input_np))
    pytorch_output = pytorch_model(torch.FloatTensor(input_np))
    check_error(gluon_output, pytorch_output)Supported layersLayers:LinearConv2dConvTranspose2d (Deconvolution)MaxPool2dAvgPool2dGlobal average pooling (as special case of AdaptiveAvgPool2d)BatchNorm2d*Padding2d (constant, reflection, replication)Reshape:FlattenActivations:ReLULeakyReLUSigmoidSoftmaxSELUElement-wise:AdditionConcatenationSubtractionMultiplicationMisc:clampBilinearResize2DLRNClassification models converted with gluon2pytorchModelTop1Top5ParamsFLOPsSource weightsRemarksResNet-1037.0915.555,418,792892.62Mosmr's repoSuccessResNet-1235.8614.465,492,7761,124.23Mosmr's repoSuccessResNet-1432.8512.415,788,2001,355.64Mosmr's repoSuccessResNet-1630.6811.106,968,8721,586.95Mosmr's repoSuccessResNet-18 x0.2549.1624.45831,096136.64Mosmr's repoSuccessResNet-18 x0.536.5414.963,055,880485.22Mosmr's repoSuccessResNet-18 x0.7533.2512.546,675,3521,045.75Mosmr's repoSuccessResNet-1829.139.9411,689,5121,818.21Mosmr's repoSuccessResNet-3425.347.9221,797,6723,669.16Mosmr's repoSuccessResNet-5023.506.8725,557,0323,868.96Mosmr's repoSuccessResNet-50b22.926.4425,557,0324,100.70Mosmr's repoSuccessResNet-10121.665.9944,549,1607,586.30Mosmr's repoSuccessResNet-101b21.185.6044,549,1607,818.04Mosmr's repoSuccessResNet-15221.015.6160,192,80811,304.85Mosmr's repoSuccessResNet-152b20.545.3760,192,80811,536.58Mosmr's repoSuccessPreResNet-1828.729.8811,687,8481,818.41Mosmr's repoSuccessPreResNet-3425.888.1121,796,0083,669.36Mosmr's repoSuccessPreResNet-5023.396.6825,549,4803,869.16Mosmr's repoSuccessPreResNet-50b23.166.6425,549,4804,100.90Mosmr's repoSuccessPreResNet-10121.455.7544,541,6087,586.50Mosmr's repoSuccessPreResNet-101b21.735.8844,541,6087,818.24Mosmr's repoSuccessPreResNet-15220.705.3260,185,25611,305.05Mosmr's repoSuccessPreResNet-152b21.005.7560,185,25611,536.78MGluon Model ZooSuccessPreResNet-200b21.105.6464,666,28015,040.27Mtornadomeet/ResNetSuccessResNeXt-101 (32x4d)21.325.7944,177,7047,991.62MCadene's repoSuccessResNeXt-101 (64x4d)20.605.4183,455,27215,491.88MCadene's repoSuccessSE-ResNet-5022.516.4428,088,0243,877.01MCadene's repoSuccessSE-ResNet-10121.925.8949,326,8727,600.01MCadene's repoSuccessSE-ResNet-15221.485.7766,821,84811,324.62MCadene's repoSuccessSE-ResNeXt-50 (32x4d)21.065.5827,559,8964,253.33MCadene's repoSuccessSE-ResNeXt-101 (32x4d)19.995.0048,955,4168,005.33MCadene's repoSuccessSENet-15418.844.65115,088,98420,742.40MCadene's repoSuccessDenseNet-12125.117.807,978,8562,852.39MGluon Model ZooSuccessDenseNet-16122.406.1828,681,0007,761.25MGluon Model ZooSuccessDenseNet-16923.896.8914,149,4803,381.48MGluon Model ZooSuccessDenseNet-20122.716.3620,013,9284,318.75MGluon Model ZooSuccessDPN-6823.577.0012,611,6022,338.71MCadene's repoSuccessDPN-9820.235.2861,570,72811,702.80MCadene's repoSuccessDPN-13120.035.2279,254,50416,056.22MCadene's repoSuccessDarkNet Tiny40.3117.461,042,104496.34Mosmr's repoSuccessDarkNet Ref38.0016.687,319,416365.55Mosmr's repoSuccessSqueezeNet v1.040.9718.961,248,424828.30Mosmr's repoSuccessSqueezeNet v1.139.0917.391,235,496354.88Mosmr's repoSuccessSqueezeResNet v1.139.8317.841,235,496354.88Mosmr's repoSuccessShuffleNetV2 x0.540.6118.301,366,79242.34Mosmr's repoSuccessShuffleNetV2c x0.539.8718.111,366,79242.37Mtensorpack/tensorpackSuccessShuffleNetV2 x1.033.7613.222,278,604147.92Mosmr's repoSuccessShuffleNetV2c x1.030.7411.382,279,760148.85Mtensorpack/tensorpackSuccessShuffleNetV2 x1.532.3812.374,406,098318.61Mosmr's repoSuccessShuffleNetV2 x2.032.0412.107,601,686593.66Mosmr's repoSuccess108-MENet-8x1 (g=3)43.6220.30654,51640.64Mosmr's repoSuccess128-MENet-8x1 (g=4)45.8021.93750,79643.58Mclavichord93/MENetSuccess228-MENet-12x1 (g=3)35.0313.991,806,568148.93Mclavichord93/MENetSuccess256-MENet-12x1 (g=4)34.4913.901,888,240146.11Mclavichord93/MENetSuccess348-MENet-12x1 (g=3)31.1711.413,368,128306.31Mclavichord93/MENetSuccess352-MENet-12x1 (g=8)34.7013.752,272,872151.03Mclavichord93/MENetSuccess456-MENet-24x1 (g=3)29.5710.435,304,784560.72Mclavichord93/MENetSuccessMobileNet x0.2545.7822.18470,07242.30Mosmr's repoSuccessMobileNet x0.536.1214.811,331,592152.04Mosmr's repoSuccessMobileNet x0.7532.7112.282,585,560329.22MGluon Model ZooSuccessMobileNet x1.029.2510.034,231,976573.83MGluon Model ZooSuccessFD-MobileNet x0.2556.1931.38383,16012.44Mosmr's repoSuccessFD-MobileNet x0.542.6219.69993,92840.93Mosmr's repoSuccessFD-MobileNet x1.035.9514.722,901,288146.08Mclavichord93/FD-MobileNetSuccessMobileNetV2 x0.2548.8925.241,516,39232.22MGluon Model ZooSuccessMobileNetV2 x0.535.5114.641,964,73695.62MGluon Model ZooSuccessMobileNetV2 x0.7530.8211.262,627,592191.61MGluon Model ZooSuccessMobileNetV2 x1.028.519.903,504,960320.19MGluon Model ZooSuccessNASNet-A-Mobile25.377.955,289,978587.29MCadene's repoSuccessInceptionV321.225.5923,834,5685,746.72MGluon Model ZooSuccessAirNet50-1x64d (r=2)22.486.2127,425,8644,757.77Msoeaver/AirNet-PyTorchSuccessAirNet50-1x64d (r=16)22.916.4625,714,9524,385.54Msoeaver/AirNet-PyTorchSuccessAirNeXt50-32x4d (r=2)20.875.5127,604,2965,321.18Msoeaver/AirNet-PyTorchSuccessDiracNetV2-1831.4711.7011,511,7841,798.43Mszagoruyko/diracnetsSuccessDiracNetV2-3428.759.9321,616,2323,649.37Mszagoruyko/diracnetsSuccessDARTS26.708.744,718,752537.64Mszagoruyko/diracnetsSuccessPolyNet19.104.5295,366,60034,768.84MCadene's repoSuccessZfNet????osmr's repoSuccessFishNet-15022.856.3824,959,4006,435.02Mosmr's repoSuccessSegmentation models converted with gluon2pytorchNameModelpixAccmIoUSource weightsRemarksfcn_resnet101_cocoFCN92.266.2Gluon Model ZooSuccessfcn_resnet101_vocFCNN/A83.6Gluon Model ZooSuccessCode snippetsLook at thetestsdirectory.LicenseThis software is covered by MIT License.