From 87a2ee525522905da412baa12c578790b1260c7c Mon Sep 17 00:00:00 2001 From: augustin64 Date: Fri, 18 Mar 2022 15:32:39 +0100 Subject: [PATCH] Add src --- src/preview_mnist.c | 61 ++++++++++++++++++++++++++++++++ test_mnist.c => src/test_mnist.c | 0 2 files changed, 61 insertions(+) create mode 100644 src/preview_mnist.c rename test_mnist.c => src/test_mnist.c (100%) diff --git a/src/preview_mnist.c b/src/preview_mnist.c new file mode 100644 index 0000000..bfc8d14 --- /dev/null +++ b/src/preview_mnist.c @@ -0,0 +1,61 @@ +#include +#include +#include +#include + + +void print_image(unsigned int width, unsigned int height, FILE* ptr, int start) { + unsigned char buffer[width*height+start]; + + fread(buffer, sizeof(buffer), 1, ptr); + + int cur; + + for (int i=0; i 150) + printf("0"); + else { + if (cur > 100) + printf("."); + else + printf(" "); + } + } + printf("\n"); + } + printf("\t\t---\n"); +} + + + +void print_bytes(char* filename) { + unsigned char buffer[4]; + FILE *ptr; + + ptr = fopen(filename, "rb"); + + fread(buffer, sizeof(buffer), 1, ptr); + + uint32_t magic_number = buffer[0]; + uint32_t number_of_images = (int)buffer[1]; + unsigned int height = buffer[2]; + unsigned int width = buffer[3]; + + + printf("magic number: %" PRIu32 "\n", magic_number); + printf("number of images: %" PRIu32 "\n", number_of_images); + printf("%x x %x\n\n", width, height); + for (int i=0; i < number_of_images; i++) + print_image(width, height, ptr, (i*width*height)+4); +} + +int main(int argc, char *argv[]) { + if (argc == 1) { + printf("Utilisation: %s [FILE]\n", argv[0]); + return 1; + } + print_bytes(argv[1]); + return 0; +} diff --git a/test_mnist.c b/src/test_mnist.c similarity index 100% rename from test_mnist.c rename to src/test_mnist.c