Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exemplar dict is not serializable #13

Open
trifle opened this issue Jun 11, 2022 · 3 comments
Open

Exemplar dict is not serializable #13

trifle opened this issue Jun 11, 2022 · 3 comments

Comments

@trifle
Copy link

trifle commented Jun 11, 2022

Hi, thanks for your awesome libraries.

Just a short question: In this line:

representative_images[cluster] = {"Indices": [int(index) for index in exemplars],

you're casting the numpy int64s to integers, presumably so they can be used as indexes?
In any case, the cluster keys remain np.int64. This means the whole dict cannot be serialized (as json doesn't know how to handle numpy data types).

My suggestion would be to int() the keys as well to make this a bit less perplexing. But I'm not sure if you rely on the indexes being np.int64 in some other place?

@MaartenGr
Copy link
Owner

Thank you for finding this! Did you encounter any issues with saving the model due to keeping the cluster keys as np.int64? Or was there another use case for which this is an issue?

@trifle
Copy link
Author

trifle commented Jun 14, 2022

Hi, I've simply tried to json.dump() the cluster keys in an attempt to store all the gritty details from the analysis to inspect and save for later. What surprised me was that even default=str failed to convince json to serialize the dict. That's when I found out that the default apparently (and somewhat sensibly) only applies to values, and having np.int64 as keys is not within the json spec.

@MaartenGr
Copy link
Owner

Ah, right, that makes sense! I am not entirely sure but I do not think it should be any problem to cast them as regular int in that specific function. It seems that cluster in representative_images[cluster] is derived from items in self.cluster_labels which I think can be regular int.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants