0Pricing
Deep Learning Academy · レッスン

CNN画像分類器を組み立てる

Conv-ReLU-poolブロックで動作するモデルを作ります

「CNN画像分類器を組み立てる」はCoddyKit上の無料Deep Learning Academyレッスンです。 これはレッスン4/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これはDeep Learning Academy学習パスの一部であり、ウェブとCoddyKitアプリ全体で進捗が同期されます。 Deep Learning Academyコースには全4レッスンが含まれています。

このレッスンの一部はまだ翻訳されておらず、英語で表示されています。

The CNN Recipe

A classic image classifier stacks conv-ReLU-pool blocks to extract features, then ends with dense layers that predict the class.

One Building Block

Each block follows the same rhythm: a conv layer, a ReLU activation, then a pool. This is the basic conv block you repeat.

block = nn.Sequential(
    nn.Conv2d(3, 16, 3, padding=1),
    nn.ReLU(),
    nn.MaxPool2d(2),
)

ReLU Adds Nonlinearity

Without an activation, stacked convolutions collapse into one linear step. ReLU after each conv lets the network learn complex shapes.

Stack Blocks to Go Deeper

Repeat the block, growing the channels each time. More blocks mean a wider receptive field and richer learned features.

Flatten Before the Head

After the conv blocks you have a stack of small maps. Flatten them into one vector so a dense layer can read them.

x = torch.flatten(x, start_dim=1)

The Classifier Head

A Linear layer maps the flattened features to one score per class. For ten classes, it outputs ten numbers.

head = nn.Linear(64, 10)

Define the Model

Wrap the features and head in an nn.Module. The forward method runs the convs, flattens, then the classifier.

class CNN(nn.Module):
    def __init__(self):
        super().__init__()
        self.features = block
        self.head = head

Write the Forward Pass

In forward, pass the image through features, flatten, and feed the head. The output is one raw score per class.

def forward(self, x):
    x = self.features(x)
    x = torch.flatten(x, 1)
    return self.head(x)

Outputs Are Logits

The head returns raw scores called logits, not probabilities. Cross-entropy loss expects exactly these raw values during training.

Pick the Loss

For multiclass images, use CrossEntropyLoss. It applies softmax internally and compares against the true label index.

loss_fn = nn.CrossEntropyLoss()

Predict a Class

At inference, take the index of the largest logit. That argmax is the model's predicted class for the image. 🖼️

pred = logits.argmax(dim=1)

Quick Check

Let us check the order of a CNN classifier's pieces.

Recap: A Working CNN

You assembled a CNN: conv-ReLU-pool blocks extract features, flatten feeds a Linear head, and argmax over logits gives the predicted class. 🎉

よくある質問

「CNN画像分類器を組み立てる」レッスンは無料ですか?

はい。「CNN画像分類器を組み立てる」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、Deep Learning Academyコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 Deep Learning Academyコースには全4レッスンが含まれています。

「CNN画像分類器を組み立てる」で何を学びますか?

Conv-ReLU-poolブロックで動作するモデルを作ります ブラウザで直接実行するハンズオンコードでDeep Learning Academyを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。

Deep Learning Academyを始めるのに経験は必要ですか?

事前経験は必要ありません。CoddyKitのDeep Learning Academyは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン4/4です。

「CNN画像分類器を組み立てる」レッスンにはどのくらい時間がかかりますか?

ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。

このDeep Learning Academyレッスンでコードを書いて実行できますか?

はい。すべてのDeep Learning Academyレッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。

このコースのすべてのレッスン

  1. 畳み込み:カーネルをピクセル上で滑らせる
  2. ストライド、パディング、プーリング
  3. チャネル、特徴マップ、受容野
  4. CNN画像分類器を組み立てる
← Deep Learning Academyに戻る