File size: 855 Bytes
ea8c728
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import sys
import pathlib

BASE_DIR = pathlib.Path(__file__).parents[1]
sys.path.append(str(BASE_DIR))

# torch & related imports
import numpy as np

# local imports
from utils.utils import *


def generate_random_dataset(file_path: str, n: int, instances_number: int = 128) -> None:
    np.save(file_path, np.random.uniform(0, 1, size=(instances_number, n, 2)))


def _load_points(file_path: str) -> np.ndarray:
    return np.load(file_path)


def load_points(output_dir: str, n: int, instances_count: int = 128) -> np.ndarray:
    file_path = pathlib.Path(output_dir) / f"points/{n}.npy"

    if not is_file_exist(str(file_path)):
        create_dir(str(file_path.parent))

        # generating a new dataset
        generate_random_dataset(str(file_path), n, instances_number=instances_count)

    return _load_points(str(file_path))[:instances_count]