From: Brendan Hansen Date: Wed, 14 Apr 2021 19:58:42 +0000 (-0500) Subject: small changes X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=3a6e14a11ebadb59845b1e29d2d1b4022f733e3d;p=onyx-mnist.git small changes --- diff --git a/src/mnist.onyx b/src/mnist.onyx index 6200418..c224ced 100644 --- a/src/mnist.onyx +++ b/src/mnist.onyx @@ -1,7 +1,6 @@ #load "core/std" -#load_path "src" -#load "neuralnet" +#load "src/neuralnet" use package core @@ -144,43 +143,3 @@ main :: (args: [] cstr) { train(^nn, ^mnist_data.base, ^optimizer); } - - - - -// Old code for printing the outputs fancily: -/* - { - print_colored_array :: (arr: [] $T, color_idx: i32, color_code := 94) { - for i: arr.count { - if i == color_idx { - printf("\x1b[%im", color_code); - print(arr[i]); - print("\x1b[0m "); - } else { - print(arr[i]); - print(" "); - } - } - print("\n"); - } - - color := 94; - if prediction != label do color = 91; - - output := nn->get_output(); - - print_colored_array(sample.output, label, color); - print_colored_array(output, prediction, color); - - loss := nn->get_loss(sample.output, criterion); - printf("Loss: %f Correct: %i / 100\n", cast(f32) loss, past_100_correct); - - past_100_correct = 0; - - // if ex % 10000 == 0 { - // println("Saving neural network..."); - // neural_net_save(nn, "data/still_working.nn"); - // } - } - */ diff --git a/src/neuralnet.onyx b/src/neuralnet.onyx index 2c608b9..4289b03 100644 --- a/src/neuralnet.onyx +++ b/src/neuralnet.onyx @@ -516,12 +516,8 @@ Optimizer_Functions :: struct { optimizer_init :: (use optim: ^Optimizer, nn: ^NeuralNet, allocator := context.allocator) { network = nn; - #context_scope { - context.allocator = allocator; - - variables = array.make(#type ^Variable); - variable_arrays = array.make(#type ^[] Variable); - } + variables = array.make(#type ^Variable, allocator=allocator); + variable_arrays = array.make(#type ^[] Variable, allocator=allocator); } optimizer_step :: (use optim: ^Optimizer, scale: f32 = 1) { @@ -577,4 +573,4 @@ sgd_optimizer_step :: (use optimizer: ^SGD_Optimizer, scale: f32) { variable.value += variable.delta * alpha; } } -} \ No newline at end of file +}