なにをしたいか
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
pip install git+https://github.com/pytorch/accimage
Activation
torchvision.set_image_backend('accimage')
でOKです
>>> import torchvision
>>> # デフォルト
>>> torchvision.get_image_backend()
'PIL'
>>> # バックエンド変更後
>>> torchvision.set_image_backend("accimage")
>>> torchvision.get_image_backend()
'accimage'