Computer Vision News - May 2020
2 Summary Deep Learning Library 2 Follows a snippet of code that takes the loaded image and applies the augmentation pipeline n different times providing with n versions of the same initial image. The model generates a prediction for each and saves them in a numpy array. seq = iaa.Sequential([ iaa.Sometimes( 0.5 , iaa.GaussianBlur(sigma=( 0 , 0.5 )) ), iaa.LinearContrast(( 0.75 , 1.5 )), iaa.AdditiveGaussianNoise(loc= 0 , scale=( 0.0 , 0.05 * 255 ), per_channel= 0.5 ), iaa.Multiply(( 0.8 , 1.2 ), per_channel= 0.2 ) ], random_order=True) n_trials = 10 y = input_image.size[ 0 ] x = input_image.size[ 1 ] all_preds = np.zeros((n_trials,x,y)) for i in range(n_trials): input_image = seq(image=np.array(input_image)) input_image = Image.fromarray(np.uint8(input_image)) preprocess = transforms.Compose([ transforms.ToTensor(), transforms.Normalize(mean=[ 0.485 , 0.456 , 0.406 ], std=[ 0.229 , 0.224 , 0.225 ]), ]) input_tensor = preprocess(input_image) input_batch = input_tensor.unsqueeze( 0 ) if torch.cuda.is_available(): input_batch = input_batch.to('cuda') model.to( 'cuda') with torch.no_grad(): output = model(input_batch)['out'][ 0 ] output_predictions = output.argmax( 0 ) all_preds[i] = output_predictions Here it’s an example of how the images look like after the augmentation. Several such images are fed into the model.
Made with FlippingBook
RkJQdWJsaXNoZXIy NTc3NzU=