diff options
author | Jeremy Johnson <jeremy.johnson@arm.com> | 2022-09-15 12:16:07 +0100 |
---|---|---|
committer | Jeremy Johnson <jeremy.johnson@arm.com> | 2022-09-15 12:57:21 +0100 |
commit | c92710d7259558fb0cd9e9b38d0c78da21c6e2d4 (patch) | |
tree | 657a3cf2921a8bd8cc9a360cc85eee4ff8aeeb67 /python/serializer/tosa_serializer.py | |
parent | 4381b3d7fcb7cab975f46c62c86a35c53ade047f (diff) | |
download | serialization_lib-c92710d7259558fb0cd9e9b38d0c78da21c6e2d4.tar.gz |
Fix for CONST floats always truncated to integer values.
Add way of saving CONSTs to numpy file for testing purposes.
Signed-off-by: Jeremy Johnson <jeremy.johnson@arm.com>
Change-Id: Ic3a22da8ec3432037832374090b7ceff345d48de
Diffstat (limited to 'python/serializer/tosa_serializer.py')
-rw-r--r-- | python/serializer/tosa_serializer.py | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/python/serializer/tosa_serializer.py b/python/serializer/tosa_serializer.py index a71f3c9..acec4b7 100644 --- a/python/serializer/tosa_serializer.py +++ b/python/serializer/tosa_serializer.py @@ -362,12 +362,17 @@ class TosaSerializerTensor: self.shape = shape self.dtype = dtype + if dtype == DType.FLOAT: + fntype = np.float32 + else: + fntype = int + if isinstance(data, np.ndarray): - data = data.flatten().astype(int).tolist() - data = list(map(int, data)) + data = data.flatten().astype(fntype).tolist() + data = list(map(fntype, data)) self.data = data elif isinstance(data, list): - data = list(map(int, data)) + data = list(map(fntype, data)) self.data = data else: self.data = None @@ -569,7 +574,7 @@ class TensorDir(IntEnum): class TosaSerializer: - def __init__(self, pathPrefix): + def __init__(self, pathPrefix, saveConstsToFile=False): self.add_compat_methods() # Get the global TOSA version if not already defined @@ -579,6 +584,9 @@ class TosaSerializer: self.startBasicBlock("main") self.pathPrefix = pathPrefix + # Enables inspection of constant data outside of graph + self.saveConstsToFile = saveConstsToFile + # Indicies used for adding/naming tensors self.currInputIdx = 0 self.currConstIdx = 0 @@ -624,6 +632,10 @@ class TosaSerializer: # Add the operator now self.currBasicBlock.addOperator(TosaOp.Op().CONST, [], name) + if self.saveConstsToFile: + filename = "{}.npy".format(name) + np.save(os.path.join(self.pathPrefix, filename), vals, False) + return tens def addIntermediate(self, shape, dtype): |