Gets tensor details. Args: tensor_index: Tensor index of tensor to query. Returns: a dictionary containing the name, index, shape and type of the tensor. Raises: ValueError: If tensor_index is invalid.
(self, tensor_index)
| 272 | data access.""") |
| 273 | |
| 274 | def _get_tensor_details(self, tensor_index): |
| 275 | """Gets tensor details. |
| 276 | |
| 277 | Args: |
| 278 | tensor_index: Tensor index of tensor to query. |
| 279 | |
| 280 | Returns: |
| 281 | a dictionary containing the name, index, shape and type of the tensor. |
| 282 | |
| 283 | Raises: |
| 284 | ValueError: If tensor_index is invalid. |
| 285 | """ |
| 286 | tensor_index = int(tensor_index) |
| 287 | tensor_name = self._interpreter.TensorName(tensor_index) |
| 288 | tensor_size = self._interpreter.TensorSize(tensor_index) |
| 289 | tensor_type = self._interpreter.TensorType(tensor_index) |
| 290 | tensor_quantization = self._interpreter.TensorQuantization(tensor_index) |
| 291 | |
| 292 | if not tensor_name or not tensor_type: |
| 293 | raise ValueError('Could not get tensor details') |
| 294 | |
| 295 | details = { |
| 296 | 'name': tensor_name, |
| 297 | 'index': tensor_index, |
| 298 | 'shape': tensor_size, |
| 299 | 'dtype': tensor_type, |
| 300 | 'quantization': tensor_quantization, |
| 301 | } |
| 302 | |
| 303 | return details |
| 304 | |
| 305 | def get_tensor_details(self): |
| 306 | """Gets tensor details for every tensor with valid tensor details. |