Given a blob object, return the Caffe2 operator that creates this blob as constant. Currently support NumPy tensor and Caffe2 Int8Tensor.
(
name: str,
blob: Union[np.ndarray, workspace.Int8Tensor],
device_option: Optional[caffe2_pb2.DeviceOption] = None,
)
| 263 | |
| 264 | |
| 265 | def create_const_fill_op( |
| 266 | name: str, |
| 267 | blob: Union[np.ndarray, workspace.Int8Tensor], |
| 268 | device_option: Optional[caffe2_pb2.DeviceOption] = None, |
| 269 | ) -> caffe2_pb2.OperatorDef: |
| 270 | """ |
| 271 | Given a blob object, return the Caffe2 operator that creates this blob |
| 272 | as constant. Currently support NumPy tensor and Caffe2 Int8Tensor. |
| 273 | """ |
| 274 | |
| 275 | tensor_type = type(blob) |
| 276 | assert tensor_type in [ |
| 277 | np.ndarray, |
| 278 | workspace.Int8Tensor, |
| 279 | ], 'Error when creating const fill op for "{}", unsupported blob type: {}'.format( |
| 280 | name, type(blob) |
| 281 | ) |
| 282 | |
| 283 | if tensor_type == np.ndarray: |
| 284 | return _create_const_fill_op_from_numpy(name, blob, device_option) |
| 285 | elif tensor_type == workspace.Int8Tensor: |
| 286 | assert device_option is None |
| 287 | return _create_const_fill_op_from_c2_int8_tensor(name, blob) |
| 288 | |
| 289 | |
| 290 | def construct_init_net_from_params( |
no test coverage detected