From 137dc8765e986a83f270be176c1897d94022e7b4 Mon Sep 17 00:00:00 2001 From: Christoph Eder Date: Thu, 18 Dec 2025 16:09:46 +0100 Subject: [PATCH 1/3] Changes in symbol.py Image is now stored as a np array again --- anansyTypes/structures/symbol.py | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/anansyTypes/structures/symbol.py b/anansyTypes/structures/symbol.py index e7cf104..8e182d0 100644 --- a/anansyTypes/structures/symbol.py +++ b/anansyTypes/structures/symbol.py @@ -11,22 +11,21 @@ import base64 class Symbol: id: int label: str - image: Tensor[np.ndarray[Any, Any], tuple, Literal["int32", "int64"]] + image: np.ndarray @classmethod def from_dict(cls, data: dict) -> "Symbol": - # if isinstance(data["image"], str): - # # Decode from base64 - # image_bytes = base64.b64decode(data["image"]) - # image_array = np.frombuffer(image_bytes, dtype=np.uint8) - # else: - # # From list/array - # image_array = np.array(data["image"], dtype=np.int32) - image_data=data["image"].encode("utf-8") + if isinstance(data["image"], str): + # Decode base64 to numpy array + image_bytes = base64.b64decode(data["image"]) + image_array = np.frombuffer(image_bytes, dtype=np.uint8) + else: + image_array = np.array(data["image"], dtype=np.uint8) + return cls( id=data["id"], label=data["label"], - image=image_data, + image=image_array, ) @classmethod @@ -46,7 +45,7 @@ class Symbol: lambda x: { "id": x.id, "label": x.label, - "image": x.image.decode("utf-8"), + "image": base64.b64encode(x.image.tobytes()).decode("utf-8"), }, when_used="json", ), From af2abad1ff268fc8cbd719841a87a5f63060f976 Mon Sep 17 00:00:00 2001 From: Christoph Eder Date: Thu, 18 Dec 2025 16:11:44 +0100 Subject: [PATCH 2/3] Changes in symbol.py Removed tobytes as it is already bytes --- anansyTypes/structures/symbol.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/anansyTypes/structures/symbol.py b/anansyTypes/structures/symbol.py index 8e182d0..7fefbbc 100644 --- a/anansyTypes/structures/symbol.py +++ b/anansyTypes/structures/symbol.py @@ -45,7 +45,7 @@ class Symbol: lambda x: { "id": x.id, "label": x.label, - "image": base64.b64encode(x.image.tobytes()).decode("utf-8"), + "image": base64.b64encode(x.image).decode("utf-8"), }, when_used="json", ), From a4799f2c3faa879819d560db0abe38665952e009 Mon Sep 17 00:00:00 2001 From: Christoph Eder Date: Thu, 18 Dec 2025 16:18:36 +0100 Subject: [PATCH 3/3] Changes in symbol.py Trying just bytes now --- anansyTypes/structures/symbol.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/anansyTypes/structures/symbol.py b/anansyTypes/structures/symbol.py index 7fefbbc..fa211f9 100644 --- a/anansyTypes/structures/symbol.py +++ b/anansyTypes/structures/symbol.py @@ -11,21 +11,19 @@ import base64 class Symbol: id: int label: str - image: np.ndarray + image: bytes @classmethod def from_dict(cls, data: dict) -> "Symbol": if isinstance(data["image"], str): - # Decode base64 to numpy array image_bytes = base64.b64decode(data["image"]) - image_array = np.frombuffer(image_bytes, dtype=np.uint8) else: - image_array = np.array(data["image"], dtype=np.uint8) + image_bytes = bytes(data["image"]) return cls( id=data["id"], label=data["label"], - image=image_array, + image=image_bytes, ) @classmethod