torchvision 0.2.2 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d218068a8502ca9aa41ec3240043c55122c22e10944fb5d0fb402e95ccb48e99
4
- data.tar.gz: 3d9288e590d4d9a570c7f6c501ffbd30ef968c58790e2beec42721672b34075f
3
+ metadata.gz: 73e4a86f8dfcd27a7fe92c82f68865116b8d0906f07c1b1887a3a2990b5b9f1d
4
+ data.tar.gz: 20dfe4a76998626a75542048fee9f9529e14cb85cc7935be3b66fa521751ae21
5
5
  SHA512:
6
- metadata.gz: c841175a05fdace23e273413c863dcb2135fcab66414a6600864e16e12375c65d37a62fa2f03a433852f946324f40192ca5656d1f3e87b72ec0207e1f92e585f
7
- data.tar.gz: a9e98d5929bed556b59ef29ad690668dac7bfe7b5f46f87e92d9e8dab352793ee659dcd8894343264c60b75bfd0cc07177db00bb0a5828410d879ebeb22bf860
6
+ metadata.gz: f5e4383b65158f675cce3bc14dba875acd2182e59db0b005a9d288c58189b52bea2698ed60349e16f04e207e8a1be13a8278a6d1633d70db6bc2a6a2c3c38165
7
+ data.tar.gz: 70ddf739f2f85eeb8ce78bb098930aae169497544ab996b152800ca7b06333bc9e2ed541834f472145dbe82582c77f11c0af2404c9e5cea329b80bd25348d6ab
data/CHANGELOG.md CHANGED
@@ -1,3 +1,12 @@
1
+ ## 0.4.0 (2024-08-02)
2
+
3
+ - Dropped support for Ruby < 3.1
4
+
5
+ ## 0.3.0 (2023-01-29)
6
+
7
+ - Added mirror for MNIST dataset
8
+ - Dropped support for Ruby < 2.7
9
+
1
10
  ## 0.2.2 (2021-05-23)
2
11
 
3
12
  - Fixed error with ruby-vips 2.1.2
data/LICENSE.txt CHANGED
@@ -1,7 +1,7 @@
1
1
  BSD 3-Clause License
2
2
 
3
3
  Copyright (c) Soumith Chintala 2016,
4
- Copyright (c) Andrew Kane 2020-2021,
4
+ Copyright (c) Andrew Kane 2020-2024,
5
5
  All rights reserved.
6
6
 
7
7
  Redistribution and use in source and binary forms, with or without
data/README.md CHANGED
@@ -1,8 +1,8 @@
1
- # TorchVision
1
+ # TorchVision Ruby
2
2
 
3
3
  :fire: Computer vision datasets, transforms, and models for Ruby
4
4
 
