[PYTHON] can't pickle annoy. How to deal with Annoy objects

The machine learning model was managed by the basic pickle, but for Annoy, the following error occurs when saving with pickle.

can't pickle annoy.Annoy objects

For the time being, let's google and see the hit issue.

https://github.com/spotify/annoy/issues/367

image.png

apparently. ..

If you look at the Sample code properly, you can see that the load method and save method were prepared.

So, according to this sample code

from annoy import AnnoyIndex
import random

f = 40
t = AnnoyIndex(f, 'angular')  # Length of item vector that will be indexed
for i in range(1000):
    v = [random.gauss(0, 1) for z in range(f)]
    t.add_item(i, v)

t.build(10) # 10 trees
t.save('test.ann') #Save

# ...

u = AnnoyIndex(f, 'angular')
u.load('test.ann') # super fast, will just mmap the file #Read
print(u.get_nns_by_item(0, 1000)) # will find the 1000 nearest neighbors

It seems to be okay if you set it to.

Recommended Posts

can't pickle annoy. How to deal with Annoy objects
How to deal with imbalanced data
How to deal with imbalanced data
How to deal with DistributionNotFound errors
How to deal with enum compatibility errors
[Python] How to deal with module errors
How to deal with memory leaks in matplotlib.pyplot
How to deal with run-time errors in subprocess.call
How to deal with module'tensorflow' has no attribute'〇〇'
How to deal with SessionNotCreatedException when using Selenium
How to deal with Django's Template Does Not Exist
[Python] How to deal with pandas read_html read error
How to deal with Executing transaction: failed in Anaconda
How to update with SQLAlchemy?
How to cast with Theano
How to Alter with SQLAlchemy?
How to separate strings with','
How to RDP with Fedora31
2 ways to deal with SessionNotCreatedException
How to Delete with SQLAlchemy?
[Linux] How to deal with garbled characters when viewing files
[AWS] How to deal with "Invalid codepoint" error in CloudSearch
A story about how to deal with the CORS problem
For beginners, how to deal with common errors in keras
How to deal with UnicodeDecodeError when executing google image download
How to cancel RT with tweepy
Python: How to use async with
How to use virtualenv with PowerShell
How to install python-pip with ubuntu20.04LTS
How to get started with Scrapy
How to get started with Python
How to get started with Django
How to Data Augmentation with PyTorch
How to use FTP with Python
How to calculate date with python
How to install mysql-connector with pip3
How to INNER JOIN with SQLAlchemy
How to install Anaconda with pyenv
How to authenticate with Django Part 2
How to authenticate with Django Part 3
How to deal with python installation error in pyenv (BUILD FAILED)
How to enable Keras Regressor to be saved with pickle or joblib
How to deal with errors when installing whitenoise and deploying to Heroku
How to install pandas on EC2 (How to deal with MemoryError and PermissionError)
How to deal with errors when installing Python and pip with choco
How to do arithmetic with Django template
[Blender] How to set shape_key with script
I want to detect objects with OpenCV
How to title multiple figures with matplotlib
How to get parent id with sqlalchemy
How to add a package with PyCharm
How to install DLIB with 2020 / CUDA enabled
How to deal with OAuth2 error when using Google APIs from Python
How to use ManyToManyField with Django's Admin
How to use Cmder with PyCharm (Windows)
How to prevent package updates with apt
How to work with BigQuery in Python
How to use Ass / Alembic with HtoA
How to deal with SSL error when connecting to S3 with boto of Python
How to use Japanese with NLTK plot
How to do portmanteau test with python