def __init__(self, in_planes, planes, stride=1): 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, padding=1, stride=1, bias=False) self.bn2 = nn.BatchNorm2D(planes) self.downsample = [] if stride != 1 or in_planes != self.expansion * planes: self.downsample = [ nn.Conv2d(in_planes, self.expansion * planes, kernel_size=1, stride=stride, bias=False), nn.BatchNorm2D(self.expansion * planes) ]
def __init__(self, block, num_blocks, num_classes=10, url=None): self.url = url self.in_planes = 64 self.conv1 = nn.Conv2d(3, 64, kernel_size=7, stride=2, bias=False, padding=3) self.bn1 = nn.BatchNorm2D(64) self.layer1 = self._make_layer(block, 64, num_blocks[0], stride=2) self.layer2 = self._make_layer(block, 128, num_blocks[1], stride=2) self.layer3 = self._make_layer(block, 256, num_blocks[2], stride=2) self.layer4 = self._make_layer(block, 512, num_blocks[3], stride=2) self.fc = {"weight": Tensor.uniform(512 * block.expansion, num_classes), "bias": Tensor.zeros(num_classes)}
def __init__(self, block, num_blocks, num_classes=10, pretrained=False): self.in_planes = 64 self.conv1 = nn.Conv2d(3, 64, kernel_size=7, stride=2, bias=False, padding=3) self.bn1 = nn.BatchNorm2D(64) self.layer1 = self._make_layer(block, 64, num_blocks[0], stride=2) self.layer2 = self._make_layer(block, 128, num_blocks[1], stride=2) self.layer3 = self._make_layer(block, 256, num_blocks[2], stride=2) self.layer4 = self._make_layer(block, 512, num_blocks[3], stride=2) self.fc = nn.Linear(512 * block.expansion, num_classes)
def __init__(self, num, num_classes): self.num = num self.block = { 18: BasicBlock, 34: BasicBlock, 50: Bottleneck, 101: Bottleneck, 152: Bottleneck }[num] self.num_blocks = { 18: [2, 2, 2, 2], 34: [3, 4, 6, 3], 50: [3, 4, 6, 3], 101: [3, 4, 23, 3], 152: [3, 8, 36, 3] }[num] self.in_planes = 64 self.conv1 = nn.Conv2d(3, 64, kernel_size=7, stride=2, bias=False, padding=3) self.bn1 = nn.BatchNorm2D(64) self.layer1 = self._make_layer(self.block, 64, self.num_blocks[0], stride=2) self.layer2 = self._make_layer(self.block, 128, self.num_blocks[1], stride=2) self.layer3 = self._make_layer(self.block, 256, self.num_blocks[2], stride=2) self.layer4 = self._make_layer(self.block, 512, self.num_blocks[3], stride=2) self.fc = { "weight": Tensor.uniform(512 * self.block.expansion, num_classes), "bias": Tensor.zeros(num_classes) }