5
- [![Build Status](https://github.com/ankane/torchvision/workflows/build/badge.svg?branch=master)](https://github.com/ankane/torchvision/actions)
5
+ [![Build Status](https://github.com/ankane/torchvision-ruby/actions/workflows/build.yml/badge.svg)](https://github.com/ankane/torchvision-ruby/actions)
6
6
 
7
7
  ## Installation
8
8
 
@@ -15,17 +15,17 @@ brew install vips
15
15
  Add this line to your application’s Gemfile:
16
16
 
17
17
  ```ruby
18
- gem 'torchvision'
18
+ gem "torchvision"
19
19
  ```
20
20
 
21
21
  ## Getting Started
22
22
 
23
- This library follows the [Python API](https://pytorch.org/docs/stable/torchvision/index.html). Many methods and options are missing at the moment. PRs welcome!
23
+ This library follows the [Python API](https://pytorch.org/vision/). Many methods and options are missing at the moment. PRs welcome!
24
24
 
25
25
  ## Examples
26
26
 
27
27
  - [MNIST](https://github.com/ankane/torch.rb/tree/master/examples/mnist)
28
- - [Transfer learning](https://github.com/ankane/torch.rb/tree/master/examples/transfer-learning)
28
+ - [Transfer learning](https://github.com/ankane/torch.rb/tree/master/tutorials/transfer_learning/README.md)
29
29
  - [Generative adversarial networks](https://github.com/ankane/torch.rb/tree/master/examples/gan)
30
30
 
31
31
  ## Datasets
@@ -161,22 +161,22 @@ If you’re a dataset owner and wish to update any details or remove it from thi
161
161
 
162
162
  ## History
163
163
 
164
- View the [changelog](https://github.com/ankane/torchvision/blob/master/CHANGELOG.md)
164
+ View the [changelog](https://github.com/ankane/torchvision-ruby/blob/master/CHANGELOG.md)
165
165
 
166
166
  ## Contributing
167
167
 
168
168
  Everyone is encouraged to help improve this project. Here are a few ways you can help:
169
169
 
170
- - [Report bugs](https://github.com/ankane/torchvision/issues)
171
- - Fix bugs and [submit pull requests](https://github.com/ankane/torchvision/pulls)
170
+ - [Report bugs](https://github.com/ankane/torchvision-ruby/issues)
171
+ - Fix bugs and [submit pull requests](https://github.com/ankane/torchvision-ruby/pulls)
172
172
  - Write, clarify, or fix documentation
173
173
  - Suggest or add new features
174
174
 
175
175
  To get started with development:
176
176
 
177
177
  ```sh
178
- git clone https://github.com/ankane/torchvision.git
179
- cd torchvision
178
+ git clone https://github.com/ankane/torchvision-ruby.git
179
+ cd torchvision-ruby
180
180
  bundle install
181
181
  bundle exec rake test
182
182
  ```
@@ -99,7 +99,7 @@ module TorchVision
99
99
  {filename: "data_batch_2.bin", sha256: "a591ca11fa1708a91ee40f54b3da4784ccd871ecf2137de63f51ada8b3fa57ed"},
100
100
  {filename: "data_batch_3.bin", sha256: "bbe8596564c0f86427f876058170b84dac6670ddf06d79402899d93ceea26f67"},
101
101
  {filename: "data_batch_4.bin", sha256: "014e562d6e23c72197cc727519169a60359f5eccd8945ad5a09d710285ff4e48"},
102
- {filename: "data_batch_5.bin", sha256: "755304fc0b379caeae8c14f0dac912fbc7d6cd469eb67a1029a08a39453a9add"},
102
+ {filename: "data_batch_5.bin", sha256: "755304fc0b379caeae8c14f0dac912fbc7d6cd469eb67a1029a08a39453a9add"}
103
103
  ]
104
104
  end
105
105
 
@@ -42,6 +42,8 @@ module TorchVision
42
42
  def size
43
43
  @samples.size
44
44
  end
45
+ alias_method :count, :size
46
+ alias_method :length, :size
45
47
 
46
48
  private
47
49
 
@@ -5,22 +5,28 @@ module TorchVision
5
5
 
6
6
  private
7
7
 
8
+ def mirrors
9
+ [
10
+ "http://fashion-mnist.s3-website.eu-central-1.amazonaws.com/"
11
+ ]
12
+ end
13
+
8
14
  def resources
9
15
  [
10
16
  {
11
- url: "http://fashion-mnist.s3-website.eu-central-1.amazonaws.com/train-images-idx3-ubyte.gz",
17
+ filename: "train-images-idx3-ubyte.gz",
12
18
  sha256: "3aede38d61863908ad78613f6a32ed271626dd12800ba2636569512369268a84"
13
19
  },
14
20
  {
15
- url: "http://fashion-mnist.s3-website.eu-central-1.amazonaws.com/train-labels-idx1-ubyte.gz",
21
+ filename: "train-labels-idx1-ubyte.gz",
16
22
  sha256: "a04f17134ac03560a47e3764e11b92fc97de4d1bfaf8ba1a3aa29af54cc90845"
17
23
  },
18
24
  {
19
- url: "http://fashion-mnist.s3-website.eu-central-1.amazonaws.com/t10k-images-idx3-ubyte.gz",
25
+ filename: "t10k-images-idx3-ubyte.gz",
20
26
  sha256: "346e55b948d973a97e58d2351dde16a484bd415d4595297633bb08f03db6a073"
21
27
  },
22
28
  {
23
- url: "http://fashion-mnist.s3-website.eu-central-1.amazonaws.com/t10k-labels-idx1-ubyte.gz",
29
+ filename: "t10k-labels-idx1-ubyte.gz",
24
30
  sha256: "67da17c76eaffca5446c3361aaab5c3cd6d1c2608764d35dfb1850b086bf8dd5"
25
31
  }
26
32
  ]
@@ -5,22 +5,28 @@ module TorchVision
5
5
 
6
6
  private
7
7
 
8
+ def mirrors
9
+ [
10
+ "http://codh.rois.ac.jp/kmnist/dataset/kmnist/"
11
+ ]
12
+ end
13
+
8
14
  def resources
9
15
  [
10
16
  {
11
- url: "http://codh.rois.ac.jp/kmnist/dataset/kmnist/train-images-idx3-ubyte.gz",
17
+ filename: "train-images-idx3-ubyte.gz",
12
18
  sha256: "51467d22d8cc72929e2a028a0428f2086b092bb31cfb79c69cc0a90ce135fde4"
13
19
  },
14
20
  {
15
- url: "http://codh.rois.ac.jp/kmnist/dataset/kmnist/train-labels-idx1-ubyte.gz",
21
+ filename: "train-labels-idx1-ubyte.gz",
16
22
  sha256: "e38f9ebcd0f3ebcdec7fc8eabdcdaef93bb0df8ea12bee65224341c8183d8e17"
17
23
  },
18
24
  {
19
- url: "http://codh.rois.ac.jp/kmnist/dataset/kmnist/t10k-images-idx3-ubyte.gz",
25
+ filename: "t10k-images-idx3-ubyte.gz",
20
26
  sha256: "edd7a857845ad6bb1d0ba43fe7e794d164fe2dce499a1694695a792adfac43c5"
21
27
  },
22
28
  {
23
- url: "http://codh.rois.ac.jp/kmnist/dataset/kmnist/t10k-labels-idx1-ubyte.gz",
29
+ filename: "t10k-labels-idx1-ubyte.gz",
24
30
  sha256: "20bb9a0ef54c7db3efc55a92eef5582c109615df22683c380526788f98e42a1c"
25
31
  }
26
32
  ]
@@ -52,8 +52,18 @@ module TorchVision
52
52
  FileUtils.mkdir_p(processed_folder)
53
53
 
54
54
  resources.each do |resource|
55
- filename = resource[:url].split("/").last
56
- download_file(resource[:url], download_root: raw_folder, filename: filename, sha256: resource[:sha256])
55
+ success = false
56
+ mirrors.each do |mirror|
57
+ begin
58
+ url = "#{mirror}#{resource[:filename]}"
59
+ download_file(url, download_root: raw_folder, filename: resource[:filename], sha256: resource[:sha256])
60
+ success = true
61
+ break
62
+ rescue Net::HTTPFatalError, Net::HTTPClientException => e
63
+ puts "Failed to download (trying next): #{e.message}"
64
+ end
65
+ end
66
+ raise Error, "Error downloading #{resource[:filename]}" unless success
57
67
  end
58
68
 
59
69
  puts "Processing..."
@@ -75,22 +85,29 @@ module TorchVision
75
85
 
76
86
  private
77
87
 
88
+ def mirrors
89
+ [
90
+ "https://yann.lecun.com/exdb/mnist/",
91
+ "https://ossci-datasets.s3.amazonaws.com/mnist/"
92
+ ]
93
+ end
94
+
78
95
  def resources
79
96
  [
80
97
  {
81
- url: "http://yann.lecun.com/exdb/mnist/train-images-idx3-ubyte.gz",
98
+ filename: "train-images-idx3-ubyte.gz",
82
99
  sha256: "440fcabf73cc546fa21475e81ea370265605f56be210a4024d2ca8f203523609"
83
100
  },
84
101
  {
85
- url: "http://yann.lecun.com/exdb/mnist/train-labels-idx1-ubyte.gz",
102
+ filename: "train-labels-idx1-ubyte.gz",
86
103
  sha256: "3552534a0a558bbed6aed32b30c495cca23d567ec52cac8be1a0730e8010255c"
87
104
  },
88
105
  {
89
- url: "http://yann.lecun.com/exdb/mnist/t10k-images-idx3-ubyte.gz",
106
+ filename: "t10k-images-idx3-ubyte.gz",
90
107
  sha256: "8d422c7b0a1c1c79245a5bcf07fe86e33eeafee792b84584aec276f5a2dbc4e6"
91
108
  },
92
109
  {
93
- url: "http://yann.lecun.com/exdb/mnist/t10k-labels-idx1-ubyte.gz",
110
+ filename: "t10k-labels-idx1-ubyte.gz",
94
111
  sha256: "f7ae60f92e00ec6debd23a6088c31dbd2371eca3ffa0defaefb259924204aec6"
95
112
  }
96
113
  ]
@@ -37,12 +37,13 @@ module TorchVision
37
37
  # of response bodies and automatically decompresses gzip
38
38
  # and deflateresponses unless a Range header was sent.
39
39
  # https://ruby-doc.org/stdlib-2.6.4/libdoc/net/http/rdoc/Net/HTTP.html
40
- Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == "https") do |http|
40
+ Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == "https", open_timeout: 3) do |http|
41
41
  request = Net::HTTP::Get.new(uri)
42
42
 
43
43
  puts "Downloading #{url}..."
44
44
  File.open(temp_path, "wb") do |f|
45
45
  http.request(request) do |response|
46
+ response.value # raise error if not success
46
47
  response.read_body do |chunk|
47
48
  f.write(chunk)
48
49
  end
@@ -2,18 +2,18 @@ module TorchVision
2
2
  module Models
3
3
  class ResNet < Torch::NN::Module
4
4
  MODEL_URLS = {
5
- "resnet18" => "https://download.pytorch.org/models/resnet18-5c106cde.pth",
6
- "resnet34" => "https://download.pytorch.org/models/resnet34-333f7ec4.pth",
7
- "resnet50" => "https://download.pytorch.org/models/resnet50-19c8e357.pth",
8
- "resnet101" => "https://download.pytorch.org/models/resnet101-5d3b4d8f.pth",
9
- "resnet152" => "https://download.pytorch.org/models/resnet152-b121ed2d.pth",
5
+ "resnet18" => "https://download.pytorch.org/models/resnet18-f37072fd.pth",
6
+ "resnet34" => "https://download.pytorch.org/models/resnet34-b627a593.pth",
7
+ "resnet50" => "https://download.pytorch.org/models/resnet50-0676ba61.pth",
8
+ "resnet101" => "https://download.pytorch.org/models/resnet101-63fe2227.pth",
9
+ "resnet152" => "https://download.pytorch.org/models/resnet152-394f9c45.pth",
10
10
  "resnext50_32x4d" => "https://download.pytorch.org/models/resnext50_32x4d-7cdf4587.pth",
11
11
  "resnext101_32x8d" => "https://download.pytorch.org/models/resnext101_32x8d-8ba56ff5.pth",
12
12
  "wide_resnet50_2" => "https://download.pytorch.org/models/wide_resnet50_2-95faca4d.pth",
13
13
  "wide_resnet101_2" => "https://download.pytorch.org/models/wide_resnet101_2-32ee1156.pth"
14
14
  }
15
15
 
16
- def initialize(block, layers, num_classes=1000, zero_init_residual: false,
16
+ def initialize(block, layers, num_classes = 1000, zero_init_residual: false,
17
17
  groups: 1, width_per_group: 64, replace_stride_with_dilation: nil, norm_layer: nil)
18
18
 
19
19
  super()
@@ -2,8 +2,8 @@ module TorchVision
2
2
  module Models
3
3
  class VGG < Torch::NN::Module
4
4
  MODEL_URLS = {
5
- "vgg11" => "https://download.pytorch.org/models/vgg11-bbd30ac9.pth",
6
- "vgg13" => "https://download.pytorch.org/models/vgg13-c768596a.pth",
5
+ "vgg11" => "https://download.pytorch.org/models/vgg11-8a719046.pth",
6
+ "vgg13" => "https://download.pytorch.org/models/vgg13-19584684.pth",
7
7
  "vgg16" => "https://download.pytorch.org/models/vgg16-397923af.pth",
8
8
  "vgg19" => "https://download.pytorch.org/models/vgg19-dcbb9e9d.pth",
9
9
  "vgg11_bn" => "https://download.pytorch.org/models/vgg11_bn-6002323d.pth",
@@ -56,7 +56,7 @@ module TorchVision
56
56
  "A" => [64, "M", 128, "M", 256, 256, "M", 512, 512, "M", 512, 512, "M"],
57
57
  "B" => [64, 64, "M", 128, 128, "M", 256, 256, "M", 512, 512, "M", 512, 512, "M"],
58
58
  "D" => [64, 64, "M", 128, 128, "M", 256, 256, 256, "M", 512, 512, 512, "M", 512, 512, 512, "M"],
59
- "E" => [64, 64, "M", 128, 128, "M", 256, 256, 256, 256, "M", 512, 512, 512, 512, "M", 512, 512, 512, 512, "M"],
59
+ "E" => [64, 64, "M", 128, 128, "M", 256, 256, 256, 256, "M", 512, 512, 512, 512, "M", 512, 512, 512, 512, "M"]
60
60
  }
61
61
 
62
62
  def self.make_model(arch, cfg, batch_norm, pretrained: false, **kwargs)
@@ -1,3 +1,3 @@
1
1
  module TorchVision
2
- VERSION = "0.2.2"
2
+ VERSION = "0.4.0"
3
3
  end
data/lib/torchvision.rb CHANGED
@@ -11,53 +11,53 @@ require "rubygems/package"
11
11
  require "tmpdir"
12
12
 
13
13
  # modules
14
- require "torchvision/utils"
15
- require "torchvision/version"
14
+ require_relative "torchvision/utils"
15
+ require_relative "torchvision/version"
16
16
 
17
17
  # datasets
18
- require "torchvision/datasets/vision_dataset"
19
- require "torchvision/datasets/dataset_folder"
20
- require "torchvision/datasets/image_folder"
21
- require "torchvision/datasets/cifar10"
22
- require "torchvision/datasets/cifar100"
23
- require "torchvision/datasets/mnist"
24
- require "torchvision/datasets/fashion_mnist"
25
- require "torchvision/datasets/kmnist"
18
+ require_relative "torchvision/datasets/vision_dataset"
19
+ require_relative "torchvision/datasets/dataset_folder"
20
+ require_relative "torchvision/datasets/image_folder"
21
+ require_relative "torchvision/datasets/cifar10"
22
+ require_relative "torchvision/datasets/cifar100"
23
+ require_relative "torchvision/datasets/mnist"
24
+ require_relative "torchvision/datasets/fashion_mnist"
25
+ require_relative "torchvision/datasets/kmnist"
26
26
 
27
27
  # models
28
- require "torchvision/models/alexnet"
29
- require "torchvision/models/basic_block"
30
- require "torchvision/models/bottleneck"
31
- require "torchvision/models/resnet"
32
- require "torchvision/models/resnet18"
33
- require "torchvision/models/resnet34"
34
- require "torchvision/models/resnet50"
35
- require "torchvision/models/resnet101"
36
- require "torchvision/models/resnet152"
37
- require "torchvision/models/resnext50_32x4d"
38
- require "torchvision/models/resnext101_32x8d"
39
- require "torchvision/models/vgg"
40
- require "torchvision/models/vgg11"
41
- require "torchvision/models/vgg11_bn"
42
- require "torchvision/models/vgg13"
43
- require "torchvision/models/vgg13_bn"
44
- require "torchvision/models/vgg16"
45
- require "torchvision/models/vgg16_bn"
46
- require "torchvision/models/vgg19"
47
- require "torchvision/models/vgg19_bn"
48
- require "torchvision/models/wide_resnet50_2"
49
- require "torchvision/models/wide_resnet101_2"
28
+ require_relative "torchvision/models/alexnet"
29
+ require_relative "torchvision/models/basic_block"
30
+ require_relative "torchvision/models/bottleneck"
31
+ require_relative "torchvision/models/resnet"
32
+ require_relative "torchvision/models/resnet18"
33
+ require_relative "torchvision/models/resnet34"
34
+ require_relative "torchvision/models/resnet50"
35
+ require_relative "torchvision/models/resnet101"
36
+ require_relative "torchvision/models/resnet152"
37
+ require_relative "torchvision/models/resnext50_32x4d"
38
+ require_relative "torchvision/models/resnext101_32x8d"
39
+ require_relative "torchvision/models/vgg"
40
+ require_relative "torchvision/models/vgg11"
41
+ require_relative "torchvision/models/vgg11_bn"
42
+ require_relative "torchvision/models/vgg13"
43
+ require_relative "torchvision/models/vgg13_bn"
44
+ require_relative "torchvision/models/vgg16"
45
+ require_relative "torchvision/models/vgg16_bn"
46
+ require_relative "torchvision/models/vgg19"
47
+ require_relative "torchvision/models/vgg19_bn"
48
+ require_relative "torchvision/models/wide_resnet50_2"
49
+ require_relative "torchvision/models/wide_resnet101_2"
50
50
 
51
51
  # transforms
52
- require "torchvision/transforms/center_crop"
53
- require "torchvision/transforms/compose"
54
- require "torchvision/transforms/functional"
55
- require "torchvision/transforms/normalize"
56
- require "torchvision/transforms/random_horizontal_flip"
57
- require "torchvision/transforms/random_resized_crop"
58
- require "torchvision/transforms/random_vertical_flip"
59
- require "torchvision/transforms/resize"
60
- require "torchvision/transforms/to_tensor"
52
+ require_relative "torchvision/transforms/center_crop"
53
+ require_relative "torchvision/transforms/compose"
54
+ require_relative "torchvision/transforms/functional"
55
+ require_relative "torchvision/transforms/normalize"
56
+ require_relative "torchvision/transforms/random_horizontal_flip"
57
+ require_relative "torchvision/transforms/random_resized_crop"
58
+ require_relative "torchvision/transforms/random_vertical_flip"
59
+ require_relative "torchvision/transforms/resize"
60
+ require_relative "torchvision/transforms/to_tensor"
61
61
 
62
62
  module TorchVision
63
63
  class Error < StandardError; end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: torchvision
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Kane
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-05-23 00:00:00.000000000 Z
11
+ date: 2024-08-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: numo-narray
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - ">="
46
46
  - !ruby/object:Gem::Version
47
- version: 0.3.7
47
+ version: '0.13'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
- version: 0.3.7
54
+ version: '0.13'
55
55
  description:
56
56
  email: andrew@ankane.org
57
57
  executables: []
@@ -103,7 +103,7 @@ files:
103
103
  - lib/torchvision/transforms/to_tensor.rb
104
104
  - lib/torchvision/utils.rb
105
105
  - lib/torchvision/version.rb
106
- homepage: https://github.com/ankane/torchvision
106
+ homepage: https://github.com/ankane/torchvision-ruby
107
107
  licenses:
108
108
  - BSD-3-Clause
109
109
  metadata: {}
@@ -115,14 +115,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
115
115
  requirements:
116
116
  - - ">="
117
117
  - !ruby/object:Gem::Version
118
- version: '2.6'
118
+ version: '3.1'
119
119
  required_rubygems_version: !ruby/object:Gem::Requirement
120
120
  requirements:
121
121
  - - ">="
122
122
  - !ruby/object:Gem::Version
123
123
  version: '0'
124
124
  requirements: []
125
- rubygems_version: 3.2.3
125
+ rubygems_version: 3.5.11
126
126
  signing_key:
127
127
  specification_version: 4
128
128
  summary: Computer vision datasets, transforms, and models for Ruby