Module: DNN::CIFAR100

Defined in:
lib/dnn/datasets/cifar100.rb

Defined Under Namespace

Classes: DNN_CIFAR100_LoadError

Class Method Summary collapse

Class Method Details

.downloadsObject



12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/dnn/datasets/cifar100.rb', line 12

def self.downloads
  return if Dir.exist?(DOWNLOADS_PATH + "/downloads/" + DIR_CIFAR100)
  Downloader.download(URL_CIFAR100)
  cifar100_binary_file_name = DOWNLOADS_PATH + "/downloads/" + URL_CIFAR100.match(%r`.+/(.+)`)[1]
  begin
    Zlib::GzipReader.open(cifar100_binary_file_name) do |gz|
      Archive::Tar::Minitar.unpack(gz, DOWNLOADS_PATH + "/downloads")
    end
  ensure
    File.unlink(cifar100_binary_file_name)
  end
end

.load_testObject



38
39
40
41
42
43
44
45
46
47
48
# File 'lib/dnn/datasets/cifar100.rb', line 38

def self.load_test
  downloads
  fname = DOWNLOADS_PATH + "/downloads/#{DIR_CIFAR100}/test.bin"
  raise DNN_CIFAR100_LoadError, %`file "#{fname}" is not found.` unless File.exist?(fname)
  bin = File.binread(fname)
  datas = Numo::UInt8.from_binary(bin).reshape(10000, 3074)
  x_test = datas[true, 2...3074]
  x_test = x_test.reshape(10000, 3, 32, 32).transpose(0, 2, 3, 1).clone
  y_test = datas[true, 0...2]
  [x_test, y_test]
end

.load_trainObject



25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/dnn/datasets/cifar100.rb', line 25

def self.load_train
  downloads
  bin = ""
  fname = DOWNLOADS_PATH + "/downloads/#{DIR_CIFAR100}/train.bin"
  raise DNN_CIFAR100_LoadError, %`file "#{fname}" is not found.` unless File.exist?(fname)
  bin << File.binread(fname)
  datas = Numo::UInt8.from_binary(bin).reshape(50000, 3074)
  x_train = datas[true, 2...3074]
  x_train = x_train.reshape(50000, 3, 32, 32).transpose(0, 2, 3, 1).clone
  y_train = datas[true, 0...2]
  [x_train, y_train]
end