yl-1993 / learn-to-cluster

Learning to Cluster Faces (CVPR 2019, CVPR 2020)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

building symmetric adjacency matrix in utils

marigoold opened this issue · comments

def build_symmetric_adj(adj, self_loop=True):
adj = adj + adj.T.multiply(adj.T > adj) - adj.multiply(adj.T > adj)
if self_loop:
adj = adj + sp.eye(adj.shape[0])
return adj

The original adjacency matrix built from faiss is not symmetric, so what is the purpose to convert it to symmetric matrix? And why do you implement it in this way?

def row_normalize(mx):
"""Row-normalize sparse matrix"""
rowsum = np.array(mx.sum(1))
# if rowsum <= 0, keep its previous value
rowsum[rowsum <= 0] = 1
r_inv = np.power(rowsum, -1).flatten()
r_inv[np.isinf(r_inv)] = 0.
r_mat_inv = sp.diags(r_inv)
mx = r_mat_inv.dot(mx)
return mx

By the way, what is the purpose of row_normalize, and # if rowsum <= 0, keep its previous value?