| 695 | */ |
| 696 | template <typename T> |
| 697 | void load_trained_data(T &tensor, const std::string &filename) |
| 698 | { |
| 699 | ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(&tensor, 1, DataType::F32); |
| 700 | |
| 701 | std::ifstream fs; |
| 702 | |
| 703 | try |
| 704 | { |
| 705 | fs.exceptions(std::ofstream::failbit | std::ofstream::badbit | std::ofstream::eofbit); |
| 706 | // Open file |
| 707 | fs.open(filename, std::ios::in | std::ios::binary); |
| 708 | |
| 709 | if (!fs.good()) |
| 710 | { |
| 711 | throw std::runtime_error("Could not load binary data: " + filename); |
| 712 | } |
| 713 | |
| 714 | // Map buffer if creating a CLTensor |
| 715 | map(tensor, true); |
| 716 | |
| 717 | Window window; |
| 718 | |
| 719 | window.set(arm_compute::Window::DimX, arm_compute::Window::Dimension(0, 1, 1)); |
| 720 | |
| 721 | for (unsigned int d = 1; d < tensor.info()->num_dimensions(); ++d) |
| 722 | { |
| 723 | window.set(d, Window::Dimension(0, tensor.info()->tensor_shape()[d], 1)); |
| 724 | } |
| 725 | |
| 726 | arm_compute::Iterator in(&tensor, window); |
| 727 | |
| 728 | execute_window_loop( |
| 729 | window, |
| 730 | [&](const Coordinates &) |
| 731 | { |
| 732 | fs.read(reinterpret_cast<std::fstream::char_type *>(in.ptr()), |
| 733 | tensor.info()->tensor_shape()[0] * tensor.info()->element_size()); |
| 734 | }, |
| 735 | in); |
| 736 | |
| 737 | // Unmap buffer if creating a CLTensor |
| 738 | unmap(tensor); |
| 739 | } |
| 740 | catch (const std::ofstream::failure &e) |
| 741 | { |
| 742 | ARM_COMPUTE_ERROR_VAR("Writing %s: (%s)", filename.c_str(), e.what()); |
| 743 | } |
| 744 | } |
| 745 | |
| 746 | template <typename T, typename TensorType> |
| 747 | void fill_tensor_value(TensorType &tensor, T value) |