Calculate the weighted adjacency matrix for image labels

Hello,

I am trying to calculate the weighted adjacency matrix for image labels, its size for example [8,500,500,1], is there an existent function in PyTorch to do that? or is there an effective and fast way to compute the weighted adjacency matrix?

Thanks in advance.