LoginSignup
2
6

More than 3 years have passed since last update.

Pillow-SIMDとaccimageでTorchVisionを速くするときのメモ

Posted at

なにをしたいか

TorchVisionをpillow-simdとaccimageで速くしたい

はじめに

https://github.com/pytorch/vision#image-backend
torchvisionのバックエンドは、デフォルトでPillowであり、Pillow-SIMDがインストールされているとデフォルトが変更されます。accimageはset_image_backend関数でバックエンドに設定できます。
ちなみに、デフォルトのPillowは最近のCPUだったらPillow-SIMDに乗り換えたほうがいいかもしれません。

Pillow-SIMD

Benchmarks

https://github.com/uploadcare/pillow-simd#benchmarks
- 通常のPillowの4-6倍程度速いらしいです。
- AVX2が有効なCPUであると、ImageMagickより16-40倍速いらしいです。

Installation

$ pip uninstall pillow
$ CC="cc -mavx2" pip install -U --force-reinstall pillow-simd

accimage

Benchmarks

不明です。たぶんデフォルトのPillowよりは速いんじゃなかろうか…(根拠なし

Installation

オフィシャルはconda推奨ですが、以下の通りでpipからもインストールできます
https://github.com/pytorch/accimage#installation
https://github.com/pytorch/accimage/issues/18

一応conda推奨です
pip install git+https://github.com/pytorch/accimage

Activation

torchvision.set_image_backend('accimage')でOKです

デフォルトとset_image_backend後を確認
>>> import torchvision
>>> # デフォルト
>>> torchvision.get_image_backend()
'PIL'
>>> # バックエンド変更後
>>> torchvision.set_image_backend("accimage")
>>> torchvision.get_image_backend()
'accimage'
2
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
6