MCPcopy Create free account
hub / github.com/0xShug0/audio.cpp / main

Function main

external/ggml/examples/mnist/mnist-eval.cpp:19–67  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

17#endif
18
19int 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<int32_t> 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}

Callers

nothing calls this directly

Calls 14

ggml_time_initFunction · 0.85
ggml_opt_dataset_initFunction · 0.85
mnist_image_loadFunction · 0.85
mnist_label_loadFunction · 0.85
mnist_image_printFunction · 0.85
ggml_time_usFunction · 0.85
mnist_model_buildFunction · 0.85
mnist_model_evalFunction · 0.85
ggml_opt_result_predFunction · 0.85
ggml_opt_result_lossFunction · 0.85
ggml_opt_result_accuracyFunction · 0.85

Tested by

no test coverage detected