def test_conv2d_relu(self):
    target = torch.LongTensor(1, 6, 5).fill_(0)
    for i in range(1, self.num_classes):
        target[..., i:(- i), i:(- i)] = i
    m = nn.Sequential(nn.Conv2d(1, self.num_classes, kernel_size=3, padding=1), nn.ReLU(True))
    m.apply(self.init_weights)
    optimizer = optim.Adam(m.parameters(), lr=self.lr)
    criterion = kornia.losses.FocalLoss(alpha=self.alpha, gamma=self.gamma, reduction='mean')
    for iter_id in range(self.num_iterations):
        sample = self.generate_sample(target)
        output = m(sample)
        loss = criterion(output, target)
        logger.debug('Loss: {}'.format(loss.item()))
        optimizer.zero_grad()
        loss.backward()
        optimizer.step()
    sample = self.generate_sample(target)
    output_argmax = torch.argmax(m(sample), dim=1)
    logger.debug('Output argmax: \n{}'.format(output_argmax))
    val = F.mse_loss(output_argmax.float(), target.float())
    if (not (val.item() < self.thresh)):
        pytest.xfail('Wrong seed or initial weight values.')
def test_conv2d_relu(self):
    target = torch.LongTensor(1, 6, 5).fill_(0)
    for i in range(1, self.num_classes):
        target[..., i:(- i), i:(- i)] = i
    m = nn.Sequential(nn.Conv2d(1, self.num_classes, kernel_size=3, padding=1), nn.ReLU(True))
    m.apply(self.init_weights)
    optimizer = optim.Adam(m.parameters(), lr=self.lr)
    criterion = kornia.losses.FocalLoss(alpha=self.alpha, gamma=self.gamma, reduction='mean')
    for iter_id in range(self.num_iterations):
        sample = self.generate_sample(target)
        output = m(sample)
        loss = criterion(output, target)
        logger.debug('Loss: {}'.format(loss.item()))
        optimizer.zero_grad()
        loss.backward()
        optimizer.step()
    sample = self.generate_sample(target)
    output_argmax = torch.argmax(m(sample), dim=1)
    logger.debug('Output argmax: \n{}'.format(output_argmax))
    val = F.mse_loss(output_argmax.float(), target.float())
    if (not (val.item() < self.thresh)):
        pytest.xfail('Wrong seed or initial weight values.')