ruby-dnn 0.1.2 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2f509323fa3b0d100943d2f30f9545baf0116e5e9f66c068121712e0b079ad04
4
- data.tar.gz: 9e1163fe79527c2514b4cd509d3899e93c9e39e1a3491ce98e9a0d073ee24763
3
+ metadata.gz: a30ecc0e25621a1ea4c06948c155adb037983241ac8f7f05efa2a28db9e52e48
4
+ data.tar.gz: 601599d13059ae9db1a4fb8129f3483bbea258a0408c3208b11a4b4f55f82198
5
5
  SHA512:
6
- metadata.gz: ef8704fb2def4124e0f7d0bfba7fa83ed9c304bf1d366ba3c03fb28b583cc909d969a2991b99fe55c879e6806590e59f76fbc177dc8ddd9643e4d07aef862b07
7
- data.tar.gz: b8600ede2ba0e2463a0ca4e1170a3ec94f02a60edf89545927a0eb9752719c48cf13d2b7c4ac38d936bd70fab7d4003df33c82d8625ee827b2aa599572acd466
6
+ metadata.gz: 6db06348f1a7f7e27a5a0010199302a20000242fba944a03a12aa42ebda7832fa1a80271475de1f20e3866b653e3ebf6dd44c4e42e22bd6c9b1874f6671a4178
7
+ data.tar.gz: 0af1c1c6bf2d1ed8b48876730a76e3f1324319a075be72885cdcb24ffb0d15de9c673beb6b446b74be5f9298730d9a7e17a4ceb0f2dfe232663b2bd4dcd83824
@@ -1,3 +1,3 @@
1
1
  module DNN
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
@@ -1,26 +1,53 @@
1
1
  require "dnn"
2
2
  require "dnn/ext/cifar10/cifar10_ext"
3
+ require "open-uri"
4
+ require "zlib"
5
+ require "archive/tar/minitar"
6
+
7
+ URL_CIFAR10 = "https://www.cs.toronto.edu/~kriz/cifar-10-binary.tar.gz"
8
+ CIFAR10_DIR = "cifar-10-batches-bin"
3
9
 
4
10
  module DNN
5
11
  module CIFAR10
12
+ class DNN_CIFAR10_LoadError < DNN_Error; end
13
+
14
+ class DNN_CIFAR10_DownloadError < DNN_Error; end
15
+
6
16
  private_class_method :_cifar10_load
7
17
 
18
+ def self.downloads
19
+ return if Dir.exist?(__dir__ + "/" + CIFAR10_DIR)
20
+ cifar10_binary_file_name = __dir__ + "/" + URL_CIFAR10.match(%r`.+/(.+)`)[1]
21
+ puts "Now downloading..."
22
+ open(URL_CIFAR10, "rb") do |f|
23
+ File.binwrite(cifar10_binary_file_name, f.read)
24
+ Zlib::GzipReader.open(cifar10_binary_file_name) do |gz|
25
+ Archive::Tar::Minitar::unpack(gz, __dir__)
26
+ end
27
+ end
28
+ File.delete(cifar10_binary_file_name)
29
+ puts "The download has ended."
30
+ rescue => ex
31
+ raise DNN_CIFAR10_DownloadError.new(ex.message)
32
+ end
33
+
8
34
  def self.load_train
35
+ downloads
9
36
  bin = ""
10
37
  (1..5).each do |i|
11
- bin << File.binread("#{dir}/data_batch_#{i}.bin")
38
+ fname = __dir__ + "/#{CIFAR10_DIR}/data_batch_#{i}.bin"
39
+ raise DNN_CIFAR10_LoadError.new(%`file "#{fname}" is not found.`) unless File.exist?(fname)
40
+ bin << File.binread(fname)
12
41
  end
13
42
  _cifar10_load(bin, 50000)
14
43
  end
15
44
 
16
45
  def self.load_test
17
- bin = File.binread("#{dir}/test_batch.bin")
46
+ downloads
47
+ fname = __dir__ + "/#{CIFAR10_DIR}/test_batch.bin"
48
+ raise DNN_CIFAR10_LoadError.new(%`file "#{fname}" is not found.`) unless File.exist?(fname)
49
+ bin = File.binread(fname)
18
50
  _cifar10_load(bin, 10000)
19
51
  end
20
-
21
- def self.dir
22
- "cifar-10-batches-bin"
23
- end
24
52
  end
25
53
  end
26
- ##30730000
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-dnn
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - unagiootoro