Class: Datasets::CIFAR
- Includes:
- TarGzReadable
- Defined in:
- lib/datasets/cifar.rb
Defined Under Namespace
Modules: Pixelable Classes: Record10, Record100
Instance Attribute Summary
Attributes inherited from Dataset
Instance Method Summary collapse
- #each(&block) ⇒ Object
-
#initialize(n_classes: 10, type: :train) ⇒ CIFAR
constructor
A new instance of CIFAR.
Methods included from TarGzReadable
Methods inherited from Dataset
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) = "Please set n_classes 10 or 100: #{n_classes.inspect}" raise ArgumentError, end unless [:train, :test].include?(type) = "Please set type :train or :test: #{type.inspect}" raise ArgumentError, 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 |
# 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" data_url = "https://www.cs.toronto.edu/~kriz/cifar-#{@n_classes}-binary.tar.gz" download(data_path, data_url) parse_data(data_path, &block) end |