留学生考试辅导

Part 0: Dataloader and Visualizations¶

Copyright By PowCoder代写 加微信 powcoder

import torch
import wandb
import scipy.io

import numpy as np

import torch.nn as nn
import torch.nn.functional as F
import torchvision.models as models
from torchvision import transforms, datasets
from torch.utils.data import DataLoader

from voc_dataset import VOCDataset

from PIL import Image

from utils import *

USE_WANDB = False

Editing the Dataloader¶
The first part of the assignment involves editing the dataloader so that we can access bounding-box proposals as well as the ground-truth bounding boxes. The ground truth bounding box can be accessed through the VOC Dataset annotations itself. Unsupervised bounding box proposals are obtained through methods such as Selective Search.

Since Selective Search is slow to run on each image, we have pre-computed the bounding box proposals. You should be able to access the .mat files using scipy.io.loadmat(‘file.mat’). Feel free to experiment with the data in the files to figure out the number of proposals per image, their scores, etc.

Your task is to change the dataloader to obtain the ground-truth bounding boxes, as well as the proposed bounding boxes for each image. Returning a dictionary would be convenient here. For the bounding boxes, using the relative positions is usually a better idea since they are invariant to changes in the size of the image.

# Load the Dataset – items at a particular index can be accesed by usual indexing notation (dataset[idx])
dataset = VOCDataset(‘trainval’, top_n=10)

#TODO: get the image information from index 2020
idx = 2020

and Logging¶
Initialize a Weights and Biases project, and convert the image tensor to a PIL image and plot it (check utils.py for helper functions).

You can use this as a reference for logging syntax.

if USE_WANDB:
wandb.init(project=”vlr2″, reinit=True)

See this block as an example of plotting the ground truth box for an image.

class_id_to_label = dict(enumerate(dataset.CLASS_NAMES))

img = wandb.Image(original_image, boxes={
“predictions”: {
“box_data”: get_box_data(gt_labels, gt_boxes),
“class_labels”: class_id_to_label,

Check the get_box_data function in utils.py and understand how it is being used. Log the image with the GT bounding box on wandb.
After, this you should be able to easily plot the top 10 bounding proposals as well.

nums = range(len(rois)) # placeholder for names of proposals

#TODO: plot top ten proposals (of bounding boxes)

程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com