ChrisWu1997 / 2D-Motion-Retargeting

PyTorch implementation for our paper Learning Character-Agnostic Motion for Motion Retargeting in 2D, SIGGRAPH 2019
https://motionretargeting2d.github.io
MIT License
440 stars 86 forks source link

Clustering code #6

Closed karanahujax closed 5 years ago

karanahujax commented 5 years ago

Is the code to cluster the motions into the latent space also available?

ChrisWu1997 commented 5 years ago

Those clusters are made by PCA and t-SNE, and drawn by matplotlib. The code has not been organized for release, but I can put the core code here for temporal usage:

from sklearn.decomposition import PCA
from sklearn.manifold import TSNE

def tsne_on_pca(arr):
    """
    visualize through t-sne on pca reduced data
    :param arr: ndarray, (nr_examples, nr_features)
    :return: ndarray, (nr_examples, 2)
    """
    pca_50 = PCA(n_components=50)
    res = pca_50.fit_transform(arr)
    tsne_2 = TSNE(n_components=2)
    res = tsne_2.fit_transform(res)
    return res

# apply this function on latent vectors

Please let me know if you need further help.

NicksonYap commented 4 years ago

Since the docs did not mention clustering:

Code for clustering: https://github.com/ChrisWu1997/2D-Motion-Retargeting/blob/master/cluster.py

Example for clustering https://github.com/ChrisWu1997/2D-Motion-Retargeting/issues/20#issuecomment-569082008