def __init__(self, inputs_list, model): super().__init__() self.node = model ######### Set up node ######### # Freeze parameters of node for params in self.node.parameters(): params.requires_grad = False self.indices_node = np.arange(len(self.node.amplitude)) ######### set learnable parameters ######### control_list = self.set_controls(inputs_list) ###### Set everything as torch Tensors and send to DEVICE ###### self.inputs_list = TorchUtils.get_tensor_from_list( inputs_list, torch.int64) self.control_list = TorchUtils.get_tensor_from_list( control_list, torch.int64 ) # IndexError: tensors used as indices must be long, byte or bool tensors
def load_model(self, configs): """Loads a pytorch model from a directory string.""" self.info, state_dict = self.load_file(configs['torch_model_dict'], 'pt') if 'smg_configs' in self.info.keys(): model_dict = self.info['smg_configs']['processor'] else: model_dict = self.info super().__init__(model_dict) self.configs = configs self.load_state_dict(state_dict) self.init_max_and_min_values() self.amplification = TorchUtils.get_tensor_from_list(self.info['data_info']['processor']['amplification']) self.init_noise_configs()
def init_max_and_min_values(self): self.offset = TorchUtils.get_tensor_from_list(self.info['data_info']['input_data']['offset']) self.amplitude = TorchUtils.get_tensor_from_list(self.info['data_info']['input_data']['amplitude']) self.min_voltage = self.offset - self.amplitude self.max_voltage = self.offset + self.amplitude