module DNN::FashionMNIST

Constants

TEST_IMAGES_FILE_NAME
TEST_LABELS_FILE_NAME
TRAIN_IMAGES_FILE_NAME
TRAIN_LABELS_FILE_NAME
URL_BASE
URL_TEST_IMAGES
URL_TEST_LABELS
URL_TRAIN_IMAGES
URL_TRAIN_LABELS

Public Class Methods

downloads() click to toggle source
# File lib/dnn/datasets/fashion-mnist.rb, line 22
def self.downloads
  Dir.mkdir("#{DOWNLOADS_PATH}/downloads") unless Dir.exist?("#{DOWNLOADS_PATH}/downloads")
  Dir.mkdir(mnist_dir) unless Dir.exist?(mnist_dir)
  Downloader.download(URL_TRAIN_IMAGES, mnist_dir) unless File.exist?(get_file_path(TRAIN_IMAGES_FILE_NAME))
  Downloader.download(URL_TRAIN_LABELS, mnist_dir) unless File.exist?(get_file_path(TRAIN_LABELS_FILE_NAME))
  Downloader.download(URL_TEST_IMAGES, mnist_dir) unless File.exist?(get_file_path(TEST_IMAGES_FILE_NAME))
  Downloader.download(URL_TEST_LABELS, mnist_dir) unless File.exist?(get_file_path(TEST_LABELS_FILE_NAME))
end
load_test() click to toggle source
# File lib/dnn/datasets/fashion-mnist.rb, line 42
def self.load_test
  downloads
  test_images_file_path = get_file_path(TEST_IMAGES_FILE_NAME)
  test_labels_file_path = get_file_path(TEST_LABELS_FILE_NAME)
  raise DNN_MNIST_LoadError, %`file "#{test_images_file_path}" is not found.` unless File.exist?(test_images_file_path)
  raise DNN_MNIST_LoadError, %`file "#{test_labels_file_path}" is not found.` unless File.exist?(test_labels_file_path)
  images = load_images(test_images_file_path)
  labels = load_labels(test_labels_file_path)
  [images, labels]
end
load_train() click to toggle source
# File lib/dnn/datasets/fashion-mnist.rb, line 31
def self.load_train
  downloads
  train_images_file_path = get_file_path(TRAIN_IMAGES_FILE_NAME)
  train_labels_file_path = get_file_path(TRAIN_LABELS_FILE_NAME)
  raise DNN_MNIST_LoadError, %`file "#{train_images_file_path}" is not found.` unless File.exist?(train_images_file_path)
  raise DNN_MNIST_LoadError, %`file "#{train_labels_file_path}" is not found.` unless File.exist?(train_labels_file_path)
  images = load_images(train_images_file_path)
  labels = load_labels(train_labels_file_path)
  [images, labels]
end

Private Class Methods

get_file_path(file_name) click to toggle source
# File lib/dnn/datasets/fashion-mnist.rb, line 77
                     def self.get_file_path(file_name)
  mnist_dir + "/" + file_name
end
load_images(file_name) click to toggle source
# File lib/dnn/datasets/fashion-mnist.rb, line 53
                     def self.load_images(file_name)
  images = nil
  Zlib::GzipReader.open(file_name) do |f|
    magic, num_images = f.read(8).unpack("N2")
    rows, cols = f.read(8).unpack("N2")
    images = Numo::UInt8.from_binary(f.read)
    images = images.reshape(num_images, cols, rows, 1)
  end
  images
end
load_labels(file_name) click to toggle source
# File lib/dnn/datasets/fashion-mnist.rb, line 64
                     def self.load_labels(file_name)
  labels = nil
  Zlib::GzipReader.open(file_name) do |f|
    magic, num_labels = f.read(8).unpack("N2")
    labels = Numo::UInt8.from_binary(f.read)
  end
  labels
end
mnist_dir() click to toggle source
# File lib/dnn/datasets/fashion-mnist.rb, line 73
                     def self.mnist_dir
  "#{DOWNLOADS_PATH}/downloads/fashion-mnist"
end