lib/dnn/lib/mnist.rb in ruby-dnn-0.8.6 vs lib/dnn/lib/mnist.rb in ruby-dnn-0.8.7

- old
+ new

@@ -1,29 +1,25 @@ -require "open-uri" require "zlib" require_relative "../core/error" +require_relative "downloader" module DNN module MNIST class DNN_MNIST_LoadError < DNN_Error; end - class DNN_MNIST_DownloadError < DNN_Error; end - URL_TRAIN_IMAGES = "http://yann.lecun.com/exdb/mnist/train-images-idx3-ubyte.gz" URL_TRAIN_LABELS = "http://yann.lecun.com/exdb/mnist/train-labels-idx1-ubyte.gz" URL_TEST_IMAGES = "http://yann.lecun.com/exdb/mnist/t10k-images-idx3-ubyte.gz" URL_TEST_LABELS = "http://yann.lecun.com/exdb/mnist/t10k-labels-idx1-ubyte.gz" def self.downloads return if Dir.exist?(mnist_dir) Dir.mkdir(mnist_dir) - puts "Now downloading..." - download(URL_TRAIN_IMAGES) - download(URL_TRAIN_LABELS) - download(URL_TEST_IMAGES) - download(URL_TEST_LABELS) - puts "The download has ended." + Downloader.download(URL_TRAIN_IMAGES, mnist_dir) + Downloader.download(URL_TRAIN_LABELS, mnist_dir) + Downloader.download(URL_TEST_IMAGES, mnist_dir) + Downloader.download(URL_TEST_LABELS, mnist_dir) end def self.load_train downloads train_images_file_name = url_to_file_name(URL_TRAIN_IMAGES) @@ -53,17 +49,9 @@ labels = load_labels(test_labels_file_name) [images, labels] end private_class_method - - def self.download(url) - open(url, "rb") do |f| - File.binwrite(url_to_file_name(url), f.read) - end - rescue => ex - raise DNN_MNIST_DownloadError.new(ex.message) - end def self.load_images(file_name) images = nil Zlib::GzipReader.open(file_name) do |f| magic, num_images = f.read(8).unpack("N2") \ No newline at end of file