| 58 | } |
| 59 | |
| 60 | std::shared_ptr<Tensor> lite::example::parse_npy( |
| 61 | const std::string& path, LiteBackend backend) { |
| 62 | std::string type_str; |
| 63 | std::vector<npy::ndarray_len_t> stl_shape; |
| 64 | std::vector<int8_t> raw; |
| 65 | npy::LoadArrayFromNumpy(path, type_str, stl_shape, raw); |
| 66 | |
| 67 | auto lite_tensor = std::make_shared<Tensor>(backend, LiteDeviceType::LITE_CPU); |
| 68 | Layout layout; |
| 69 | layout.ndim = stl_shape.size(); |
| 70 | const std::map<std::string, LiteDataType> type_map = { |
| 71 | {"f4", LiteDataType::LITE_FLOAT}, |
| 72 | {"i4", LiteDataType::LITE_INT}, |
| 73 | {"i1", LiteDataType::LITE_INT8}, |
| 74 | {"u1", LiteDataType::LITE_UINT8}}; |
| 75 | layout.shapes[0] = 1; |
| 76 | for (size_t i = 0; i < layout.ndim; i++) { |
| 77 | layout.shapes[i] = static_cast<size_t>(stl_shape[i]); |
| 78 | } |
| 79 | |
| 80 | for (auto& item : type_map) { |
| 81 | if (type_str.find(item.first) != std::string::npos) { |
| 82 | layout.data_type = item.second; |
| 83 | break; |
| 84 | } |
| 85 | } |
| 86 | lite_tensor->set_layout(layout); |
| 87 | size_t length = lite_tensor->get_tensor_total_size_in_byte(); |
| 88 | void* dest = lite_tensor->get_memory_ptr(); |
| 89 | memcpy(dest, raw.data(), length); |
| 90 | //! rknn not support reshape now |
| 91 | if (layout.ndim == 3) { |
| 92 | lite_tensor->reshape( |
| 93 | {1, static_cast<int>(layout.shapes[0]), |
| 94 | static_cast<int>(layout.shapes[1]), |
| 95 | static_cast<int>(layout.shapes[2])}); |
| 96 | } |
| 97 | return lite_tensor; |
| 98 | } |
| 99 | |
| 100 | void lite::example::set_cpu_affinity(const std::vector<int>& cpuset) { |
| 101 | #if defined(__APPLE__) || defined(WIN32) || defined(_WIN32) |
nothing calls this directly
no test coverage detected