MCPcopy Create free account
hub / github.com/alibaba/MNN / _loadInputFromFile

Function _loadInputFromFile

tools/cpp/MNNV2Basic.cpp:97–151  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

95}
96
97static void _loadInputFromFile(Tensor* inputTensor, std::string pwd, std::string name) {
98 MNN::Tensor givenTensor(inputTensor, inputTensor->getDimensionType());
99 {
100 int size_w = inputTensor->width();
101 int size_h = inputTensor->height();
102 int bpp = inputTensor->channel();
103 int batch = inputTensor->batch();
104 MNN_PRINT("Input size:%d\n", inputTensor->elementSize());
105 inputTensor->printShape();
106
107 std::ostringstream fileName;
108 fileName << pwd << name;
109 std::ifstream input(fileName.str().c_str());
110 FUNC_PRINT_ALL(fileName.str().c_str(), s);
111
112 if (givenTensor.getType().code == halide_type_int) {
113 auto size = givenTensor.elementSize();
114 const auto bytesLen = givenTensor.getType().bytes();
115 if (bytesLen == 4) {
116 auto inputData = givenTensor.host<int32_t>();
117 double temp;
118 for (int i = 0; i < size; ++i) {
119 input >> temp;
120 inputData[i] = temp;
121 }
122 } else if (bytesLen == 1) {
123 auto inputData = givenTensor.host<int8_t>();
124 double pixel = 0;
125 for (int i = 0; i < size; ++i) {
126 input >> pixel;
127 inputData[i] = static_cast<int8_t>(pixel);
128 }
129 }
130 } else if (givenTensor.getType().code == halide_type_uint) {
131 auto size = givenTensor.elementSize();
132 {
133 FUNC_PRINT(givenTensor.getType().bytes());
134 auto inputData = givenTensor.host<uint8_t>();
135 for (int i = 0; i < size; ++i) {
136 double p;
137 input >> p;
138 inputData[i] = (uint8_t)p;
139 }
140 }
141 } else if (givenTensor.getType().code == halide_type_float) {
142 auto inputData = givenTensor.host<float>();
143 auto size = givenTensor.elementSize();
144 for (int i = 0; i < size; ++i) {
145 input >> inputData[i];
146 // inputData[i] = 1.0f;
147 }
148 }
149 inputTensor->copyFromHostTensor(&givenTensor);
150 }
151}
152
153static inline int64_t getTimeInUs() {
154 uint64_t time;

Callers 1

test_mainFunction · 0.85

Calls 9

getDimensionTypeMethod · 0.80
printShapeMethod · 0.80
copyFromHostTensorMethod · 0.80
widthMethod · 0.45
heightMethod · 0.45
c_strMethod · 0.45
strMethod · 0.45
getTypeMethod · 0.45
bytesMethod · 0.45

Tested by 1

test_mainFunction · 0.68