Bitpath

Boss lesson · Unit 04

Stand on a trained model

Load weights, freeze the body, train a new head

13 exercisesabout 3 min

What you practise

  • Save and load a state_dict, freeze layers, replace the head, different learning rates for old and new parts, inference with eval() and no_grad()

Try a question from this lesson

Pick one

A model trained on a million photos already detects edges, textures and shapes. You have 200 labelled X-rays and 3 diagnoses. What is the smart move?

The idea

Concept cards are short on purpose. In the app they appear between questions, after you have met the idea.

Concept

A model is its state_dict

Everything a model has learned lives in its state_dict: an ordinary dict from parameter name to tensor.

Saving a model means saving that dict with torch.save. Loading means building the same architecture again and calling load_state_dict on it.

Python
net = nn.Sequential(
    nn.Linear(4, 8), nn.ReLU(),
    nn.Linear(8, 2),
)
for name, t in net.state_dict().items():
    print(name, tuple(t.shape))
# 0.weight (8, 4)
# 0.bias (8,)
# 2.weight (2, 8)
# 2.bias (2,)

11 more exercises in the app

  • 3× type the answer
  • 3× multiple choice
  • 3× fill the blanks
  • 1× true or false
  • 1× order the lines

Bitpath is an iOS app in development. Join the waitlist and you get one email when it is ready to try.

One email when Bitpath is ready to try. Nothing else. Privacy