| 54 | } |
| 55 | |
| 56 | int main(int argc, char* argv[]) |
| 57 | { |
| 58 | int img_h = 224; |
| 59 | int img_w = 224; |
| 60 | |
| 61 | /* prepare input data */ |
| 62 | float* input_data = ( float* )malloc(sizeof(float) * img_h * img_w * 3); |
| 63 | |
| 64 | init_tengine(); |
| 65 | if(request_tengine_version("0.9") < 0) |
| 66 | return 1; |
| 67 | |
| 68 | graph_t graph = create_graph(nullptr, "caffe", text_file, model_file); |
| 69 | if(graph == nullptr) |
| 70 | { |
| 71 | std::cout << "Create graph failed\n"; |
| 72 | std::cout << "errno: " << get_tengine_errno() << "\n"; |
| 73 | return 1; |
| 74 | } |
| 75 | |
| 76 | /* run the graph */ |
| 77 | prerun_graph(graph); |
| 78 | |
| 79 | int node_idx = 0; |
| 80 | int tensor_idx = 0; |
| 81 | |
| 82 | const char* repeat_count = std::getenv("REPEAT_COUNT"); |
| 83 | if(repeat_count) |
| 84 | repeat = std::strtoul(repeat_count, NULL, 10); |
| 85 | |
| 86 | for(int i = 0; i < repeat; i++) |
| 87 | { |
| 88 | /* get input tensor */ |
| 89 | get_input_data(image_file, input_data, img_h, img_w, channel_mean, 1); |
| 90 | |
| 91 | tensor_t input_tensor = get_graph_input_tensor(graph, node_idx, tensor_idx); |
| 92 | |
| 93 | if(input_tensor == nullptr) |
| 94 | { |
| 95 | std::printf("Cannot find input tensor,node_idx: %d,tensor_idx: %d\n", node_idx, tensor_idx); |
| 96 | return -1; |
| 97 | } |
| 98 | |
| 99 | int dims[] = {1, 3, img_h, img_w}; |
| 100 | set_tensor_shape(input_tensor, dims, 4); |
| 101 | |
| 102 | /* setup input buffer */ |
| 103 | if(set_tensor_buffer(input_tensor, input_data, 3 * img_h * img_w * 4) < 0) |
| 104 | { |
| 105 | std::printf("Set buffer for tensor failed\n"); |
| 106 | return -1; |
| 107 | } |
| 108 | |
| 109 | run_graph(graph, 1); |
| 110 | |
| 111 | release_graph_tensor(input_tensor); |
| 112 | } |
| 113 |
nothing calls this directly
no test coverage detected