🔥 Computer vision datasets, transforms, and models for Ruby
First, install libvips. For Homebrew, use:
brew install vips
Add this line to your application’s Gemfile:
gem "torchvision"
This library follows the Python API. Many methods and options are missing at the moment. PRs welcome!
Load a dataset
TorchVision::Datasets::MNIST.new("./data", train: true, download: true)
Supported datasets are:
- CIFAR10
- CIFAR100
- FashionMNIST
- KMNIST
- MNIST
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
TorchVision::Models::AlexNet.new
TorchVision::Models::ResNet18.new
TorchVision::Models::ResNet34.new
TorchVision::Models::ResNet50.new
TorchVision::Models::ResNet101.new
TorchVision::Models::ResNet152.new
TorchVision::Models::ResNext52_32x4d.new
TorchVision::Models::ResNext101_32x8d.new
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
TorchVision::Models::WideResNet52_2.new
TorchVision::Models::WideResNet101_2.new
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"))
Check your package manager. For Ubuntu, use:
sudo apt install libvips
You can also build from source.
brew install vips
Check out the options.
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.
View the changelog
Everyone is encouraged to help improve this project. Here are a few ways you can help:
- Report bugs
- Fix bugs and submit pull requests
- Write, clarify, or fix documentation
- Suggest or add new features
To get started with development:
git clone https://github.com/ankane/torchvision-ruby.git
cd torchvision-ruby
bundle install
bundle exec rake test