use package core
+// NOTE(Brendan Hansen): Currently, this supports only loading one of the dataset files,
+// even through there are 6 of them.
CIFAR10_DataLoader :: struct {
use data : DataLoader;
_, bytes_read := io.stream_read_at(^data_file, location, ~~ sample);
label := ~~sample[0];
- // TODO(Brendan Hansen): NOT DONE
+ for ^o: output do *o = 0;
+ output[cast(u32) label] = 1;
+
+ for i: 3072 {
+ input[i] = (cast(f32) cast(u32) sample[i + 1]) / 255;
+ }
+
+ return true;
}
};
printf("Loss: %f Correct: %i / 100\n", cast(f32) loss, past_100_correct);
past_100_correct = 0;
-
- /*
- if ex % 10000 == 0 {
+
+ if ex % 1000 == 0 {
println("Saving neural network...");
- neural_net_save(nn, "data/test_4.nn");
+ neural_net_save(nn, output_file);
}
- */
}
}
}
}
+// :Cleanup
+output_file := "data/tmp.nn"
main :: (args: [] cstr) {
- println("Hello World!");
+ if args.count > 1 {
+ output_file = string.make(args[0]);
+ }
+
+ printf("Network save location: %s\n", output_file);
+
+ random.set_seed(5432);
cifar10_dataloader := cifar10_create();
defer cifar10_close(^cifar10_dataloader);
+
+ nn := make_neural_net(3072, 1024, 256, 10);
+ defer neural_net_free(^nn);
+
+ stocastic_gradient_descent(^nn, ^cifar10_dataloader);
}
\ No newline at end of file
neurons = memory.make_slice(f32, layer_size, allocator);
pre_activation_neurons = memory.make_slice(f32, layer_size, allocator);
- weights = memory.make_slice(#type [] f32, layer_size, allocator);
-
use_bias = true;
deltas = memory.make_slice(f32, layer_size, allocator);
activation = sigmoid_activation;
if use_bias {
biases = memory.make_slice(f32, layer_size, allocator);
}
-
+
+ weights = memory.make_slice(#type [] f32, layer_size, allocator);
for ^weight: weights {
*weight = memory.make_slice(f32, prev_layer_size, allocator);
}