| 149 | } |
| 150 | |
| 151 | void DataParser::parse_npy(const std::string& name, const std::string& path) { |
| 152 | std::string type_str; |
| 153 | std::vector<npy::ndarray_len_t> stl_shape; |
| 154 | std::vector<int8_t> raw; |
| 155 | npy::LoadArrayFromNumpy(path, type_str, stl_shape, raw); |
| 156 | |
| 157 | megdnn::SmallVector<size_t> shape; |
| 158 | for (auto val : stl_shape) { |
| 159 | shape.append({static_cast<size_t>(val)}); |
| 160 | } |
| 161 | |
| 162 | const std::map<std::string, megdnn::DType> type_map = { |
| 163 | {"f4", mgb::dtype::Float32()}, {"i4", mgb::dtype::Int32()}, |
| 164 | {"i2", mgb::dtype::Int16()}, {"u2", mgb::dtype::Uint16()}, |
| 165 | {"i1", mgb::dtype::Int8()}, {"u1", mgb::dtype::Uint8()}}; |
| 166 | |
| 167 | megdnn::DType hv_type; |
| 168 | for (auto& item : type_map) { |
| 169 | if (type_str.find(item.first) != std::string::npos) { |
| 170 | hv_type = item.second; |
| 171 | break; |
| 172 | } |
| 173 | } |
| 174 | |
| 175 | mgb::HostTensorND hv; |
| 176 | hv.comp_node(mgb::CompNode::default_cpu(), true).dtype(hv_type).resize(shape); |
| 177 | mgb::dt_byte* raw_ptr = hv.raw_ptr(); |
| 178 | memcpy(raw_ptr, raw.data(), raw.size()); |
| 179 | |
| 180 | inputs.insert(std::make_pair(name, std::move(hv))); |
| 181 | } |
| 182 | |
| 183 | void DataParser::parse_string(const std::string& name, const std::string& str) { |
| 184 | //! parse shape |