KMeans via sklearn (Python2)
A clustering example using sklearn.
If this is your first time using Binaris, visit our Getting Started page to set up your account for free.
The function in this project uses kmeans to quantize an input image potentially reducing the number of unique colors greatly. This can allow for greater color compression of the input image or pleasing filter-esque effects.
Deploying with pip packages
To deploy a Binaris function that depends on
pip packages we need to rely on the Bob tool. Bob is simple script, which greatly reduces the hassle of building platform-specific python packages. This is accomplished by building the dependencies against the same architecture used by Binaris functions, this way you can guarantee your dependencies will work at runtime.
Outlined below are the steps needed to build with Bob and then subsequently deploy your own kmeans functions.
Install Bob somewhere accessible
git clone https://github.com/binaris/bob.git
Navigate to the "kmeans-sklearn" directory (the same directory this README is in) and run
Note: The first run of Bob builds a Docker image and may take a while
Deploy your function
bn deploy public_kmeans_image_quant_py2
As a final note, keep in mind that you only need to run Bob again if you add or remove pip packages. Changes to the function code itself only require another
Try it out
Visit the URL printed by deploy (for
public_kmeans_image_quant_py2) in your browser and add the image URL you want to run kmeans on.
The optional query param
num_colors can also be used to modify the number of clusters kmeans used to quantify your image.
Note: "0123456789" is merely a placeholder and should be replaced with your personal Binaris account id
Below are example before and after images after running the function with