Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/ggml/blob/master/examples/mnist/mnist-eval.cpp # ggml [Ported from github.com/ggml-org/ggml] docs : sync ggml_type enum in gguf.md (#1685) Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `master` Branches Tags History `ggml / examples / mnist / mnist-eval.cpp` 67 lines ยท 2066 bytes Raw Blame History 1 #include "ggml.h" 2 #include "ggml-opt.h" 3 4 #include "mnist-common.h" 5 6 #include 7 #include 8 #include 9 #include 10 #include 11 #include 12 #include 13 #include 14 15 #if defined(_MSC_VER) 16 #pragma warning(disable: 4244 4267) // possible loss of data 17 #endif 18 19 int main(int argc, char ** argv) { 20 srand(time(NULL)); 21 ggml_time_init(); 22 23 if (argc != 4 && argc != 5) { 24 fprintf(stderr, "Usage: %s mnist-fc-f32.gguf data/MNIST/raw/t10k-images-idx3-ubyte data/MNIST/raw/t10k-labels-idx1-ubyte [CPU/CUDA0]\n", argv[0]); 25 exit(1); 26 } 27 28 ggml_opt_dataset_t dataset = ggml_opt_dataset_init(GGML_TYPE_F32, GGML_TYPE_F32, MNIST_NINPUT, MNIST_NCLASSES, MNIST_NTEST, MNIST_NBATCH_PHYSICAL); 29 30 if (!mnist_image_load(argv[2], dataset)) { 31 return 1; 32 } 33 if (!mnist_label_load(argv[3], dataset)) { 34 return 1; 35 } 36 37 const int iex = rand() % MNIST_NTEST; 38 mnist_image_print(stdout, dataset, iex); 39 40 const std::string backend = argc >= 5 ? argv[4] : ""; 41 42 const int64_t t_start_us = ggml_time_us(); 43 mnist_model model = mnist_model_init_from_file(argv[1], backend, MNIST_NBATCH_LOGICAL, MNIST_NBATCH_PHYSICAL); 44 mnist_model_build(model); 45 const int64_t t_load_us = ggml_time_us() - t_start_us; 46 fprintf(stdout, "%s: loaded model in %.2lf ms\n", __func__, t_load_us / 1000.0); 47 48 ggml_opt_result_t result_eval = mnist_model_eval(model, dataset); 49 50 std::vector pred(MNIST_NTEST); 51 ggml_opt_result_pred(result_eval, pred.data()); 52 fprintf(stdout, "%s: predicted digit is %d\n", __func__, pred[iex]); 53 54 double loss; 55 double loss_unc; 56 ggml_opt_result_loss(result_eval, &loss, &loss_unc); 57 fprintf(stdout, "%s: test_loss=%.6lf+-%.6lf\n", __func__, loss, loss_unc); 58 59 double accuracy; 60 double accuracy_unc; 61 ggml_opt_result_accuracy(result_eval, &accuracy, &accuracy_unc); 62 fprintf(stdout, "%s: test_acc=%.2lf+-%.2lf%%\n", __func__, 100.0*accuracy, 100.0*accuracy_unc); 63 64 ggml_opt_result_free(result_eval); 65 66 return 0; 67 }