Reputation: 25
Currently The K-means CLustring code is written like this in a method:
def predict(image_path):
image = cv2.imread(image_path)
image = image.reshape((image.shape[0] * image.shape[1], 3))
clt = KMeans(n_clusters = 3, random_state=2, n_jobs=1)
clt.fit(image)
How can I save This to a model so I can convert it to Core-ML and use it in my application?
Upvotes: 2
Views: 6140
Reputation: 31
import joblib
joblib.dump(reducer, umap_model_path)
loaded_reducer = joblib.load(your_model_path)
embedding = loaded_reducer.fit_transform(data_to_predict)
using joblib allow you to set the prediction accuracy also
Upvotes: 0
Reputation: 7892
Core ML does not support K-means clustering at the moment.
You can find a simple implementation of K-means at the Swift Algorithm Club.
Upvotes: 1
Reputation: 75
Save:
pickle.dump(clt, open("save.pkl", "wb"))
Load:
clt = pickle.load(open("save.pkl", "rb"))
Upvotes: 6