| 25 | #include <string> |
| 26 | |
| 27 | int main(int argc, char** argv) { |
| 28 | std::string model_path = "models/edgetam_f16.ggml"; |
| 29 | std::string image_path = "data/test_image.jpg"; |
| 30 | int n_threads = 4; |
| 31 | int n_warmup = 2; |
| 32 | int n_iter = 5; |
| 33 | bool use_gpu = true; |
| 34 | |
| 35 | for (int i = 1; i < argc; ++i) { |
| 36 | if (strcmp(argv[i], "--model") == 0 && i + 1 < argc) { |
| 37 | model_path = argv[++i]; |
| 38 | } else if (strcmp(argv[i], "--image") == 0 && i + 1 < argc) { |
| 39 | image_path = argv[++i]; |
| 40 | } else if (strcmp(argv[i], "--n-threads") == 0 && i + 1 < argc) { |
| 41 | n_threads = atoi(argv[++i]); |
| 42 | } else if (strcmp(argv[i], "--n-warmup") == 0 && i + 1 < argc) { |
| 43 | n_warmup = atoi(argv[++i]); |
| 44 | } else if (strcmp(argv[i], "--n-iter") == 0 && i + 1 < argc) { |
| 45 | n_iter = atoi(argv[++i]); |
| 46 | } else if (strcmp(argv[i], "--cpu") == 0) { |
| 47 | use_gpu = false; |
| 48 | } else { |
| 49 | fprintf(stderr, "Unknown option: %s\n", argv[i]); |
| 50 | fprintf(stderr, "Usage: %s [--model <path>] [--image <path>] " |
| 51 | "[--n-threads <n>] [--n-warmup <n>] [--n-iter <n>] [--cpu]\n", argv[0]); |
| 52 | return 1; |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | fprintf(stderr, "Loading model: %s\n", model_path.c_str()); |
| 57 | fprintf(stderr, "Test image: %s\n", image_path.c_str()); |
| 58 | fprintf(stderr, "Backend: %s\n", use_gpu ? "Metal (GPU)" : "CPU"); |
| 59 | fprintf(stderr, "\n"); |
| 60 | |
| 61 | // Load model |
| 62 | sam3_params params; |
| 63 | params.model_path = model_path; |
| 64 | params.use_gpu = use_gpu; |
| 65 | params.n_threads = n_threads; |
| 66 | |
| 67 | auto model = sam3_load_model(params); |
| 68 | if (!model) { |
| 69 | fprintf(stderr, "ERROR: failed to load model\n"); |
| 70 | return 1; |
| 71 | } |
| 72 | |
| 73 | if (sam3_get_model_type(*model) != SAM3_MODEL_EDGETAM) { |
| 74 | fprintf(stderr, "ERROR: model is not EdgeTAM (model_type=%d)\n", |
| 75 | sam3_get_model_type(*model)); |
| 76 | return 1; |
| 77 | } |
| 78 | |
| 79 | // Load image |
| 80 | auto image = sam3_load_image(image_path); |
| 81 | if (image.data.empty()) { |
| 82 | fprintf(stderr, "ERROR: failed to load image '%s'\n", image_path.c_str()); |
| 83 | return 1; |
| 84 | } |
nothing calls this directly
no test coverage detected