Skip to content

Commit 403c191

Browse files
committed
Add a thumbnail (image shows up now!)
Signed-off-by: Fabrice Normandin <fabrice.normandin@gmail.com>
1 parent ff65c49 commit 403c191

1 file changed

Lines changed: 11 additions & 12 deletions

File tree

examples/tutorials/plot_5_warm_starting.py

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -118,18 +118,16 @@ class Net(nn.Sequential):
118118

119119
def __init__(self, n_classes: int = 10):
120120
super().__init__(
121-
nn.LazyConv2d(
122-
32, 3, 1
123-
), # NOTE: `in_channels` is determined in the first forward pass
121+
# NOTE: `in_channels` is determined in the first forward pass
122+
nn.LazyConv2d(32, 3, 1),
124123
nn.ReLU(),
125124
nn.Conv2d(32, 64, 3, 1),
126125
nn.ReLU(),
127126
nn.MaxPool2d(2),
128127
nn.Dropout2d(0.25),
129128
nn.Flatten(),
130-
nn.LazyLinear(
131-
128
132-
), # NOTE: `in_features` is determined in the first forward pass
129+
# NOTE: `in_features` is determined in the first forward pass
130+
nn.LazyLinear(128),
133131
nn.ReLU(),
134132
nn.Dropout(0.5),
135133
nn.Linear(128, n_classes),
@@ -174,12 +172,10 @@ def test_epoch(model: Net, device: torch.device, test_loader: DataLoader) -> flo
174172
for data, target in test_loader:
175173
data, target = data.to(device), target.to(device)
176174
output = model(data)
177-
test_loss += F.nll_loss(
178-
output, target, reduction="sum"
179-
).item() # sum up batch loss
180-
pred = output.argmax(
181-
dim=1, keepdim=True
182-
) # get the index of the max log-probability
175+
# sum up batch loss
176+
test_loss += F.nll_loss(output, target, reduction="sum").item()
177+
# get the index of the max log-probability
178+
pred = output.argmax(dim=1, keepdim=True)
183179
correct += pred.eq(target.view_as(pred)).sum().item()
184180

185181
test_loss /= num_batches
@@ -379,4 +375,7 @@ def main(**kwargs):
379375
},
380376
)
381377
fig.show()
378+
fig.write_image("../../docs/src/_static/warm_start_thumbnail.png")
382379
fig
380+
381+
# sphinx_gallery_thumbnail_path = '_static/warm_start_thumbnail.png'

0 commit comments

Comments
 (0)