in fairmotion/viz/tsne.py [0:0]
def main(args):
all_features = []
filenames = []
with open(args.features_file) as f:
for line in f:
filename, features = line.split(":")
all_features.append(
np.array(list(map(float, features.strip().split())))
)
filenames.append(filename.strip())
norm_features = normalize_features(all_features)
if args.algorithm == "tsne":
embeddings = get_tsne_embeddings(norm_features)
elif args.algorithm == "mds":
embeddings = get_mds_embeddings(norm_features)
filename2label = {}
if args.clusters_file:
with open(args.clusters_file) as f:
for line in f:
label_and_score, filename = line.split(":")
label = int(label_and_score.strip().split(",")[0])
filename2label[filename.strip()] = label
plot_embeddings(
filename=args.output_file,
X=embeddings,
labels=[filename2label[filename] for filename in filenames]
if args.clusters_file
else None,
)