Sha256: 03da72a546d34480b6843c22a6ef9a76b28b3e07e37e4b093ee1a25c65b38ef0
Contents?: true
Size: 921 Bytes
Versions: 8
Compression:
Stored size: 921 Bytes
Contents
require "dnn" require "dnn/lib/mnist" #require "numo/linalg/autoloader" include Numo include DNN::Layers include DNN::Activations include DNN::Optimizers Model = DNN::Model MNIST = DNN::MNIST x_train, y_train = MNIST.load_train x_test, y_test = MNIST.load_test x_train = SFloat.cast(x_train).reshape(x_train.shape[0], 784) x_test = SFloat.cast(x_test).reshape(x_test.shape[0], 784) x_train /= 255 x_test /= 255 y_train = DNN::Util.to_categorical(y_train, 10) y_test = DNN::Util.to_categorical(y_test, 10) model = Model.new model << InputLayer.new(784) model << Dense.new(256) model << BatchNormalization.new model << ReLU.new model << Dense.new(256) model << BatchNormalization.new model << ReLU.new model << Dense.new(10) model << SoftmaxWithLoss.new model.compile(RMSProp.new) model.train(x_train, y_train, 10, batch_size: 100) do model.test(x_test, y_test) end
Version data entries
8 entries across 8 versions & 1 rubygems