পাঠ ২৪ · ৪০-এর মধ্যে · মডিউল ৩

Data Augmentation

Data augmentation — multiplying small datasets
৬ মিনিট পড়া মাঝারি · Intermediate PyTorch hands-on

এই পাঠে যা শিখবেন

  • Data augmentation-এর intuition — কেন regularize করে
  • Standard transforms — flip, crop, rotate, color jitter
  • Modern advanced — MixUp, CutMix, RandAugment, AutoAugment
  • Test-time augmentation (TTA)
  • Domain-specific augmentation (medical, satellite, Bangla text)
  • PyTorch torchvision ও Albumentations library

১ · Data augmentation — কেন

একটি বিড়ালের ছবি — উলটা ফ্লিপ করলেও বিড়াল। ঘুরালেও বিড়াল। একটু crop করলেও বিড়াল। Class-label invariant এই transformations দিয়ে — একই image থেকে অনেক "নতুন" সমান-label image।

  • Effective dataset: $N$ image, $K$ augmentation = $N \times K$ training samples।
  • Overfitting reduce: network-কে memorize করার সুযোগ কম।
  • Invariance শেখা: "এই transformation-এ class একই" — explicitly শেখায়।
  • Robustness: test-এ image-এর variation handle।
Augmentation rule

Transform $T$ — augmentation valid যদি class-label invariant হয়:
$$f^*(T(x)) = f^*(x)$$
যেখানে $f^*$ — true class function।

সাবধানতা: sometimes transform label-changing। যেমন — "৬" কে ১৮০° ঘুরালে "৯" হয়। Domain-aware augmentation choice critical।

২ · Standard image augmentations

  • Horizontal flip: বেশিরভাগ natural image-এ valid (বিড়াল, ফুল, গাড়ি)। চরিত্র বা text-এ NOT।
  • Random crop: object-এর different angle/position। Resize + crop।
  • Random rotation: ±15° সাধারণত safe। বেশি — class change risk।
  • Color jitter: brightness, contrast, saturation, hue — lighting variation।
  • Gaussian noise: sensor noise simulate।
  • Random erasing: patch erase — occlusion robustness।
ভাবুন আপনি একজন child-কে বিড়াল চিনতে শেখাচ্ছেন। একই বিড়ালের ছবি ১০০০ বার দেখানোর চেয়ে — বিভিন্ন angle, light, distance, partial visibility-তে দেখালে সে ভাল শিখবে। Data augmentation ঠিক একই — "একই বিড়াল, ভিন্ন দৃশ্যকল্প"।

৩ · PyTorch torchvision transforms

Python · torchvision
import torchvision.transforms as T

train_transform = T.Compose([
    T.Resize(256),
    T.RandomResizedCrop(224, scale=(0.7, 1.0)),
    T.RandomHorizontalFlip(p=0.5),
    T.RandomRotation(15),
    T.ColorJitter(brightness=0.3, contrast=0.3,
                  saturation=0.3, hue=0.1),
    T.RandomGrayscale(p=0.1),
    T.ToTensor(),
    T.Normalize([0.485, 0.456, 0.406],
                [0.229, 0.224, 0.225]),
    T.RandomErasing(p=0.3),
])

# Validation/test — minimal
val_transform = T.Compose([
    T.Resize(256),
    T.CenterCrop(224),
    T.ToTensor(),
    T.Normalize([0.485, 0.456, 0.406],
                [0.229, 0.224, 0.225]),
])

    

৪ · MixUp — labels-ও mix

Zhang et al. (২০১৭) — দু'টো image-কে interpolate করুন, label-ও interpolate:

$$\tilde{x} = \lambda x_i + (1 - \lambda) x_j$$ $$\tilde{y} = \lambda y_i + (1 - \lambda) y_j$$

$\lambda \sim \text{Beta}(\alpha, \alpha)$ — typically $\alpha = 0.2$।

Python · MixUp
import numpy as np
import torch

def mixup_batch(x, y, alpha=0.2):
    lam = np.random.beta(alpha, alpha)
    idx = torch.randperm(x.size(0))
    x_mixed = lam * x + (1 - lam) * x[idx]
    return x_mixed, y, y[idx], lam

