| 2131 | } |
| 2132 | |
| 2133 | bool sam_params_parse(int argc, char ** argv, sam_params & params) { |
| 2134 | |
| 2135 | bool use_point_prompt = false; |
| 2136 | bool use_box_prompt = false; |
| 2137 | |
| 2138 | for (int i = 1; i < argc; i++) { |
| 2139 | std::string arg = argv[i]; |
| 2140 | |
| 2141 | if (arg == "-s" || arg == "--seed") { |
| 2142 | params.seed = std::stoi(argv[++i]); |
| 2143 | } else if (arg == "-t" || arg == "--threads") { |
| 2144 | params.n_threads = std::stoi(argv[++i]); |
| 2145 | } else if (arg == "-m" || arg == "--model") { |
| 2146 | params.model = argv[++i]; |
| 2147 | } else if (arg == "-i" || arg == "--inp") { |
| 2148 | params.fname_inp = argv[++i]; |
| 2149 | } else if (arg == "-o" || arg == "--out") { |
| 2150 | params.fname_out = argv[++i]; |
| 2151 | } else if (arg == "-sm" || arg == "--single-mask") { |
| 2152 | params.multimask_output = false; |
| 2153 | } else if (arg == "-mt" || arg == "--mask-threshold") { |
| 2154 | params.mask_threshold = std::stof(argv[++i]); |
| 2155 | } else if (arg == "-it" || arg == "--iou-threshold") { |
| 2156 | params.iou_threshold = std::stof(argv[++i]); |
| 2157 | } else if (arg == "-st" || arg == "--score-threshold") { |
| 2158 | params.stability_score_threshold = std::stof(argv[++i]); |
| 2159 | } else if (arg == "-so" || arg == "--score-offset") { |
| 2160 | params.stability_score_offset = std::stof(argv[++i]); |
| 2161 | } else if (arg == "-e" || arg == "--epsilon") { |
| 2162 | params.eps = std::stof(argv[++i]); |
| 2163 | } else if (arg == "-ed" || arg == "--epsilon-decoder-transformer") { |
| 2164 | params.eps_decoder_transformer = std::stof(argv[++i]); |
| 2165 | } else if (arg == "-p" || arg == "--point-prompt") { |
| 2166 | // TODO multiple points per model invocation |
| 2167 | use_point_prompt = true; |
| 2168 | char* point = argv[++i]; |
| 2169 | |
| 2170 | char* coord = strtok(point, ","); |
| 2171 | if (!coord){ |
| 2172 | fprintf(stderr, "Error while parsing prompt!\n"); |
| 2173 | exit(1); |
| 2174 | } |
| 2175 | params.prompt.pt.x = std::stof(coord); |
| 2176 | |
| 2177 | coord = strtok(NULL, ","); |
| 2178 | if (!coord){ |
| 2179 | fprintf(stderr, "Error while parsing prompt!\n"); |
| 2180 | exit(1); |
| 2181 | } |
| 2182 | params.prompt.pt.y = std::stof(coord); |
| 2183 | } else if (arg == "-b" || arg == "--box-prompt") { |
| 2184 | use_box_prompt = true; |
| 2185 | char * box_prompt = argv[++i]; |
| 2186 | float box_vals[4]; |
| 2187 | |
| 2188 | char * val = strtok(box_prompt, ","); |
| 2189 | if (!val) { |
| 2190 | fprintf(stderr, "Error while parsing prompt!\n"); |
no test coverage detected