Computer Vision News - May 2020
3 Summary img ug 21 import torch import urllib from PIL import Image from torchvision import transforms import pdb import imgaug as ia import imgaug.augmenters as iaa from numpy import asarray import matplotlib.pyplot as plt import numpy as np from torch.nn.utils.rnn import pad_sequence model = torch.hub.load('pytorch/vision:v0.5.0', 'deeplabv3_resnet101', pretrained=True) model.eval() Once our model is loaded, we can proceed by choosing the image to test. You can continue by loading an example from pytorch or read any other local image. For this, I decided to download the test folder (v. 2017) available on the COCO website and choose one image from there. You can copy the loaded image for visualisation purposes later on, since we are going to change the input to the network multiple times. We can now finally set up the augmentation pipeline that we want. Here I applied a gaussian blur in about 50% of the cases and some change in contrast for each image. I also added gaussian noise to change color and brightness of the pixels. To do the same you can run the code below but note that here you can play with the transformations as much as you want, depending on your specific application and desired results. The extende d list of augmentations provided by imgaug should suit any desire. # Option 1: Download an example image from the pytorch website url, filename = ( "https://github.com/pytorch/hub/raw/master/dog.jpg" , "dog.jpg") try : urllib.URLopener().retrieve(url, filename) except : urllib.request.urlretrieve(url, filename) # Option 2: Read a local image filename = "2008_000159.jpg" input_image = Image.open(filename) copy_image = input_image
Made with FlippingBook
RkJQdWJsaXNoZXIy NTc3NzU=