検証を含むエポックループ
データを1周するたびに評価します
「検証を含むエポックループ」はCoddyKit上の無料Deep Learning Academyレッスンです。 これはレッスン2/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これはDeep Learning Academy学習パスの一部であり、ウェブとCoddyKitアプリ全体で進捗が同期されます。 Deep Learning Academyコースには全4レッスンが含まれています。
このレッスンの一部はまだ翻訳されておらず、英語で表示されています。
What an Epoch Means
One epoch is a single full pass over your entire training set. Real training repeats this pass many times so the model keeps improving.
The Outer Loop
Wrap your whole routine in a loop over epochs. Each turn of this outer loop trains once and then checks progress on validation.
for epoch in range(num_epochs):
train_one_epoch()
validate()The Inner Training Loop
Inside an epoch you loop over batches from the DataLoader. Each batch runs the familiar forward, loss, backward, step rhythm.
for x, y in train_loader:
optimizer.zero_grad()
loss = loss_fn(model(x), y)
loss.backward()
optimizer.step()Switch to Train Mode
Before training a pass, call model.train(). It turns on layers like dropout and batch norm that should behave differently while learning.
model.train()Switch to Eval Mode
Before validating, call model.eval(). This freezes dropout and uses running batch-norm stats so your scores are steady and fair.
model.eval()No Gradients While Validating
Validation only reads the model, so wrap it in torch.no_grad(). Skipping the graph saves memory and runs noticeably faster.
with torch.no_grad():
for x, y in val_loader:
out = model(x)Track the Running Loss
Add up each batch's loss across the epoch, then divide by the count. This average loss is one clean number to compare epoch to epoch.
total += loss.item() * x.size(0)
epoch_loss = total / len(loader.dataset)Measure Validation Loss
Compute the same average on the validation set. This validation loss reveals how well the model generalizes beyond what it trained on.
Print Progress Each Epoch
Log both losses every epoch so you can watch the curves. Seeing the trend live makes overfitting easy to catch the moment it starts.
print(epoch, train_loss, val_loss)Read the Two Curves
Healthy training shows both losses falling. When validation loss starts climbing while training keeps dropping, the model is beginning to overfit.
Don't Backward on Validation
A frequent bug is calling backward() during validation. Never update weights from val data, or you contaminate your honest measurement.
Quick Check
What should you call right before running the validation pass?
Recap
Each epoch trains in train mode, then validates in eval mode under no_grad. Track both losses and watch the gap to catch overfitting early. 📈
よくある質問
「検証を含むエポックループ」レッスンは無料ですか?
はい。「検証を含むエポックループ」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、Deep Learning Academyコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 Deep Learning Academyコースには全4レッスンが含まれています。
「検証を含むエポックループ」で何を学びますか?
データを1周するたびに評価します ブラウザで直接実行するハンズオンコードでDeep Learning Academyを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。
Deep Learning Academyを始めるのに経験は必要ですか?
事前経験は必要ありません。CoddyKitのDeep Learning Academyは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン2/4です。
「検証を含むエポックループ」レッスンにはどのくらい時間がかかりますか?
ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。
このDeep Learning Academyレッスンでコードを書いて実行できますか?
はい。すべてのDeep Learning Academyレッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。