| 45 | } |
| 46 | |
| 47 | bool reset_input_output(const Args& args) { |
| 48 | std::string network_path = args.model_path; |
| 49 | std::string input_path = args.input_path; |
| 50 | lite::Config config; |
| 51 | |
| 52 | //! create and load the network |
| 53 | std::shared_ptr<Network> network = std::make_shared<Network>(config); |
| 54 | network->load_model(network_path); |
| 55 | |
| 56 | //! set input data to input tensor |
| 57 | std::shared_ptr<Tensor> input_tensor = network->get_input_tensor(0); |
| 58 | auto layout = input_tensor->get_layout(); |
| 59 | |
| 60 | auto src_tensor = parse_npy(input_path); |
| 61 | void* src = src_tensor->get_memory_ptr(); |
| 62 | input_tensor->reset(src, layout); |
| 63 | |
| 64 | //! set output ptr to store the network output |
| 65 | std::shared_ptr<Tensor> output_tensor = network->get_output_tensor(0); |
| 66 | auto result_tensor = std::make_shared<Tensor>( |
| 67 | LiteDeviceType::LITE_CPU, Layout{{1, 1000}, 2, LiteDataType::LITE_FLOAT}); |
| 68 | |
| 69 | void* out_data = result_tensor->get_memory_ptr(); |
| 70 | output_tensor->reset(out_data, result_tensor->get_layout()); |
| 71 | |
| 72 | network->forward(); |
| 73 | network->wait(); |
| 74 | |
| 75 | float max = -1.0f; |
| 76 | float sum = 0.0f; |
| 77 | for (size_t i = 0; i < 1000; i++) { |
| 78 | float data = static_cast<float*>(out_data)[i]; |
| 79 | sum += data; |
| 80 | if (max < data) |
| 81 | max = data; |
| 82 | } |
| 83 | printf("max=%e, sum=%e\n", max, sum); |
| 84 | return true; |
| 85 | } |
| 86 | } // namespace |
| 87 | |
| 88 | REGIST_EXAMPLE("reset_input", reset_input); |
nothing calls this directly
no test coverage detected