This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from facenet_pytorch import MTCNN | |
import cv2 | |
from PIL import Image | |
import numpy as np | |
from matplotlib import pyplot as plt | |
from tqdm.notebook import tqdm |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pip install facenet-pytorch |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
centroids.print("Centroids:"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mlpack_kmeans.Cluster(data, k, clusters, centroids); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mlpack::kmeans::KMeans<> mlpack_kmeans(max_iter); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//cluster the data | |
arma::Row<size_t> clusters; | |
arma::mat centroids; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// create data | |
int i = 0; | |
for(; i < samples / 2; ++i) | |
{ | |
data.col(i) = arma::vec({1, 1}) + 0.25*arma::randn<arma::vec>(dim); | |
} | |
for(; i < samples; ++i) | |
{ | |
data.col(i) = arma::vec({2, 3}) + 0.25*arma::randn<arma::vec>(dim); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
arma::mat data(dim, samples, arma::fill::zeros); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int k = 2; //amount of clusters | |
int dim = 2;//dimensionality of program | |
int samples = 50; | |
int max_iter = 10;//maximum number of iterations |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <bits/stdc++.h>// include basic c++ liraries | |
#include <mlpack/methods/kmeans/kmeans.hpp>// mlpack library for k-means | |
#include <armadillo>//ml pack is dependent on armadillo | |
Using namespace std; |