资源算法opencv_transforms

opencv_transforms

2019-10-09 | |  69 |   0 |   0

opencv_transforms

This repository is intended as a faster drop-in replacement for Pytorch's Torchvision augmentations. This repo uses OpenCV for fast image augmentation for PyTorch computer vision pipelines. I wrote this code because the Pillow-based Torchvision transforms was starving my GPU due to slow image augmentation.

Requirements

  • A working installation of OpenCV. Tested with OpenCV version 3.4.1

  • Tested on Windows 10. There is evidence that OpenCV doesn't work well with multithreading on Linux / MacOS, for example num_workers >0 in a pytorch DataLoader. I haven't tried this on those systems.

Installation

  • git clone https://github.com/jbohnslav/opencv_transforms.git

  • Add to your python path

Usage

  • from opencv_transforms import opencv_transforms as transforms

  • From here, almost everything should work exactly as the original transforms.

Example: Image resizing

import numpy as np
image = np.random.randint(low=0, high=255, size=(1024, 2048, 3))
resize = transforms.Resize(size=(256,256))
image = resize(image)

Should be 1.5 to 10 times faster than PIL. See benchmarks

Performance

  • Most transformations are between 1.5X and ~4X faster in OpenCV. Large image resizes are up to 10 times faster in OpenCV.

  • To reproduce the following benchmarks, download the Cityscapes dataset.

  • An example benchmarking file can be found in the notebook bencharming_v2.ipynb I wrapped the Cityscapes default directories with a HDF5 file for even faster reading.

benchmarking_Resize.png benchmarking_Random_crop_quarter_size.png benchmarking_Color_brightness_only.png benchmarking_Color_constrast_and_brightness.png benchmarking_Color_contrast_only.png benchmarking_Random_horizontal_flip.png

The changes start to add up when you compose multiple transformations together. benchmarking_Resize_flip_brightness_contrast_rotate.png

TODO

  •  Initial commit with all currently implemented torchvision transforms

  •  Cityscapes benchmarks

  •  Make the resample flag on RandomRotationRandomAffine actually do something

  •  Speed up augmentation in saturation and hue. Currently, fastest way is to convert to a PIL image, perform same augmentation as Torchvision, then convert back to np.ndarray


上一篇:magnet

下一篇:fastai

用户评价
全部评价

热门资源

  • Keras-ResNeXt

    Keras ResNeXt Implementation of ResNeXt models...

  • seetafaceJNI

    项目介绍 基于中科院seetaface2进行封装的JAVA...

  • spark-corenlp

    This package wraps Stanford CoreNLP annotators ...

  • capsnet-with-caps...

    CapsNet with capsule-wise convolution Project ...

  • inferno-boilerplate

    This is a very basic boilerplate example for pe...