예제 #1
0
 def __init__(self, para=Parameters.gtn(), debug_mode=False, device='cpu'):
     # Initialize Parameters
     Programclass.Program.__init__(self, device=device, dtype=para['dtype'])
     MLclass.MachineLearning.__init__(self, para, debug_mode)
     MPSclass.MPS.__init__(self)
     self.initialize_parameters_gtn()
     self.name_md5_generate()
     self.debug_mode = debug_mode
     # Initialize MPS and update info
     if not debug_mode:
         self.load_gtn()
     # if not exist saved mps gtn model,then initialize
     if len(self.tensor_data) == 0:
         self.initialize_dataset()
         # Initialize info
         self.generate_tensor_info()
         self.generate_update_info()
         self.initialize_mps_gtn()
     if not self.tensor_data[0].device == self.device:
         for ii in range(len(self.tensor_data)):
             self.tensor_data[ii] = torch.tensor(self.tensor_data[ii],
                                                 device=self.device)
         if device == 'cuda': torch.cuda.empty_cache()
     # Environment Preparation
     self.tensor_input = tuple()
     self.environment_left = tuple()
     self.environment_right = tuple()
     self.environment_zoom = tuple()
예제 #2
0
from library import TNMLclass
from library import Parameters as Pa

pa = Pa.gtn()
A = TNMLclass.GTN(para=pa, device='cuda:0', debug_mode=False)
A.start_learning()
예제 #3
0
from library import MPSMLclass
from library import Parameters

para = Parameters.gtn()
GTN = MPSMLclass.GTN(para=para,
                     device='cpu')  # change device='cuda' to use GPU
GTN.start_learning()