Rakit Pengklasifikasi Gambar CNN
Gabungkan blok Conv-ReLU-pool menjadi model yang berfungsi
Rakit Pengklasifikasi Gambar CNN adalah pelajaran Deep Learning Academy gratis di CoddyKit. Ini adalah pelajaran 4 dari 4. Kamu bisa membaca pelajaran lengkapnya di bawah secara gratis — lalu praktikkan langsung di browser dengan editor kode bawaan dan tutor AI 24/7. Ini adalah bagian dari jalur belajar Deep Learning Academy, dan progresmu tersinkronisasi di web dan aplikasi CoddyKit. Kursus Deep Learning Academy mencakup 4 pelajaran total.
Bagian dari pelajaran ini belum diterjemahkan dan ditampilkan dalam bahasa Inggris.
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 = headWrite 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. 🎉
Pertanyaan yang Sering Diajukan
Apakah pelajaran “Rakit Pengklasifikasi Gambar CNN” gratis?
Ya — teks lengkap “Rakit Pengklasifikasi Gambar CNN” gratis dibaca di sini di web. Untuk praktiknya secara interaktif (editor kode bawaan dan tutor AI 24/7) dan buka sisa kursus Deep Learning Academy, upgrade ke CoddyKit PRO. Kursus Deep Learning Academy mencakup 4 pelajaran total.
Apa yang akan aku pelajari di “Rakit Pengklasifikasi Gambar CNN”?
Gabungkan blok Conv-ReLU-pool menjadi model yang berfungsi Kamu berlatih Deep Learning Academy dengan kode praktik yang langsung kamu jalankan di browser, dan tutor AI 24/7 menjawab pertanyaanmu saat kamu mengerjakan pelajaran ini.
Apakah aku perlu pengalaman untuk memulai Deep Learning Academy?
Tidak diperlukan pengalaman sebelumnya. Deep Learning Academy di CoddyKit dirancang untuk pemula hingga pelajar tingkat lanjut, jadi kamu bisa memulai di sini atau dari awal dan belajar sesuai kecepatan kamu sendiri. Ini adalah pelajaran 4 dari 4.
Berapa lama pelajaran “Rakit Pengklasifikasi Gambar CNN” memakan waktu?
Sebagian besar pelajaran CoddyKit memakan waktu sekitar 5–10 menit. Setiap pelajaran ringkas dan interaktif, jadi kamu membuat kemajuan stabil dan melanjutkan dari tempat kamu tinggalkan di web dan aplikasi.
Bisakah aku menulis dan menjalankan kode dalam pelajaran Deep Learning Academy ini?
Ya. Setiap pelajaran Deep Learning Academy menyertakan editor kode bawaan, jadi kamu menulis dan menjalankan kode nyata langsung di browser dan mendapatkan umpan balik AI instan — tidak diperlukan penyiapan lokal.
Semua pelajaran dalam kursus ini
- Konvolusi: Kernel Meluncur di Atas Piksel
- Stride, Padding, dan Pooling
- Kanal, Peta Fitur, dan Medan Reseptif
- Rakit Pengklasifikasi Gambar CNN