0Pricing
Deep Learning Academy · Lektion

Einen CNN-Bildklassifikator zusammensetzen

Conv-ReLU-Pool-Blöcke zu einem funktionierenden Modell verbinden.

Einen CNN-Bildklassifikator zusammensetzen ist eine kostenlose Deep Learning Academy-Lektion auf CoddyKit. Dies ist Lektion 4 von 4. Du kannst die komplette Lektion unten kostenlos lesen – dann übst du sie direkt im Browser mit einem integrierten Code-Editor und einem KI-Tutor rund um die Uhr. Sie ist Teil des Deep Learning Academy-Lernpfads, und dein Fortschritt wird über Web und CoddyKit-App synchronisiert. Der Deep Learning Academy-Kurs umfasst insgesamt 4 Lektionen.

Teile dieser Lektion wurden noch nicht übersetzt und werden auf Englisch angezeigt.

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. 🎉

Häufig gestellte Fragen

Ist die Lektion „Einen CNN-Bildklassifikator zusammensetzen“ kostenlos?

Ja — der vollständige Text von „Einen CNN-Bildklassifikator zusammensetzen“ ist hier im Web kostenlos zu lesen. Um sie interaktiv zu üben (integrierter Code-Editor und 24/7 KI-Tutor) und den Rest des Deep Learning Academy-Kurses freizuschalten, upgrade auf CoddyKit PRO. Der Deep Learning Academy-Kurs umfasst insgesamt 4 Lektionen.

Was lerne ich in „Einen CNN-Bildklassifikator zusammensetzen“?

Conv-ReLU-Pool-Blöcke zu einem funktionierenden Modell verbinden. Du übst Deep Learning Academy mit praktischem Code, den du direkt im Browser ausführst, und ein 24/7 KI-Tutor beantwortet deine Fragen während du die Lektion bearbeitest.

Brauche ich Erfahrung, um Deep Learning Academy zu starten?

Keine Vorkenntnisse erforderlich. Deep Learning Academy auf CoddyKit ist für Anfänger bis fortgeschrittene Lernende strukturiert, sodass du hier starten oder von Anfang an beginnen und in deinem eigenen Tempo voranschreiten kannst. Dies ist Lektion 4 von 4.

Wie lange dauert die Lektion „Einen CNN-Bildklassifikator zusammensetzen“?

Die meisten CoddyKit-Lektionen dauern etwa 5–10 Minuten. Jede ist kompakt und interaktiv, sodass du stetig Fortschritte machst und genau dort weitermachst, wo du aufgehört hast – im Web und in der App.

Kann ich in dieser Deep Learning Academy-Lektion Code schreiben und ausführen?

Ja. Jede Deep Learning Academy-Lektion enthält einen integrierten Code-Editor, sodass du echten Code direkt in deinem Browser schreibst und ausführst und sofort KI-Feedback erhältst — ohne lokale Einrichtung erforderlich.

Alle Lektionen in diesem Kurs

  1. Konvolution: Kernel gleiten über Pixel
  2. Stride, Padding und Pooling
  3. Channels, Feature Maps und rezeptive Felder
  4. Einen CNN-Bildklassifikator zusammensetzen
← Zurück zu Deep Learning Academy