[b52eda]: / Graph_Conversion.py

Download this file

21 lines (17 with data), 678 Bytes

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
from torch.cuda import LongTensor
from numpy import ndarray, array, int32, append, flip
def Convert_To_Image(tensor: LongTensor, adj_count: int) -> ndarray:
r"""
Arguments:
tensor (torch.cuda.LongTensor): Graph as tensor.
Returns:
out (numpy.ndarray): Converted image.
"""
tensor = tensor.cpu()
out = array([tensor[0:512]], dtype = int32)
for i in range(1, 512):
if i % 2 == 1:
out = append(out, flip([tensor[i*adj_count:adj_count+i*adj_count]]), axis = 0)
else:
out = append(out, [tensor[i*adj_count:adj_count+i*adj_count]], axis = 0)
return out