Class: MnistDataset
- Inherits:
-
Object
- Object
- MnistDataset
- Defined in:
- lib/mnist_dataset.rb
Constant Summary collapse
- @@VERSION =
"1.1.1"- @@YEAR =
"2023"
Instance Attribute Summary collapse
-
#all_set ⇒ Object
readonly
Returns the value of attribute all_set.
-
#test_set ⇒ Object
readonly
Returns the value of attribute test_set.
-
#train_set ⇒ Object
readonly
Returns the value of attribute train_set.
Class Method Summary collapse
Instance Method Summary collapse
- #info ⇒ Object
-
#initialize(show_progress, just_one) ⇒ MnistDataset
constructor
A new instance of MnistDataset.
-
#inspect ⇒ Object
very important to override this otherwise inspect will go crazy trying to inspect 70000 elements.
Constructor Details
#initialize(show_progress, just_one) ⇒ MnistDataset
Returns a new instance of MnistDataset.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/mnist_dataset.rb', line 14 def initialize(show_progress, just_one) test_set = File.join(File.dirname(__FILE__), '..', 'data', 'mnist_test.csv') @train_set = [] @test_set = [] @all_set = [] CSV.foreach(test_set) do |row| label, pixels = get_label_and_pixels(row) digit = MnistDigit.new(label, pixels) @test_set.push(digit) @all_set.push(digit) print "\r#{all_set.size}" if show_progress break if just_one end (1..3).each do |index| train_set = File.join(File.dirname(__FILE__), '..', 'data', "mnist_train#{index}.csv") CSV.foreach(train_set) do |row| label, pixels = get_label_and_pixels(row) digit = MnistDigit.new(label, pixels) @train_set.push(digit) @all_set.push(digit) print "\r#{all_set.size}" if show_progress break if just_one end break if just_one end puts if show_progress end |
Instance Attribute Details
#all_set ⇒ Object (readonly)
Returns the value of attribute all_set.
45 46 47 |
# File 'lib/mnist_dataset.rb', line 45 def all_set @all_set end |
#test_set ⇒ Object (readonly)
Returns the value of attribute test_set.
45 46 47 |
# File 'lib/mnist_dataset.rb', line 45 def test_set @test_set end |
#train_set ⇒ Object (readonly)
Returns the value of attribute train_set.
45 46 47 |
# File 'lib/mnist_dataset.rb', line 45 def train_set @train_set end |
Class Method Details
.instance(show_progress = false, just_one = false) ⇒ Object
47 48 49 50 51 52 53 |
# File 'lib/mnist_dataset.rb', line 47 def self.instance(show_progress = false, just_one = false) return @instance if @instance @instance_mutex.synchronize do @instance ||= new(show_progress, just_one) end @instance end |
Instance Method Details
#info ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/mnist_dataset.rb', line 60 def info s = "MNIST-READY #{@@VERSION} (#{@@YEAR})\n" s += "Author: Sergio Oliveira Jr\n" s += "LinkedIn: https://www.linkedin.com/in/soliveira/\n" s += "URL: https://github.com/saoj/mnist-ready\n" s += "License: MIT\n" s += "\n" s += "Total number of digits: #{all_set.size}\n" s += pretty_hash(count_digits(all_set)) s += "\n" s += "Total number of train digits: #{train_set.size}\n" s += pretty_hash(count_digits(train_set)) s += "\n" s += "Total number of test digits: #{test_set.size}\n" s += pretty_hash(count_digits(test_set)) s += "\n" digit = all_set.sample s += digit.ascii_image s += "\n" end |
#inspect ⇒ Object
very important to override this otherwise inspect will go crazy trying to inspect 70000 elements
56 57 58 |
# File 'lib/mnist_dataset.rb', line 56 def inspect to_s end |