GROUP "/" ㄴGROUP "tensor name" ㄴDATASET "weights" : Shape (x, y, ...), type(uint8, int16) ㄴDATASET "min" : Shape (n) ㄴDATASET "max" : Shape (n) ㄴDATASET "scale" : Shape (m) ㄴDATASET "zero_point" : Shape (m)
NOTE All Dataset is optional. It means that if tensor doesn't have the data, it won't be created as a Dataset
302{
303
305 uint32_t num_subgraph = reader.num_subgraph();
306
307
309
310 for (uint32_t subgraph_idx = 0; subgraph_idx < num_subgraph; subgraph_idx++)
311 {
312 reader.select_subgraph(subgraph_idx);
313
314 auto tensors = reader.tensors();
315 for (const auto &tensor : *tensors)
316 {
317
319 if (tensor_name == nullptr)
320 {
321 assert(false && "There is no tensor name");
322 continue;
323 }
324
325
327 std::unique_ptr<H5::Group> tensor_group =
328 std::make_unique<H5::Group>(
file.createGroup(group_name));
329
330
331 uint32_t buff_idx =
tensor->buffer();
332 auto buff_data_ptr = reader.buffers()->Get(buff_idx)->data();
333 if (buff_data_ptr)
334 {
335 ::write_vector_data_to_hdf5(file, group_name,
"weights", ::hdf5_dtype_cast(
tensor->type()),
336 buff_data_ptr,
337 ::hdf5_dims_cast(buff_data_ptr,
tensor->shape()));
338 }
339
340
341 auto quant_param =
tensor->quantization();
342 if (quant_param)
343 {
344 auto min = quant_param->min();
345 ::write_vector_data_to_hdf5(file, group_name, "min", H5::PredType::NATIVE_FLOAT, min,
346 ::hdf5_dims_cast(min));
347 auto max = quant_param->max();
348 ::write_vector_data_to_hdf5(file, group_name, "max", H5::PredType::NATIVE_FLOAT, max,
349 ::hdf5_dims_cast(max));
350 auto scale = quant_param->scale();
351 ::write_vector_data_to_hdf5(file, group_name, "scale", H5::PredType::NATIVE_FLOAT, scale,
352 ::hdf5_dims_cast(scale));
353 auto zero_point = quant_param->zero_point();
354 ::write_vector_data_to_hdf5(file, group_name, "zero_point", H5::PredType::NATIVE_INT64,
355 zero_point, ::hdf5_dims_cast(zero_point));
356 auto quantized_dimension = quant_param->quantized_dimension();
357 ::write_scalar_data_to_hdf5(file, group_name, "quantized_dimension",
358 H5::PredType::NATIVE_INT32, quantized_dimension);
359 }
360 }
361 }
362}
Loads Circle file and provides helpers to access attributes.
const char * tensor_name(const circle::Tensor *tensor)
std::string mangle(const std::string &name)
Construct HDF5-compatible dataset name from a given string.