Exemplo n.º 1
0
    def __init__(self, in_planes, planes, stride=1, test=False):
        super(BasicBlock, self).__init__()
        self.test = test
        self.conv1 = nn.Conv2d(in_planes, planes, kernel_size=3, stride=stride, padding=1, bias=False)
        self.bn1 = nn.BatchNorm2d(planes)
        self.conv2 = nn.Conv2d(planes, planes, kernel_size=3, stride=1, padding=1, bias=False)
        self.bn2 = nn.BatchNorm2d(planes)

        self.shortcut = nn.Sequential()
        if stride != 1 or in_planes != self.expansion*planes:
            self.shortcut = nn.Sequential(
                nn.Conv2d(in_planes, self.expansion*planes, kernel_size=1, stride=stride, bias=False),
                nn.BatchNorm2d(self.expansion*planes)
            )

        # Gate layers
        self.fc1 = nn.Conv2d(in_planes, 16, kernel_size=1)
        self.fc1bn = nn.BatchNorm1d(16)
        self.fc2 = nn.Conv2d(16, 2, kernel_size=1)
        # initialize the bias of the last fc for 
        # initial opening rate of the gate of about 85%
        self.fc2.bias.data[0] = 0.1
        self.fc2.bias.data[1] = 2
        self.gs = GumbleSoftmax()
        self.gs.cuda()
Exemplo n.º 2
0
    def __init__(self, num_gates_fixed_open, num_gates, num_filters_per_gate):
        super(SpecialGumble, self).__init__()
        self.num_gates_fixed_open = num_gates_fixed_open
        self.num_gates = num_gates
        self.num_filters_per_gate = num_filters_per_gate

        self.gs = GumbleSoftmax()
    def __init__(self, in_planes, planes, stride=1, test=False):
        super(Bottleneck, self).__init__()
        self.test = test
        self.conv1 = nn.Conv2d(in_planes, planes, kernel_size=1, bias=False)
        self.bn1 = nn.BatchNorm2d(planes)
        self.conv2 = nn.Conv2d(planes,
                               planes,
                               kernel_size=3,
                               stride=stride,
                               padding=1,
                               bias=False)
        self.bn2 = nn.BatchNorm2d(planes)
        self.conv3 = nn.Conv2d(planes,
                               self.expansion * planes,
                               kernel_size=1,
                               bias=False)
        self.bn3 = nn.BatchNorm2d(self.expansion * planes)

        self.shortcut = nn.Sequential()
        if stride != 1 or in_planes != self.expansion * planes:
            self.shortcut = nn.Sequential(
                nn.Conv2d(in_planes,
                          self.expansion * planes,
                          kernel_size=1,
                          stride=stride,
                          bias=False), nn.BatchNorm2d(self.expansion * planes))

        # Gate layers
        self.w = nn.Parameter(torch.cuda.FloatTensor([.1, 4]).view((2, 1, 1)))
        self.gs = GumbleSoftmax()
        self.gs.cuda()
Exemplo n.º 4
0
    def __init__(self, shape, unit_test_init=False):
        super(GumbleRelu, self).__init__()
        self.gs = GumbleSoftmax()

        self.fc1_weights = nn.Parameter(torch.zeros(
            (1, shape[1], shape[2], shape[3], 1)),
                                        requires_grad=True)
        self.fc1_bias_initial = nn.Parameter(torch.zeros(
            (1, shape[1], shape[2], shape[3], 1)),
                                             requires_grad=True)
        self.fc1_bias = nn.Parameter(torch.zeros(
            (1, shape[1], shape[2], shape[3], 2)),
                                     requires_grad=True)
        if unit_test_init:
            self.fc1_weights.data.fill_(0.1)
            self.fc1_bias.data.fill_(0.1)
        else:
            torch.nn.init.xavier_uniform(self.fc1_weights)
            self.fc1_bias.data[:, :, :, :, 1] = 4