Giter Club home page Giter Club logo

torchvision-ruby's Introduction

TorchVision Ruby

🔥 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

torchvision-ruby's People

Contributors

ankane avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

torchvision-ruby's Issues

Gem installation failing on Ubuntu despite installing libtorch

I'm trying to install torchvision on Ubuntu 18.04 (Ruby 2.7.1). It fails with:

have_library: checking for -ltorch... -------------------- no

"g++ -o conftest -I/home/derrell/.rvm/rubies/ruby-2.7.1/include/ruby-2.7.0/x86_64-linux -I/home/derrell/.rvm/rubies/ruby-2.7.1/include/ruby-2.7.0/ruby/backward -I/home/derrell/.rvm/rubies/ruby-2.7.1/include/ruby-2.7.0 -I.     -I/home/derrell/.rvm/gems/ruby-2.7.1/gems/rice-2.2.0/ruby/lib/include -g -O2 conftest.c  -L. -L/home/derrell/.rvm/rubies/ruby-2.7.1/lib -Wl,-rpath,/home/derrell/.rvm/rubies/ruby-2.7.1/lib -L. -fstack-protector-strong -rdynamic -Wl,-export-dynamic  -L/home/derrell/.rvm/gems/ruby-2.7.1/gems/rice-2.2.0/ruby/lib/lib -lrice -L/usr/local/lib    -lgomp -lstdc++  -Wl,-rpath,'/../lib' -Wl,-rpath,'/../lib' -lruby -ltorch -lgomp -lstdc++  -lm   -lc"
/usr/bin/ld: cannot find -ltorch
collect2: error: ld returned 1 exit status

This is despite having directly installed libtorch via apt install libtorch:

~/RubymineProjects/MachineLearningRuby$ locate libtorch
/usr/lib/libtorch.so.3
/usr/lib/libtorch.so.3.0.0

Any suggestions?

Thanks!

Plan

0.2.0 (waiting on ruby-vips release)

Datasets

Models

  • ResNet

Blocked

  • Automatically download pretrained models

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.