MCPcopy Create free account
hub / github.com/MegEngine/MegEngine / reset_input

Function reset_input

lite/example/cpp_example/mge/reset_io.cpp:9–45  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

7namespace {
8
9bool reset_input(const Args& args) {
10 std::string network_path = args.model_path;
11 std::string input_path = args.input_path;
12 lite::Config config;
13
14 //! create and load the network
15 std::shared_ptr<Network> network = std::make_shared<Network>(config);
16 network->load_model(network_path);
17
18 //! set input data to input tensor
19 std::shared_ptr<Tensor> input_tensor = network->get_input_tensor(0);
20 auto layout = input_tensor->get_layout();
21
22 auto src_tensor = parse_npy(input_path);
23 void* src = src_tensor->get_memory_ptr();
24 input_tensor->reset(src, layout);
25
26 //! forward
27 network->forward();
28 network->wait();
29
30 //! 6. get the output data or read tensor set in network_in
31 std::shared_ptr<Tensor> output_tensor = network->get_output_tensor(0);
32 void* out_data = output_tensor->get_memory_ptr();
33 size_t out_length = output_tensor->get_tensor_total_size_in_byte() /
34 output_tensor->get_layout().get_elem_size();
35 float max = -1.0f;
36 float sum = 0.0f;
37 for (size_t i = 0; i < out_length; i++) {
38 float data = static_cast<float*>(out_data)[i];
39 sum += data;
40 if (max < data)
41 max = data;
42 }
43 printf("max=%e, sum=%e\n", max, sum);
44 return true;
45}
46
47bool reset_input_output(const Args& args) {
48 std::string network_path = args.model_path;

Callers

nothing calls this directly

Calls 10

get_elem_sizeMethod · 0.80
load_modelMethod · 0.45
get_input_tensorMethod · 0.45
get_layoutMethod · 0.45
get_memory_ptrMethod · 0.45
resetMethod · 0.45
forwardMethod · 0.45
waitMethod · 0.45
get_output_tensorMethod · 0.45

Tested by

no test coverage detected