MCPcopy Create free account
hub / github.com/Kaggle/docker-python / LitClassifier

Class LitClassifier

tests/test_pytorch_lightning.py:34–57  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

32class LitClassifier(pl.LightningModule):
33
34 def __init__(self):
35 super().__init__()
36 self.l1 = torch.nn.Linear(28 * 28, 10)
37
38 def forward(self, x):
39 return F.relu(self.l1(x.view(x.size(0), -1)))
40
41 def training_step(self, batch, batch_idx):
42 x, y = batch
43 y_hat = self(x)
44 loss = F.cross_entropy(y_hat, y)
45 self.log('train_loss', loss)
46 return loss
47
48 def validation_step(self, batch, batch_idx):
49 x, y = batch
50 y_hat = self(x)
51 loss = F.cross_entropy(y_hat, y)
52 self.log('val_loss', loss)
53
54 def configure_optimizers(self):
55 return torch.optim.Adam(self.parameters(), lr=1e-2)
56
57class TestPytorchLightning(unittest.TestCase):
58
59 def test_version(self):
60 self.assertIsNotNone(pl.__version__)

Callers 1

test_mnistMethod · 0.85

Calls

no outgoing calls

Tested by 1

test_mnistMethod · 0.68