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