29 comment::freeze(doit);
31 extraintensors::freeze();
36 std::string
const & val)
39 if (val.empty())
return;
49 while (itsLoading.load())
51 std::this_thread::sleep_for(std::chrono::milliseconds(5));
52 try {
if (ready())
break; }
catch (...) { }
53 if (count++ == 200) {
LINFO(
"Waiting for network load to complete..."); count = 0; }
61 if (itsLoaded.load())
return true;
64 if (itsLoading.load())
66 if (itsLoadFut.valid() && itsLoadFut.wait_for(std::chrono::milliseconds(2)) == std::future_status::ready)
68 try { itsLoadFut.get(); itsLoaded.store(
true); itsLoading.store(
false);
LINFO(
"Network loaded.");
return true; }
75 itsLoading.store(
true);
77 LINFO(
"Loading network...");
84 std::vector<std::string> & info)
86 if (ready() ==
false)
LFATAL(
"Network is not ready");
88 std::vector<cv::Mat> outs;
93 if (extra.empty() ==
false)
95 std::vector<cv::Mat> newblobs = blobs;
98 for (std::string
const & in : ins)
100 vsi_nn_tensor_attr_t attr; memset(&attr, 0,
sizeof(attr));
104 LFATAL(
"Malformed extra tensor, need <type>:<shape>:val1 val2 ... valN (separate multiple tensors by comma)");
107 if (tok[0] ==
"8U") attr.dtype.vx_type = VSI_NN_TYPE_UINT8;
108 else if (tok[0] ==
"8S") attr.dtype.vx_type = VSI_NN_TYPE_INT8;
109 else if (tok[0] ==
"16U") attr.dtype.vx_type = VSI_NN_TYPE_UINT16;
110 else if (tok[0] ==
"16S") attr.dtype.vx_type = VSI_NN_TYPE_INT16;
111 else if (tok[0] ==
"16F") attr.dtype.vx_type = VSI_NN_TYPE_FLOAT16;
112 else if (tok[0] ==
"32S") attr.dtype.vx_type = VSI_NN_TYPE_INT32;
113 else if (tok[0] ==
"32F") attr.dtype.vx_type = VSI_NN_TYPE_FLOAT32;
114 else if (tok[0] ==
"64F") attr.dtype.vx_type = VSI_NN_TYPE_FLOAT64;
115 else throw std::range_error(
"Unsupported extra input tensor type [" + tok[0] +
"] in " + extra);
119 attr.dim_num = dims.size();
120 for (
size_t i = 0; i < attr.dim_num; ++i) attr.size[attr.dim_num - 1 - i] = dims[i];
123 attr.dtype.qnt_type = VSI_NN_QNT_TYPE_NONE;
124 attr.dtype.fmt = VSI_NN_DIM_FMT_AUTO;
128 std::vector<std::string> vals =
jevois::split(tok[2],
"\\s+");
129 size_t const nvals = vals.size();
130 if (nvals != b.total())
131 LFATAL(
"Extra in tensor needs " << b.total() <<
" values, but " << nvals <<
" given in [" << in <<
']');
132 switch (attr.dtype.vx_type)
134 case VSI_NN_TYPE_UINT8:
136 uint8_t * ptr =
reinterpret_cast<uint8_t *
>(b.data);
137 for (std::string
const & v : vals) *ptr++ = std::stoi(v);
141 case VSI_NN_TYPE_INT8:
143 int8_t * ptr =
reinterpret_cast<int8_t *
>(b.data);
144 for (std::string
const & v : vals) *ptr++ = std::stoi(v);
148 case VSI_NN_TYPE_UINT16:
150 uint16_t * ptr =
reinterpret_cast<uint16_t *
>(b.data);
151 for (std::string
const & v : vals) *ptr++ = std::stoi(v);
155 case VSI_NN_TYPE_INT16:
157 int16_t * ptr =
reinterpret_cast<int16_t *
>(b.data);
158 for (std::string
const & v : vals) *ptr++ = std::stoi(v);
162 case VSI_NN_TYPE_FLOAT16:
164 cv::float16_t * ptr =
reinterpret_cast<cv::float16_t *
>(b.data);
165 for (std::string
const & v : vals) *ptr++ = cv::float16_t(std::stof(v));
169 case VSI_NN_TYPE_INT32:
171 int32_t * ptr =
reinterpret_cast<int32_t *
>(b.data);
172 for (std::string
const & v : vals) *ptr++ = std::stoi(v);
176 case VSI_NN_TYPE_FLOAT32:
178 float * ptr =
reinterpret_cast<float *
>(b.data);
179 for (std::string
const & v : vals) *ptr++ = std::stof(v);
183 case VSI_NN_TYPE_FLOAT64:
185 double * ptr =
reinterpret_cast<double *
>(b.data);
186 for (std::string
const & v : vals) *ptr++ = std::stod(v);
190 default:
LFATAL(
"internal inconsistency");
193 newblobs.emplace_back(std::move(b));
200 info.emplace_back(
"* Input Tensors");
204 info.emplace_back(
"* Network");
205 if (c.empty() ==
false) info.emplace_back(c);
207 outs = std::move(doprocess(newblobs, info));
212 info.emplace_back(
"* Input Tensors");
216 info.emplace_back(
"* Network");
217 if (c.empty() ==
false) info.emplace_back(c);
219 outs = std::move(doprocess(blobs, info));
223 info.emplace_back(
"* Output Tensors");
227 if (itsReshape.empty() ==
false)
229 if (itsReshape.size() != outs.size())
230 LFATAL(
"Received " << outs.size() <<
" but outreshape has " << itsReshape.size() <<
" entries");
232 info.emplace_back(
"* Reshaped Output Tensors");
233 for (
size_t i = 0; i < outs.size(); ++i)