Introduction
Detection models help computers find and label objects in pictures, like spotting cars or people.
import torchvision.models.detection as detection model = detection.fasterrcnn_resnet50_fpn(pretrained=True) model.eval()
import torchvision.models.detection as detection model = detection.fasterrcnn_resnet50_fpn(pretrained=True) model.eval()
import torchvision.models.detection as detection model = detection.maskrcnn_resnet50_fpn(pretrained=True) model.eval()
import torchvision.models.detection as detection model = detection.retinanet_resnet50_fpn(pretrained=True) model.eval()
import torch from PIL import Image import torchvision.transforms as T import torchvision.models.detection as detection # Load a sample image img = Image.open("sample.jpg") # Transform image to tensor transform = T.Compose([T.ToTensor()]) img_tensor = transform(img) # Load pretrained Faster R-CNN model model = detection.fasterrcnn_resnet50_fpn(pretrained=True) model.eval() # Run detection with torch.no_grad(): predictions = model([img_tensor]) # Print detected labels and scores labels = predictions[0]['labels'] scores = predictions[0]['scores'] print("Detected objects and scores:") for label, score in zip(labels, scores): if score > 0.5: print(f"Label: {label.item()}, Score: {score.item():.2f}")
torchvision for finding objects in images?import torch import torchvision model = torchvision.models.detection.fasterrcnn_resnet50_fpn(weights='DEFAULT') model.eval() inputs = [torch.rand(3, 300, 400)] outputs = model(inputs) print(type(outputs))
import torchvision model = torchvision.models.detection.maskrcnn_resnet50_fpn(pretrained=True) model.eval()
Pass the test and this pattern moves unknown