From pixel to prediction -- these memory tricks lock in CNNs, object detection, image segmentation, generative vision models, and the architectures that gave machines the ability to see.
Or continue to the sub-topics below for more specialized Study Rooms and Forums
Proven Mnemonics & Acronyms — fast to learn, hard to forget.
import torchvision.models as models
resnet = models.resnet50(pretrained=True)
# Freeze early layers (universal features)
for param in list(resnet.parameters())[:-10]:
param.requires_grad = False
# Only train the final layers on your taskimport torchvision.models as models
resnet = models.resnet50(pretrained=True)
# Freeze early layers (universal features)
for param in list(resnet.parameters())[:-10]:
param.requires_grad = False
# Only train the final layers on your taskdef iou(box1, box2):
x1 = max(box1[0], box2[0]); y1 = max(box1[1], box2[1])
x2 = min(box1[2], box2[2]); y2 = min(box1[3], box2[3])
intersection = max(0, x2-x1) * max(0, y2-y1)
union = (box1[2]-box1[0])*(box1[3]-box1[1]) + (box2[2]-box2[0])*(box2[3]-box2[1]) - intersection
return intersection / uniondef iou(box1, box2):
x1 = max(box1[0], box2[0]); y1 = max(box1[1], box2[1])
x2 = min(box1[2], box2[2]); y2 = min(box1[3], box2[3])
intersection = max(0, x2-x1) * max(0, y2-y1)
union = (box1[2]-box1[0])*(box1[3]-box1[1]) + (box2[2]-box2[0])*(box2[3]-box2[1]) - intersection
return intersection / union# Discriminative: classify an image
from torchvision import models, transforms
model = models.resnet50(pretrained=True); model.eval()
# Generative: create an image from text
from diffusers import StableDiffusionPipeline
pipe = StableDiffusionPipeline.from_pretrained("runwayml/stable-diffusion-v1-5")# Discriminative: classify an image
from torchvision import models, transforms
model = models.resnet50(pretrained=True); model.eval()
# Generative: create an image from text
from diffusers import StableDiffusionPipeline
pipe = StableDiffusionPipeline.from_pretrained("runwayml/stable-diffusion-v1-5")# NMS in torchvision
from torchvision.ops import nms
import torch
boxes = torch.tensor([[100,100,200,200],[105,105,205,205]], dtype=torch.float)
scores = torch.tensor([0.9, 0.75])
keep = nms(boxes, scores, iou_threshold=0.5)
# Returns indices of boxes to keep# NMS in torchvision
from torchvision.ops import nms
import torch
boxes = torch.tensor([[100,100,200,200],[105,105,205,205]], dtype=torch.float)
scores = torch.tensor([0.9, 0.75])
keep = nms(boxes, scores, iou_threshold=0.5)
# Returns indices of boxes to keep