Class: Datasets::CIFAR

Inherits:
Dataset show all
Includes:
TarGzReadable
Defined in:
lib/datasets/cifar.rb

Defined Under Namespace

Modules: Pixelable Classes: Record10, Record100

Instance Attribute Summary

Attributes inherited from Dataset

#metadata

Instance Method Summary collapse

Methods included from TarGzReadable

#open_tar_gz

Methods inherited from Dataset

#clear_cache!, #to_table

Constructor Details

#initialize(n_classes: 10, type: :train) ⇒ CIFAR

Returns a new instance of CIFAR.



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/datasets/cifar.rb', line 28

def initialize(n_classes: 10, type: :train)
  unless [10, 100].include?(n_classes)
    message = "Please set n_classes 10 or 100: #{n_classes.inspect}"
    raise ArgumentError, message
  end
  unless [:train, :test].include?(type)
    message = "Please set type :train or :test: #{type.inspect}"
    raise ArgumentError, message
  end

  super()

  @metadata.id = "cifar-#{n_classes}"
  @metadata.name = "CIFAR-#{n_classes}"
  @metadata.url = "https://www.cs.toronto.edu/~kriz/cifar.html"
  @metadata.description = "CIFAR-#{n_classes} is 32x32 image dataset"

  @n_classes = n_classes
  @type = type
end

Instance Method Details

#each(&block) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
# File 'lib/datasets/cifar.rb', line 49

def each(&block)
  return to_enum(__method__) unless block_given?

  data_path = cache_dir_path + "cifar-#{@n_classes}.tar.gz"
  unless data_path.exist?
    data_url = "https://www.cs.toronto.edu/~kriz/cifar-#{@n_classes}-binary.tar.gz"
    download(data_path, data_url)
  end

  parse_data(data_path, &block)
end