バックボーンを固定してヘッドを学習する
学習済みの特徴を低コストで再利用します
「バックボーンを固定してヘッドを学習する」はCoddyKit上の無料Deep Learning Academyレッスンです。 これはレッスン1/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これはDeep Learning Academy学習パスの一部であり、ウェブとCoddyKitアプリ全体で進捗が同期されます。 Deep Learning Academyコースには全4レッスンが含まれています。
このレッスンの一部はまだ翻訳されておらず、英語で表示されています。
Borrow a Smart Brain
Why train from zero? A model already trained on millions of images has learned useful features. Transfer learning reuses that knowledge for your task. 🧠
Backbone vs Head
A pretrained model has two parts: the backbone that extracts general features, and the head that makes the final prediction for its original task.
The Plan
The simplest recipe: freeze the backbone so it stays as is, then swap in a fresh head and train only that part on your own labels.
Load a Pretrained Model
Start with a model that already carries good weights. torchvision hands you popular architectures with one call.
from torchvision import models
model = models.resnet18(weights='DEFAULT')Freezing Means No Gradients
To freeze a layer you set requires_grad to False. PyTorch then skips computing gradients for it, so its weights never change.
for p in model.parameters():
p.requires_grad = FalseWhy Freeze at All?
Freezing the backbone keeps its hard-won features intact and means far fewer weights to update. That makes training faster and works with little data.
Swap the Head
The old head predicts the wrong classes. Replace it with a fresh Linear layer sized for your number of classes.
import torch.nn as nn
model.fc = nn.Linear(512, 3)The New Head Is Trainable
A brand-new layer starts with requires_grad set to True automatically. So only your head will learn while the frozen backbone watches.
Optimize Only the Head
Pass just the head's parameters to your optimizer. Updating only these few weights is what makes this approach so cheap.
opt = torch.optim.Adam(model.fc.parameters(), lr=1e-3)The Backbone Becomes an Extractor
With its weights frozen, the backbone simply turns each image into a rich feature vector. Your head learns to read those features.
When This Shines
Freeze-and-train-head is ideal with a small dataset or limited compute. You get strong results in minutes instead of days.
Quick Check
You froze the backbone and replaced the head. Which weights actually update during training?
Recap
You learned to borrow a pretrained backbone, freeze it, attach a fresh head, and train just that head. Fast, cheap, and great with small data. 🎯
よくある質問
「バックボーンを固定してヘッドを学習する」レッスンは無料ですか?
はい。「バックボーンを固定してヘッドを学習する」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、Deep Learning Academyコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 Deep Learning Academyコースには全4レッスンが含まれています。
「バックボーンを固定してヘッドを学習する」で何を学びますか?
学習済みの特徴を低コストで再利用します ブラウザで直接実行するハンズオンコードでDeep Learning Academyを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。
Deep Learning Academyを始めるのに経験は必要ですか?
事前経験は必要ありません。CoddyKitのDeep Learning Academyは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン1/4です。
「バックボーンを固定してヘッドを学習する」レッスンにはどのくらい時間がかかりますか?
ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。
このDeep Learning Academyレッスンでコードを書いて実行できますか?
はい。すべてのDeep Learning Academyレッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。
このコースのすべてのレッスン
- バックボーンを固定してヘッドを学習する
- 低い学習率でファインチューニングする
- レイヤーごとに変える学習率
- Hugging Faceモデルをファインチューニングする