Sha256: 7062df3799715f90ea6c21c919d29a0726b662c0b79b41bb6d0c1aa9be78bb35
Contents?: true
Size: 572 Bytes
Versions: 2
Compression:
Stored size: 572 Bytes
Contents
require "dnn" require "dnn/image" require_relative "convnet8" def load_model return if $model $model = ConvNet.create([28, 28, 1]) $model.predict1(Numo::SFloat.zeros(28, 28, 1)) $model.load_params("trained_mnist_params.marshal") end def mnist_predict(img, width, height) load_model img = DNN::Image.from_binary(img, height, width, DNN::Image::RGBA) img = img[true, true, 0...DNN::Image::RGB] img = DNN::Image.to_gray_scale(img) x = Numo::SFloat.cast(img) / 255 out = $model.predict1(x) out.to_a.map { |v| v.round(4) * 100 } end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
ruby-dnn-1.2.0 | examples/judge-number/mnist_predict.rb |
ruby-dnn-1.1.6 | examples/judge-number/mnist_predict.rb |