Computer Vision News - June 2020

class Net(nn.Module): def __init__ (self): super(Net, self). __init__ () self.conv1 = nn.Sequential(nn.Conv2d(1, 32, kernel_size=3), nn.BatchNorm2d(32)) self.conv2 = nn.Sequential(nn.Conv2d(32, 64, kernel_size=3), nn.BatchNorm2d(64)) self.conv3 = nn.Sequential(nn.Conv2d(64, 128, kernel_size=3), nn.BatchNorm2d(128)) self.conv4 = nn.Sequential(nn.Conv2d(128, 128, kernel_size=3), nn.BatchNorm2d(128)) self.fc1 = nn.Sequential(nn.Linear(3200, 500), nn.BatchNorm1d(500)) self.fc2 = nn.Sequential(nn.Linear(500, 2), nn.BatchNorm1d(2)) def forward(self, x): x = F.relu(self.conv1(x)) x = F.relu(self.conv2(x)) x = F.max_pool2d(x, 2) x = F.relu(self.conv3(x)) x = F.relu(self.conv4(x)) x = F.max_pool2d(x, 2) x = x.view(x.size(0), -1) # preserve 0 th dimension x = F.relu(self.fc1(x)) x = self.fc2(x) x = F.log_softmax(x, dim=1) return x 2 Summary Co puter Vision Tools 34 Classification Network The classification network is described by the following ASCII schematic: Conv1 -> Conv2 -> MaxPool2D -> Conv3 -> Conv4 -> MaxPool2D -> FC1 -> FC2 -> LogSoftMax The simplicity of PyTorch shines here. It is very easy to implement a neural network, almost as easy as describing the network to a friend: model = Net().float() checkpoint = torch.load('nodels/liver-pw-seg.tar') model.load_state_dict(checkpoint['state_dict']) model = model.float() Feel free to create a training constructor for this network. To keep this example short, a pre-trained network is used here:

RkJQdWJsaXNoZXIy NTc3NzU=