def mixup_loss(loss_fn, pred, y_a, y_b, lam):
    return lam * loss_fn(pred, y_a) + (1 - lam) * loss_fn(pred, y_b)

# Usage
x_mix, y_a, y_b, lam = mixup_batch(x, y, alpha=0.2)
pred = model(x_mix)
loss = mixup_loss(criterion, pred, y_a, y_b, lam)

    

৫ · CutMix — patch swap

Yun et al. (২০১৯) — একটি image-এর patch দ্বিতীয় image থেকে নেয়া। Label proportional area ratio। MixUp-এর চেয়ে স্বাভাবিক।

Python · CutMix
def cutmix_batch(x, y, alpha=1.0):
    lam = np.random.beta(alpha, alpha)
    idx = torch.randperm(x.size(0))
    H, W = x.size(2), x.size(3)
    cut_rat = np.sqrt(1 - lam)
    cw, ch = int(W * cut_rat), int(H * cut_rat)
    cx, cy = np.random.randint(W), np.random.randint(H)
    x1 = max(cx - cw // 2, 0); x2 = min(cx + cw // 2, W)
    y1 = max(cy - ch // 2, 0); y2 = min(cy + ch // 2, H)
    x[:, :, y1:y2, x1:x2] = x[idx, :, y1:y2, x1:x2]
    lam = 1 - ((x2 - x1) * (y2 - y1) / (W * H))
    return x, y, y[idx], lam

    
Data Augmentation — single image, multiple training samples Original → flip / crop / rotate / color / MixUp / CutMix Original cat (1.0) Flip cat (1.0) Rotate 15° cat (1.0) Color Jitter cat (1.0) MixUp cat (0.6) + dog (0.4) Augmentation pipeline ১. Resize (256) ২. Random Crop (224 × 224) ৩. Horizontal Flip (50%) ৪. Color Jitter, Rotation ৫. Normalize (ImageNet stats) প্রতি epoch — ভিন্ন augmentation, "infinite" virtual data।
Data augmentation — একই original image থেকে multiple "different" training sample। Class label preserved (MixUp ছাড়া)।

৬ · RandAugment ও AutoAugment

Hand-designed augmentation pipeline tedious। Cubuk et al. (Google) — automated approach:

  • AutoAugment (২০১৮): reinforcement learning দিয়ে best augmentation policy search।
  • RandAugment (২০২০): simple — random $N$ ops with magnitude $M$।
  • Both — significant accuracy gain, hyperparameter কম।
Python · RandAugment
from torchvision.transforms import RandAugment

train_transform = T.Compose([
    T.Resize(256),
    T.RandomResizedCrop(224),
    T.RandomHorizontalFlip(),
    RandAugment(num_ops=2, magnitude=9),  # ✨
    T.ToTensor(),
    T.Normalize([0.485, 0.456, 0.406],
                [0.229, 0.224, 0.225]),
])

    

৭ · Albumentations — production library

torchvision-এর চেয়ে fast (numpy-based) ও richer transforms। Detection ও segmentation-এ bbox/mask sync support।

Python · Albumentations
import albumentations as A
from albumentations.pytorch import ToTensorV2

transform = A.Compose([
    A.Resize(256, 256),
    A.RandomResizedCrop(224, 224, scale=(0.7, 1.0)),
    A.HorizontalFlip(p=0.5),
    A.OneOf([
        A.GaussianBlur(blur_limit=3, p=0.5),
        A.MotionBlur(blur_limit=5, p=0.5),
    ], p=0.3),
    A.HueSaturationValue(20, 30, 20, p=0.3),
    A.RandomBrightnessContrast(0.2, 0.2, p=0.5),
    A.GaussNoise(var_limit=(10, 50), p=0.3),
    A.Normalize([0.485, 0.456, 0.406],
                [0.229, 0.224, 0.225]),
    ToTensorV2(),
])

# image — numpy uint8 H×W×C
out = transform(image=image)
x = out['image']  # tensor

    

৮ · Test-Time Augmentation (TTA)

Test-এ-ও augmentation। Multiple augmented version-এর prediction average — accuracy boost।

Python · TTA
def predict_tta(model, image, n_aug=5):
    model.eval()
    preds = []
    with torch.no_grad():
        # Original
        preds.append(F.softmax(model(image), dim=-1))
        # Horizontal flip
        preds.append(F.softmax(model(torch.flip(image, [3])), dim=-1))
        # Multiple crops
        for _ in range(n_aug - 2):
            x_aug = random_crop_resize(image)
            preds.append(F.softmax(model(x_aug), dim=-1))
    return torch.stack(preds).mean(0)

    

৯ · Domain-specific augmentation

  • Medical imaging: elastic deformation (organ stretch), intensity shift। Rotation/flip — domain-aware।
  • Satellite: rotation arbitrary, multispectral channel mix।
  • Bangla text/character: flip ❌ (mirror character বদলায়), rotation small।
  • Face: horizontal flip ✓, vertical flip ❌।
  • Drone/aerial: aggressive rotation, 4-image Mosaic।
Augmentation domain-specific। Bangla "৬" — flip করলে "৯" হয়, label বদলায়। Image-এর invariance বুঝা ছাড়া augmentation ভুল class শেখায়। সবসময় domain expert-এর সাথে discussion।

ভাবনার প্রশ্ন

প্রতিটি প্রশ্ন নিজে কিছুক্ষণ ভাবুন — তারপর "→ উত্তর" চাপুন।

প্র ০১ "MixUp — অস্বাভাবিক image, label fractional"। কেন তবু network ভাল শেখে? Theoretical interpretation কী?

MixUp — counter-intuitive কিন্তু empirically powerful। Multiple theoretical perspective।

Vicinal risk minimization:

  • Standard ERM — sample point-এ optimize।
  • VRM — sample-এর neighborhood-এ optimize।
  • MixUp — linear neighborhood সংজ্ঞা।
  • Smooth decision boundary।

Linear interpolation interpretation:

  • $\tilde{x} = \lambda x_i + (1-\lambda) x_j$।
  • Class boundary linear hint।
  • Network linearly interpolate predict।
  • Smooth manifold encourage।

Regularization view:

  • Network noisy label train।
  • Confidence reduce।
  • Calibration improve।
  • Memorization prevent।

Adversarial robustness:

  • MixUp-trained network — adversarial attack-এ robust।
  • Decision boundary far from data points।
  • Implicit max-margin।

Feature smoothness:

  • Embedding space smooth।
  • Classes linearly separable।
  • Better generalization।

Empirical benefits:

  • ImageNet — ResNet-50 +1.5% accuracy।
  • CIFAR — significant boost।
  • NLP — text mixing too works।
  • Multi-modal applicable।

Hyperparameter $\alpha$:

  • $\alpha = 0$ — no MixUp।
  • $\alpha = 1.0$ — uniform interpolation।
  • $\alpha = 0.2$ — typical, slight blending।
  • $\alpha \to \infty$ — $\lambda = 0.5$ always।

Variants:

  • Manifold MixUp: hidden layer-এ mix।
  • CutMix: spatial patch mix।
  • AugMix: diverse augmentation chain।
  • FMix: Fourier-domain mask।

When MixUp helps most:

  • Small/medium dataset।
  • Class imbalance।
  • Noisy labels।
  • Strong overfitting tendency।

When MixUp hurts:

  • Very small data (under 100/class)।
  • Domain where mixing meaningless (text, structured data)।
  • Already strong augmentation।
  • Fine-grained classification।

Modern NLP — MixUp:

  • Word/sentence embedding mix।
  • Attention scores mix।
  • Text classification regularization।

Bangladesh applications:

  • Bangla character recognition — MixUp at hidden layer।
  • Medical imaging — disease detection।
  • Crop disease classification।
  • Sentiment classification।

Implementation tip:

  • Validation — no MixUp।
  • Loss adjusted (linear combination)।
  • Combine standard augmentation।
  • $\alpha = 0.2$ default।

Theoretical depth:

  • Zhang-Cisse-Dauphin-Lopez-Paz (২০১৭) original।
  • Multiple follow-up theoretical paper।
  • Connections to data augmentation theory।
  • Active research।

মূল উপলব্ধি: MixUp — counter-intuitive কিন্তু theoretically grounded। Vicinal risk + linear smoothness + adversarial robust। Standard augmentation-এর সাথে combine — strong। Bangladesh-এ small data scenario — particularly useful। ML-এ "irrational" idea sometimes most effective। Empirical exploration encourage।

প্র ০২ RandAugment বনাম AutoAugment — কোনটা better? Why simple beat learned?

RandAugment-এর simplicity beat AutoAugment — DL-এ "simpler often better" lesson।

AutoAugment (২০১৮):

  • RL-based search — best augmentation policy।
  • Sub-policy: 5-stage augmentation chain।
  • Search space — operations + magnitudes।
  • 15,000 GPU hour search!
  • Per-dataset optimal।

RandAugment (২০২০):

  • $N$ random ops, magnitude $M$।
  • No search — 2 hyperparameter total।
  • Simple grid search।
  • Compute negligible।
  • Per-dataset tune $N, M$।

Why RandAugment beats:

  • Search space too big — local optima।
  • Random sufficient diversity।
  • Tuning effort — practitioner ROI।
  • Reproducibility better।

Empirical comparison:

  • ImageNet — RandAugment ~ AutoAugment।
  • CIFAR — same।
  • Compute — 1000x less।
  • Easy adoption।

RandAugment hyperparameters:

  • $N$: number ops applied (1-3 typical)।
  • $M$: magnitude (0-30 scale, 7-15 typical)।
  • Larger model — bigger M helpful।
  • Larger data — bigger M too।

Implementation:

from torchvision.transforms import RandAugment

# Default values
ra = RandAugment(num_ops=2, magnitude=9)

# Apply to PIL image
augmented = ra(pil_image)

Available operations:

  • Identity, AutoContrast, Equalize, Rotate।
  • Solarize, Color, Contrast, Brightness, Sharpness।
  • ShearX, ShearY, TranslateX, TranslateY।
  • Posterize।

Why "learned" augmentation overhyped:

  • Search overhead massive।
  • Improvement marginal vs random।
  • Practical adoption barrier।
  • "AutoML" tendency — over-engineering।

TrivialAugment (২০২১):

  • Single random op, random magnitude।
  • Even simpler!
  • Comparable performance।
  • Müller-Hutter paper।

Lesson — Occam's razor in ML:

  • Simple methods often surprisingly strong।
  • Complex methods marginal gain often।
  • Engineering cost matters।
  • Reproducibility valued।

Domain-specific:

  • Medical — domain-aware ops add।
  • Bangla text — character-specific care।
  • Audio — different op set।
  • Customize, not search।

RandAugment for transfer learning:

  • Pretrained model + RandAugment — strong।
  • Magnitude moderate (M=5-9)।
  • Standard recipe।

Bangladesh adoption:

  • Default — RandAugment।
  • 2 hyperparameter — easy tune।
  • Strong baseline immediately।
  • Compute-friendly।

Modern best practice:

  • RandAugment + horizontal flip + RandomErasing।
  • MixUp/CutMix for additional gain।
  • Domain-specific tweak।
  • Hyperparameter tune।

Failure modes:

  • Magnitude too high — performance drop।
  • Inappropriate ops (text vertical flip)।
  • Augmentation excess — under-fit।

মূল উপলব্ধি: RandAugment beat AutoAugment — simplicity > learned policy। 2 hyperparameter — tune easy। 15K GPU hour search avoid। Bangladesh practical adoption easier। ML "Occam's razor" — সরল idea অসহায় powerful। Engineering cost reproducibility critical। Default recipe modern training pipeline।

প্র ০৩ Bangla character recognition-এ horizontal flip কি? "৬" → flip → অন্য অর্থ। Domain-specific augmentation কীভাবে design করবেন?

Bangla script-এ augmentation careful। Symmetry assumption ভেঙে যায় — character semantic বদলায়।

Bangla script peculiarity:

  • Character — left-right asymmetric।
  • Conjunct character (যুক্তাক্ষর) — complex structure।
  • Vowel modifier (kar) — directional।
  • Numeric ০-৯ — unique shape।

Standard augmentation problem:

  • Horizontal flip — "ক" → mirror character (different meaning)।
  • Vertical flip — meaningless in Bangla।
  • 180° rotation — "৬" → "৯" issue।
  • Random rotation large — lossy।

Bangla-safe augmentations:

  • Translation: ±5-10 pixel — position invariance।
  • Small rotation: ±5° (limit slight variation)।
  • Scale: 0.9-1.1 — handwriting size variation।
  • Brightness/contrast: mild — paper variation।
  • Gaussian noise: sensor variation।
  • Elastic deformation: handwriting style।

Bangla-unsafe:

  • Horizontal flip ❌
  • Vertical flip ❌
  • Large rotation ❌
  • Severe shear ❌

Recommended pipeline:

import albumentations as A

bangla_safe = A.Compose([
    A.Resize(40, 40),
    A.RandomCrop(32, 32),
    A.Rotate(limit=5, p=0.5),  # very limited
    A.Affine(translate_percent={'x': 0.1, 'y': 0.1},
             scale=(0.9, 1.1),
             p=0.5),
    A.ElasticTransform(alpha=1, sigma=5, p=0.3),
    A.GaussNoise(var_limit=(5, 15), p=0.3),
    A.RandomBrightnessContrast(0.2, 0.2, p=0.3),
    A.Normalize(mean=0.5, std=0.5),
    ToTensorV2(),
])

Synthetic data generation:

# Bangla font diverse — synthetic data
from PIL import Image, ImageFont, ImageDraw
import random

bangla_fonts = [
    "Kalpurush.ttf", "Nikosh.ttf",
    "Ekushey-Lohit.ttf", "MitraMono.ttf",
]

def generate_bangla_char(char, size=32):
    font_path = random.choice(bangla_fonts)
    font = ImageFont.truetype(font_path, size)
    img = Image.new('L', (size, size), 255)
    draw = ImageDraw.Draw(img)
    draw.text((random.randint(-2, 2),
               random.randint(-2, 2)),
              char, fill=0, font=font)
    return img

Class-specific augmentation:

  • "৬" vs "৯" — separate strict augmentation।
  • Confused pair — careful।
  • Conjunct vs simple — different range।

Conjunct character handling:

  • Variable size — adaptive crop।
  • Multiple components — preserve।
  • Recognition harder — more augmentation।

Real-world data variation:

  • Handwriting — elastic deform।
  • Print — clean, less aug।
  • Scanned — JPEG artifact, blur।
  • Mobile photo — perspective, light।

MixUp Bangla concerns:

  • Two character mix — meaningless visual।
  • Embedding-level MixUp better।
  • Manifold MixUp helpful।
  • Test before adopting।

OCR-specific:

  • Random crop sequence preserve।
  • Background augment — paper texture।
  • Color/grayscale conversion।
  • Resolution variation।

Validation strategy:

  • Augmentation effect measure individually।
  • Combination tune।
  • Holdout — pure data validation।
  • Real-world test critical।

Bangla-specific challenges:

  • Limited labeled data।
  • Handwriting variation extreme।
  • Compound character complexity।
  • Font diversity scarce।

Synthetic data generation:

  • Multiple Bangla font।
  • Random background।
  • Distortion simulate।
  • Augment further on synthetic।

Active learning:

  • Confused predictions — manual label।
  • Real handwriting samples।
  • Iterative dataset growth।
  • Quality > quantity।

Validation real-world:

  • Bangladesh different region handwriting।
  • Education level variation।
  • Age group difference।
  • Test set diverse।

মূল উপলব্ধি: Bangla character augmentation — domain-specific care। Standard ImageNet augmentation copy-paste — fail। "৬"-"৯" issue, flip dangers। Safe set: small rotation, translation, scale, elastic deform। Synthetic data + real handwriting + careful aug — Bangla OCR success। Cultural/script awareness — ML quality determinant।

প্র ০৪ Bangladesh agriculture-এ crop disease detection — drone image, 2000 labeled sample। Augmentation strategy কী?

Crop disease + drone image + small data — Bangladesh-এর realistic agri-tech project।

Domain analysis:

  • Drone aerial — top-down view।
  • Disease — leaf-level pattern।
  • Multi-scale — close + distant।
  • Lighting — sun, shadow, time।
  • Crop variety — Boro, Aman, Aush।

Disease pattern variation:

  • Brown spot — discoloration patch।
  • Stem borer — visible damage।
  • Leaf hopper — yellowing।
  • Blast — fungal lesion।

Augmentation challenges:

  • 2000 sample — augmentation crucial।
  • Class imbalance — some disease rare।
  • Real-world variation — extreme।
  • Labeling noise possible।

Recommended pipeline:

import albumentations as A

train_transform = A.Compose([
    # Spatial - drone aerial flexibility
    A.Resize(640, 640),
    A.RandomResizedCrop(512, 512,
                         scale=(0.5, 1.0)),
    A.HorizontalFlip(p=0.5),
    A.VerticalFlip(p=0.5),  # aerial — okay
    A.RandomRotate90(p=0.5),
    A.Rotate(limit=45, p=0.5),

    # Lighting - field variation
    A.RandomBrightnessContrast(
        brightness_limit=0.3,
        contrast_limit=0.3, p=0.7),
    A.HueSaturationValue(
        hue_shift_limit=20,
        sat_shift_limit=30,
        val_shift_limit=20, p=0.5),

    # Weather - Bangladesh monsoon
    A.OneOf([
        A.RandomRain(p=0.5),
        A.RandomFog(p=0.5),
        A.RandomShadow(p=0.5),
    ], p=0.3),

    # Quality - drone variation
    A.OneOf([
        A.GaussianBlur(blur_limit=5, p=0.5),
        A.MotionBlur(blur_limit=7, p=0.5),
        A.Defocus(p=0.3),
    ], p=0.3),

    # Noise
    A.GaussNoise(var_limit=(10, 50), p=0.3),
    A.ISONoise(p=0.3),

    # Disease-relevant
    A.ChannelShuffle(p=0.1),  # Carefully
    A.Normalize(),
    ToTensorV2(),
])

Mosaic augmentation (YOLOv4):

def mosaic_4(images, bboxes, size=512):
    """4 image combine in 2x2 grid"""
    canvas = np.zeros((size, size, 3), dtype=np.uint8)
    cx, cy = np.random.randint(size//4, 3*size//4)
    for idx, (img, bb) in enumerate(zip(images, bboxes)):
        # Place each image in quadrant
        if idx == 0:  # top-left
            x1a, y1a, x2a, y2a = 0, 0, cx, cy
        elif idx == 1:  # top-right
            x1a, y1a, x2a, y2a = cx, 0, size, cy
        elif idx == 2:  # bottom-left
            x1a, y1a, x2a, y2a = 0, cy, cx, size
        else:  # bottom-right
            x1a, y1a, x2a, y2a = cx, cy, size, size
        canvas[y1a:y2a, x1a:x2a] = resize(img,
            (y2a - y1a, x2a - x1a))
    return canvas

Class balance:

from torch.utils.data import WeightedRandomSampler

class_counts = compute_per_class()
weights = 1.0 / np.sqrt(class_counts)  # sqrt smooth
sample_weights = weights[targets]
sampler = WeightedRandomSampler(
    sample_weights,
    len(sample_weights),
    replacement=True)

MixUp + CutMix combined:

  • 50% standard augmentation।
  • 25% MixUp।
  • 25% CutMix।
  • Diversity maximize।

Synthetic data:

  • GAN-based generation।
  • Style transfer healthy → disease।
  • Limited but supplementary।
  • Validate real-world transfer।

Test-time augmentation:

def tta_disease(model, image, n=8):
    preds = []
    for _ in range(n):
        # Different augmentation
        x_aug = drone_test_aug(image)
        with torch.no_grad():
            preds.append(F.softmax(model(x_aug), -1))
    return torch.stack(preds).mean(0)

Bangladesh-specific augmentations:

  • Monsoon rain: A.RandomRain — common scenario।
  • Hot sun: brightness extreme।
  • Dust: low contrast।
  • Crop stage: growth phase variation।

Validation strategy:

  • Field-wise hold-out।
  • Season-wise split।
  • Variety-wise generalization।
  • Real-world deployment test।

Domain expert validation:

  • Agronomist review augmentation।
  • Visually inspect synthetic।
  • Disease-specific consistency।
  • False positive analysis।

Practical deployment:

  • Drone onboard inference।
  • Bangla farmer app।
  • GPS-tagged disease map।
  • Treatment recommendation।

Continuous improvement:

  • New season — new data।
  • New disease emergence track।
  • Active learning loop।
  • Regional adaptation।

Edge cases:

  • Mixed disease (multiple)।
  • Early-stage subtle।
  • Healthy crop confusion (autumn yellowing)।
  • Weather damage vs disease।

Dataset growth:

  • Crowdsource farmer photo।
  • University research collaboration।
  • BARI (Bangladesh Agricultural Research Institute) partnership।
  • Open dataset contribution।

Realistic expectation:

  • 2000 sample — 75-85% achievable।
  • With ensemble + TTA — 88%।
  • 10000 sample target — 95%+।
  • Production threshold — 90%।

Economic impact:

  • Early detection — yield save।
  • Targeted spray — pesticide reduce।
  • Cost — farmer benefit।
  • Sustainable agriculture।

মূল উপলব্ধি: Crop disease detection — augmentation extensive use। Drone-aware (rotation, vertical flip ok), weather-aware (rain, fog), quality-aware (blur)। Mosaic + MixUp + CutMix combined। Bangladesh-এ — monsoon, sun, dust simulate। Active learning + farmer crowdsource। 2000 sample augmentation দিয়ে production-quality achievable। Domain-specific aug — ML practical impact। Agriculture AI Bangladesh transformation potential।

অনুশীলন

  1. Pipeline build: torchvision-এ একটি training pipeline — RandAugment, RandomHorizontalFlip, ColorJitter, RandomErasing।
    import torchvision.transforms as T
    train_t = T.Compose([
        T.Resize(256),
        T.RandomResizedCrop(224),
        T.RandomHorizontalFlip(p=0.5),
        T.RandAugment(num_ops=2, magnitude=9),
        T.ColorJitter(0.2, 0.2, 0.2, 0.1),
        T.ToTensor(),
        T.Normalize([0.485, 0.456, 0.406],
                    [0.229, 0.224, 0.225]),
        T.RandomErasing(p=0.3),
    ])
  2. MixUp implement: dataset একটি batch-এ MixUp apply ও loss compute।
    import numpy as np
    
    def mixup(x, y, alpha=0.2):
        lam = np.random.beta(alpha, alpha)
        idx = torch.randperm(x.size(0))
        x = lam * x + (1 - lam) * x[idx]
        return x, y, y[idx], lam
    
    x_m, y_a, y_b, lam = mixup(x, y, 0.2)
    pred = model(x_m)
    loss = lam * F.cross_entropy(pred, y_a) + \
           (1 - lam) * F.cross_entropy(pred, y_b)
  3. Domain check: "৬" Bangla digit-এর জন্য কোন augmentations safe, কোনগুলো না — তালিকা।

    Safe: small translation (±10%), small rotation (±5°), scale (0.9-1.1), elastic (handwriting), brightness/contrast, gaussian noise।

    Not safe: horizontal flip (mirror char), vertical flip (meaningless), 180° rotation ("৬" → "৯"), large rotation (label change), severe shear।

আরও পড়ুন · ABCL TECH-এ আপনার পরবর্তী পদক্ষেপ

কোড রানার কাজ না করলে? ব্রাউজারে কাজ না করলে Google Colab ব্যবহার করুন — Google-এর ফ্রি অনলাইন Python পরিবেশ, শুধু Gmail অ্যাকাউন্ট লাগে।
পূর্ববর্তী পাঠ
পাঠ ২৩ · Transfer learning