| 566 | // |
| 567 | |
| 568 | bool mtmd_image_preprocessor_llava_uhd::preprocess(const clip_image_u8 & img, clip_image_f32_batch & output) { |
| 569 | const clip_image_size original_size{img.nx, img.ny}; |
| 570 | auto const inst = get_slice_instructions(original_size); |
| 571 | std::vector<clip_image_u8_ptr> imgs = slice_image(img, inst); |
| 572 | |
| 573 | for (size_t i = 0; i < imgs.size(); ++i) { |
| 574 | // clip_image_save_to_bmp(*imgs[i], "slice_" + std::to_string(i) + ".bmp"); |
| 575 | clip_image_f32_ptr res(clip_image_f32_init()); |
| 576 | img_u8_to_f32(*imgs[i], *res, hparams.image_mean, hparams.image_std); |
| 577 | output.entries.push_back(std::move(res)); |
| 578 | } |
| 579 | |
| 580 | output.grid_x = inst.grid_size.width; |
| 581 | output.grid_y = inst.grid_size.height; |
| 582 | return true; |
| 583 | } |
| 584 | |
| 585 | mtmd_image_preprocessor_llava_uhd::slice_instructions mtmd_image_preprocessor_llava_uhd::get_slice_instructions(const clip_image_size & original_size) { |
| 586 | mtmd_image_preprocessor_llava_uhd::slice_instructions res; |
no test coverage detected