(tensor)
| 32 | |
| 33 | def merge_params(net_def, data_type): |
| 34 | def tensor_to_bytes(tensor): |
| 35 | if tensor.data_type == mace_pb2.DT_HALF: |
| 36 | data = bytearray( |
| 37 | np.array(tensor.float_data).astype(np.float16).tobytes()) |
| 38 | tensor.data_size = len(tensor.float_data) |
| 39 | elif tensor.data_type == mace_pb2.DT_FLOAT: |
| 40 | data = bytearray( |
| 41 | np.array(tensor.float_data).astype(np.float32).tobytes()) |
| 42 | tensor.data_size = len(tensor.float_data) |
| 43 | elif tensor.data_type == mace_pb2.DT_INT32: |
| 44 | data = bytearray( |
| 45 | np.array(tensor.int32_data).astype(np.int32).tobytes()) |
| 46 | tensor.data_size = len(tensor.int32_data) |
| 47 | elif tensor.data_type == mace_pb2.DT_UINT8: |
| 48 | data = bytearray( |
| 49 | np.array(tensor.int32_data).astype(np.uint8).tolist()) |
| 50 | tensor.data_size = len(tensor.int32_data) |
| 51 | elif tensor.data_type == mace_pb2.DT_INT8: |
| 52 | data = bytearray( |
| 53 | np.array(tensor.int32_data).astype(np.uint8).tolist()) |
| 54 | tensor.data_size = len(tensor.int32_data) |
| 55 | elif tensor.data_type == mace_pb2.DT_FLOAT16: |
| 56 | data = bytearray( |
| 57 | np.array(tensor.float_data).astype(np.float16).tobytes()) |
| 58 | tensor.data_size = len(tensor.float_data) |
| 59 | elif tensor.data_type == mace_pb2.DT_BFLOAT16: |
| 60 | data = Float2BFloat16Bytes(tensor.float_data) |
| 61 | tensor.data_size = len(tensor.float_data) |
| 62 | elif tensor.data_type == mace_pb2.DT_INT16: |
| 63 | data = bytearray( |
| 64 | np.array(tensor.int32_data).astype(np.int16).tobytes()) |
| 65 | tensor.data_size = len(tensor.int32_data) |
| 66 | else: |
| 67 | raise Exception('Tensor data type %s not supported' % |
| 68 | tensor.data_type) |
| 69 | return data |
| 70 | |
| 71 | model_data = [] |
| 72 | offset = 0 |
no test coverage detected