| 68 | |
| 69 | namespace { |
| 70 | bool basic_load_from_path(const Args& args) { |
| 71 | set_log_level(LiteLogLevel::DEBUG); |
| 72 | std::string network_path = args.model_path; |
| 73 | std::string input_path = args.input_path; |
| 74 | |
| 75 | //! create and load the network |
| 76 | std::shared_ptr<Network> network = std::make_shared<Network>(); |
| 77 | network->load_model(network_path); |
| 78 | //! set input data to input tensor |
| 79 | std::shared_ptr<Tensor> input_tensor = network->get_input_tensor(0); |
| 80 | |
| 81 | auto layout = input_tensor->get_layout(); |
| 82 | for (size_t i = 0; i < layout.ndim; i++) { |
| 83 | printf("model input shape[%zu]=%zu \n", i, layout.shapes[i]); |
| 84 | } |
| 85 | |
| 86 | //! copy or forward data to network |
| 87 | size_t length = input_tensor->get_tensor_total_size_in_byte(); |
| 88 | void* dst_ptr = input_tensor->get_memory_ptr(); |
| 89 | auto src_tensor = parse_npy(input_path); |
| 90 | auto layout0 = src_tensor->get_layout(); |
| 91 | for (size_t i = 0; i < layout0.ndim; i++) { |
| 92 | printf("src shape[%zu]=%zu \n", i, layout0.shapes[i]); |
| 93 | } |
| 94 | void* src = src_tensor->get_memory_ptr(); |
| 95 | memcpy(dst_ptr, src, length); |
| 96 | |
| 97 | //! forward |
| 98 | { |
| 99 | lite_example_helper::Timer ltimer("warmup"); |
| 100 | network->forward(); |
| 101 | network->wait(); |
| 102 | ltimer.print_used_time(0); |
| 103 | } |
| 104 | lite_example_helper::Timer ltimer("forward_iter"); |
| 105 | for (int i = 0; i < 10; i++) { |
| 106 | network->forward(); |
| 107 | network->wait(); |
| 108 | ltimer.print_used_time(i); |
| 109 | } |
| 110 | |
| 111 | //! forward |
| 112 | { |
| 113 | lite_example_helper::Timer ltimer("warmup"); |
| 114 | network->forward(); |
| 115 | network->wait(); |
| 116 | ltimer.print_used_time(0); |
| 117 | } |
| 118 | for (int i = 0; i < 10; i++) { |
| 119 | ltimer.reset_start(); |
| 120 | network->forward(); |
| 121 | network->wait(); |
| 122 | ltimer.print_used_time(i); |
| 123 | } |
| 124 | |
| 125 | //! get the output data or read tensor set in network_in |
| 126 | size_t output_size = network->get_all_output_name().size(); |
| 127 | output_info(network, output_size); |
nothing calls this directly
no test coverage detected