Sha256: 4f45bdc48dae07a5b7106d7350cae8c9e51b2e0ae6e55c13efcbfff007ed2fce
Contents?: true
Size: 882 Bytes
Versions: 4
Compression:
Stored size: 882 Bytes
Contents
#!/usr/bin/env ruby require 'bundler/setup' require 'mnist' require 'optparse' num_sample = nil opt = OptionParser.new opt.banner = "Usage: #{$0} [options] IMAGE_FILE LABEL_FILE" opt.version = Mnist::VERSION opt.separator '' opt.separator 'Options:' opt.on('-n', '--sample=N', Integer, 'The number of samples') {|v| num_sample = v } opt.parse!(ARGV) nrows, ncols, images = Mnist.load_images(ARGV[0]) labels = Mnist.load_labels(ARGV[1]) if images.length != labels.length raise "The lengths of images and labels are not same" end print "y" (nrows*ncols).times do |i| print ",x#{i}" end print "\r\n" indices = 0...labels.length indices = [*indices].sample(num_sample) if num_sample indices.each do |index| label = labels[index] print label image = images[index] pixels = image.unpack('C*') pixels.each do |pixel| print ",#{pixel}" end print "\r\n" end
Version data entries
4 entries across 4 versions & 2 rubygems
Version | Path |
---|---|
mnist-learn-0.1.2 | exe/mnist2csv |
mnist-learn-0.1.1 | exe/mnist2csv |
mnist-learn-0.1.0 | exe/mnist2csv |
mnist-0.1.0 | exe/mnist2csv |