0Pricing
Deep Learning Academy · Lección

Construya un clasificador de imágenes CNN

Bloques de convolución, ReLU y pooling para crear un modelo funcional

Construya un clasificador de imágenes CNN es una lección gratuita de Deep Learning Academy en CoddyKit. Esta es la lección 4 de 4. Puedes leer la lección completa abajo gratuitamente — luego la practicas en el navegador con un editor de código integrado y un tutor de IA 24/7. Forma parte de la ruta de aprendizaje de Deep Learning Academy, y tu progreso se sincroniza en la web y la app de CoddyKit. El curso de Deep Learning Academy incluye 4 lecciones en total.

Partes de esta lección aún no han sido traducidas y se muestran en inglés.

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

Preguntas frecuentes

¿La lección «Construya un clasificador de imágenes CNN» es gratis?

Sí — el texto completo de «Construya un clasificador de imágenes CNN» es gratis para leer aquí en la web. Para practicarla de forma interactiva (editor de código integrado y tutor de IA 24/7) y desbloquear el resto del curso de Deep Learning Academy, actualiza a CoddyKit PRO. El curso de Deep Learning Academy incluye 4 lecciones en total.

¿Qué aprenderé en «Construya un clasificador de imágenes CNN»?

Bloques de convolución, ReLU y pooling para crear un modelo funcional Practicas Deep Learning Academy con código real que ejecutas directamente en el navegador, y un tutor de IA 24/7 responde tus preguntas mientras trabajas en la lección.

¿Necesito experiencia previa para empezar Deep Learning Academy?

No se requiere experiencia previa. Deep Learning Academy en CoddyKit está estructurado para principiantes hasta estudiantes avanzados, así que puedes empezar aquí o desde el inicio y avanzar a tu ritmo. Esta es la lección 4 de 4.

¿Cuánto tiempo toma la lección «Construya un clasificador de imágenes CNN»?

La mayoría de las lecciones de CoddyKit toman alrededor de 5–10 minutos. Cada una es compacta e interactiva, así que avanzas constantemente y retomas exactamente por donde dejaste en la web y la app.

¿Puedo escribir y ejecutar código en esta lección de Deep Learning Academy?

Sí. Cada lección de Deep Learning Academy incluye un editor de código integrado, así que escribes y ejecutas código real directamente en tu navegador y obtienes retroalimentación instantánea de IA — sin configuración local necesaria.

Todas las lecciones de este curso

  1. Convolución: los kernels se deslizan sobre los píxeles
  2. Stride, padding y pooling
  3. Canales, mapas de características y campos receptivos
  4. Construya un clasificador de imágenes CNN
← Volver a Deep Learning Academy