Skip to content

Instantly share code, notes, and snippets.

View NumairSayed's full-sized avatar

NUMAIR SAYED NumairSayed

View GitHub Profile
@NumairSayed
NumairSayed / full_network_trainer.py
Created August 3, 2024 14:52
This trains all layers. Architecture: EfficientNetB0. Epochs: 100, optimizer: Stochastic Gradient Descent.Loss fn: Cross Entropy Loss
import torch
import torch.nn as nn
import torch.nn.functional as F
import torchvision.models as models
from torchvision import datasets, transforms
from torch.utils.data import DataLoader, random_split
import os
from PIL import Image, ImageOps
from sklearn.metrics import f1_score, recall_score
@NumairSayed
NumairSayed / 100epochs_densenet201.py
Last active August 1, 2024 22:42
For Abdullah: Changes: 100 epochs, Loss fn changed to negative log likelihood loss, mean and standard deviation changed from generic imagenet values to our dataset specific
import torch
import torch.nn as nn
import torch.nn.functional as F
import torchvision.models as models
from torchvision import datasets, transforms
from torch.utils.data import DataLoader, random_split
import os
from PIL import Image, ImageOps
from sklearn.metrics import f1_score, recall_score
import numpy as np
@NumairSayed
NumairSayed / loader_cum_transformer.py
Last active July 28, 2024 09:44
template to transform with resizing, keeping the aspect ratio preserved and loading my image dataset.
"""
The inference transforms are available at GoogLeNet_Weights.IMAGENET1K_V1.transforms
and perform the following preprocessing operations: Accepts PIL.Image, batched (B, C, H, W)
and single (C, H, W) image torch.Tensor objects.
The images are resized to resize_size=[256] using interpolation=InterpolationMode.
BILINEAR, followed by a central crop of crop_size=[224]. Finally the values are first
rescaled to [0.0, 1.0] and then normalized using mean=[0.485, 0.456, 0.406] and std=[0.229, 0.224, 0.225].
"""
import os
@NumairSayed
NumairSayed / model_inheritance.py
Last active July 28, 2024 08:58
Template to assign pretrained model state to my own model.
import torch
import torchvision.models as models
# Define your model architecture (ensure it matches AlexNet)
class MyAlexNet(torch.nn.Module):
def __init__(self):
super(MyAlexNet, self).__init__()
self.features = torch.nn.Sequential(
torch.nn.Conv2d(3, 64, kernel_size=11, stride=4, padding=2),
torch.nn.ReLU(inplace=True),