TorchVision Ruby

:fire: Computer vision datasets, transforms, and models for Ruby

Build Status

Installation

First, install libvips. For Homebrew, use:

brew install vips

Add this line to your application’s Gemfile:

gem "torchvision"

Getting Started

This library follows the Python API. Many methods and options are missing at the moment. PRs welcome!

Examples

Datasets

Load a dataset

TorchVision::Datasets::MNIST.new("./data", train: true, download: true)

Supported datasets are:

  • CIFAR10
  • CIFAR100
  • FashionMNIST
  • KMNIST
  • MNIST

Transforms

TorchVision::Transforms::Compose.new([
  TorchVision::Transforms::ToTensor.new,
  TorchVision::Transforms::Normalize.new([0.1307], [0.3081])
])

Supported transforms are:

  • CenterCrop
  • Compose
  • Normalize
  • RandomHorizontalFlip
  • RandomResizedCrop
  • RandomVerticalFlip
  • Resize
  • ToTensor

Models

AlexNet

TorchVision::Models::AlexNet.new

ResNet

TorchVision::Models::ResNet18.new
TorchVision::Models::ResNet34.new
TorchVision::Models::ResNet50.new
TorchVision::Models::ResNet101.new
TorchVision::Models::ResNet152.new

ResNeXt

TorchVision::Models::ResNext52_32x4d.new
TorchVision::Models::ResNext101_32x8d.new

VGG

TorchVision::Models::VGG11.new
TorchVision::Models::VGG11BN.new
TorchVision::Models::VGG13.new
TorchVision::Models::VGG13BN.new
TorchVision::Models::VGG16.new
TorchVision::Models::VGG16BN.new
TorchVision::Models::VGG19.new
TorchVision::Models::VGG19BN.new

Wide ResNet

TorchVision::Models::WideResNet52_2.new
TorchVision::Models::WideResNet101_2.new

Pretrained Models

You can download pretrained models with this script

pip install torchvision
python pretrained.py

And load them

net = TorchVision::Models::ResNet18.new
net.load_state_dict(Torch.load("net.pth"))

libvips Installation

Linux

Check your package manager. For Ubuntu, use:

sudo apt install libvips

You can also build from source.

Mac

brew install vips

Windows

Check out the options.

Disclaimer

This library downloads and prepares public datasets. We don’t host any datasets. Be sure to adhere to the license for each dataset.

If you’re a dataset owner and wish to update any details or remove it from this project, let us know.

History

View the changelog

Contributing

Everyone is encouraged to help improve this project. Here are a few ways you can help:

To get started with development:

git clone https://github.com/ankane/torchvision-ruby.git
cd torchvision-ruby
bundle install
bundle exec rake test