コード例 #1
0
 def net2net_deeper_nononline(self):
     s = deeper(self.conv1,
                None,
                bnorm=False,
                weight_norm=args.weight_norm,
                noise=args.noise)
     self.conv1 = s
     s = deeper(self.conv2,
                None,
                bnorm=False,
                weight_norm=args.weight_norm,
                noise=args.noise)
     self.conv2 = s
     s = deeper(self.conv3,
                None,
                bnorm=False,
                weight_norm=args.weight_norm,
                noise=args.noise)
     self.conv3 = s
コード例 #2
0
 def net2net_deeper(self):
     s = deeper(self.conv1,
                F.ReLU,
                bnorm=False,
                weight_norm=args.weight_norm,
                noise=args.noise)
     self.conv1 = s
     s = deeper(self.conv2,
                F.ReLU,
                bnorm=False,
                weight_norm=args.weight_norm,
                noise=args.noise)
     self.conv2 = s
     s = deeper(self.conv3,
                F.ReLU,
                bnorm=False,
                weight_norm=args.weight_norm,
                noise=args.noise)
     self.conv3 = s
コード例 #3
0
ファイル: train_cifar10.py プロジェクト: savourylie/Net2Net
 def net2net_deeper(self):
     s = deeper(self.conv1,
                nn.ReLU,
                bnorm_flag=True,
                weight_norm=args.weight_norm,
                noise=args.noise)
     self.conv1 = s
     s = deeper(self.conv2,
                nn.ReLU,
                bnorm_flag=True,
                weight_norm=args.weight_norm,
                noise=args.noise)
     self.conv2 = s
     s = deeper(self.conv3,
                nn.ReLU,
                bnorm_flag=True,
                weight_norm=args.weight_norm,
                noise=args.noise)
     self.conv3 = s
     print(self)
コード例 #4
0
def net2net_deeper_recursive(model):
    """
    Apply deeper operator recursively any conv layer.
    """
    for name, module in model._modules.items():
        if isinstance(module, nn.Conv2d):
            s = deeper(module, nn.ReLU, bnorm=False)
            model._modules[name] = s
        elif isinstance(module, nn.Sequential):
            module = net2net_deeper_recursive(module)
            model._modules[name] = module
    return model
コード例 #5
0
    def test_deeper(self):
        net = self._create_net()
        inp = th.autograd.Variable(th.rand(32, 1, 28, 28))

        net.eval()
        out = net(inp)

        s = deeper(net._modules['conv1'], nn.ReLU, bnorm_flag=True, weight_norm=False, noise=False)
        net._modules['conv1'] = s

        s2 = deeper(net._modules['conv2'], nn.ReLU, bnorm_flag=True, weight_norm=False, noise=False)
        net._modules['conv2'] = s2

        s3 = deeper(net._modules['fc1'], nn.ReLU, bnorm_flag=True, weight_norm=False, noise=False)
        net._modules['fc1'] = s3

        net.eval()
        nout = net(inp)

        assert th.abs((out - nout).sum().data)[0] < 1e-1

        # test for 3D net
        net = Net3D()
        inp = th.autograd.Variable(th.rand(32, 1, 16, 28, 28))

        net.eval()
        out = net(inp)

        s = deeper(net._modules['conv1'], nn.ReLU, bnorm_flag=False, weight_norm=False, noise=False)
        net._modules['conv1'] = s

        # s2 = deeper(net._modules['conv2'], nn.ReLU, bnorm_flag=False, weight_norm=False, noise=False)
        # net._modules['conv2'] = s2

        net.eval()
        nout = net(inp)

        assert th.abs((out - nout).sum().data)[0] < 1e-1, "New layer changes values by {}".format(th.abs(out - nout).sum().data[0])