0Pricing
Deep Learning Academy · Ders

Özel Veri Kümesi Sınıfı Yazma

__len__ ve __getitem__ uygulayın.

Özel Veri Kümesi Sınıfı Yazma, CoddyKit'te ücretsiz bir Deep Learning Academy dersidir. Bu, 4 dersinin 1. dersidir. Aşağıdan dersin tamamını ücretsiz okuyabilir, sonra tarayıcıda yerleşik kod editörü ve 7/24 yapay zeka koçu ile uygulamalı olarak pratik yapabilirsin. Bu, Deep Learning Academy öğrenme yolunun bir parçasıdır ve ilerlemeniz web ve CoddyKit uygulaması arasında senkronize olur. Deep Learning Academy kursu toplamda 4 dersten oluşur.

Bu dersin bazı bölümleri henüz çevrilmemiş olup İngilizce olarak gösterilmektedir.

Your Data Needs a Front Door

Before a model can learn, PyTorch needs a clean way to reach your samples one at a time. That front door is a Dataset class. 🚪

Start by Subclassing

You build a custom dataset by subclassing torch.utils.data.Dataset. PyTorch then knows exactly how to ask your object for data.

from torch.utils.data import Dataset

class MyData(Dataset):
    pass

Stash Your Data in __init__

The __init__ method runs once when you create the dataset. Use it to load file paths, arrays, or labels into the object's fields.

def __init__(self, X, y):
    self.X = X
    self.y = y

Two Methods Make It Work

A working dataset only needs two methods: __len__ to report its size and __getitem__ to fetch one sample. That is the whole contract.

__len__ Counts Your Samples

The __len__ method returns how many samples you have. PyTorch reads this to know when an epoch ends and how far an index can go.

def __len__(self):
    return len(self.X)

__getitem__ Returns One Sample

Given an index, __getitem__ returns a single sample, usually a feature and its label. This is where one row of data is handed over.

def __getitem__(self, idx):
    return self.X[idx], self.y[idx]

Return Tensors, Not Lists

__getitem__ should hand back tensors so the model can use them directly. Convert NumPy arrays or Python lists right here if needed.

import torch
x = torch.tensor(self.X[idx], dtype=torch.float32)

Lazy Loading for Big Data

For huge datasets, do not load everything in __init__. Instead read each file inside __getitem__ so only one sample sits in memory at a time.

Apply Transforms Per Sample

__getitem__ is the natural place to apply a transform, like resizing an image. Store the transform in __init__, then call it before returning.

if self.transform:
    x = self.transform(x)

Index It Like a List

Once built, your dataset behaves like a list. Calling len(ds) or ds[0] just triggers the two methods you defined. Test it before training.

ds = MyData(X, y)
print(len(ds), ds[0])

Now It Plugs Into Everything

This tidy interface is why a custom Dataset drops straight into a DataLoader. You write two methods and the rest of PyTorch just works.

Quick Check

Which method does PyTorch call to fetch a single sample by index?

Recap

A custom dataset subclasses Dataset and defines two methods: __len__ for its size and __getitem__ to return one sample. Two methods, full power. 🎉

Sıkça Sorulan Sorular

“Özel Veri Kümesi Sınıfı Yazma” dersi ücretsiz mi?

Evet — “Özel Veri Kümesi Sınıfı Yazma” dersin tüm metni burada web'de ücretsiz olarak okunabilir. Etkileşimli olarak pratik yapmak (yerleşik kod editörü ve 7/24 yapay zeka koçu) ve Deep Learning Academy kursunun geri kalanını açmak için CoddyKit PRO'ya yükselt. Deep Learning Academy kursu toplamda 4 dersten oluşur.

“Özel Veri Kümesi Sınıfı Yazma” dersinde ne öğreneceğim?

__len__ ve __getitem__ uygulayın. Deep Learning Academy ile uygulamalı kodu tarayıcıda doğrudan çalıştırarak pratik yaparsın ve 7/24 yapay zeka koçu dersi çalışırken sorularını yanıtlar.

Deep Learning Academy öğrenmeye başlamak için deneyim gerekli mi?

Önceden deneyim gerekmez. CoddyKit'te Deep Learning Academy, başlangıçtan ileri seviyeye kadar yapılandırıldığı için buradan başlayabilir veya başından başlayıp kendi hızında ilerleme yapabilirsin. Bu, 4 dersinin 1. dersidir.

“Özel Veri Kümesi Sınıfı Yazma” dersi ne kadar sürer?

Çoğu CoddyKit dersi yaklaşık 5–10 dakika sürer. Her biri kısa ve etkileşimli olduğu için sabit ilerleme yaparsın ve web ile uygulama arasında tam olarak bıraktığın yerden devam edebilirsin.

Bu Deep Learning Academy dersinde kod yazıp çalıştırabilir miyim?

Evet. Her Deep Learning Academy dersi yerleşik bir kod editörü içerir, bu sayede tarayıcıda gerçek kod yazıp çalıştırabilir ve anlık yapay zeka geri bildirimi alırsın — yerel kurulum gerekli değildir.

Bu kursun tüm dersleri

  1. Özel Veri Kümesi Sınıfı Yazma
  2. Gruplama, Karıştırma ve num_workers
  3. Değişken Uzunluktaki Girdiler için collate_fn
  4. Girdileri Normalleştirme ve Standartlaştırma
← Deep Learning Academy Sayfasına Dön