-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
38 lines (28 loc) · 1.17 KB
/
main.cpp
File metadata and controls
38 lines (28 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include "image.hpp"
#include "model_processor.hpp"
int main() {
// Initialize the ModelProcessor
ModelProcessor model_processor = ModelProcessor::from_pretrained("microsoft/Florence-2-large", true);
// Define the prompt
std::string prompt = "<OD>";
// Download and open the image
std::string image_path = "puma.png";
Image image = Image::open(image_path);
// Process the inputs
auto processor_output = model_processor.process(prompt, image);
// Generate output
auto generated_ids = model_processor.generate(processor_output->input_ids, processor_output->pixel_values, 4096, 3, false);
delete processor_output;
// Decode the generated IDs
std::string generated_text = model_processor.batch_decode(generated_ids, false);
// Post-process the generated text
std::string parsed_answer = model_processor.post_process_generation(generated_text, "<OD>",
std::make_pair(image.width(), image.height()));
// Print the result
std::cout << parsed_answer << std::endl;
return 0;
}