def __init__(self, model, train_set, test_set, output_model_name, testing_mode, folds=None, regression_type=0): self.__model = model self.__x_train, self.__y_train = train_set self.__train_set_size = len(self.__y_train) self.__x_test, self.__y_test = test_set self.__test_set_size = len(self.__y_test) self.__testing_mode = testing_mode self.__cross_val_folds = folds self.__is_cross_val = (folds is not None) self.__features = list(self.__x_train.columns) self.__labels = [ str(l) for l in list(set(self.__y_train).union(set(self.__y_test))) ] self.__metrics = {'model': output_model_name} self.__y_pred = None self.__experiment = Experiment.init( 'test_charts') # replace with: self.__experiment = Experiment() self.__regression_type = SKTrainerRegression.REGRESSION_TYPE[ regression_type] self.__coef, self.__intercept = None, None
def log_trial_start(self, trial): e = CNVRGExperiment.init() self._cnvrg_experiments[trial.trial_id] = e['slug'] config = trial.config.copy() config.pop("callbacks", None) e.log_param("trial_id", trial.trial_id) e.log_param("run_id", trial.trial_id.split("_")[0]) e.log(str(config)) for item in config: e.log_param(item, config.get(item)) e.log("======") e.log(str(trial))
def __init__(self, model, train_set, test_set, output_model_name, testing_mode): self.__model = model self.__x_train, _ = (train_set, None) if len(train_set) == 1 else train_set self.__train_set_size = len(self.__x_train) self.__x_test, self.__y_test = (test_set, None) if len(train_set) == 1 else train_set self.__test_set_size = len(self.__x_test) self.__testing_mode = testing_mode self.__features = list(self.__x_train.columns) self.__metrics = {'model': output_model_name} self.__labeled = len(train_set) == 2 or len(test_set) == 2 # if any of the sets includes target column. # self.__experiment = Experiment() self.__experiment = Experiment.init("test_charts")
model = Net().to(device) # Load checkpoint if args.ckpf != '': if use_cuda: model.load_state_dict(torch.load(args.ckpf)) else: # Load GPU model on CPU model.load_state_dict(torch.load(args.ckpf, map_location=lambda storage, loc: storage)) optimizer = optim.SGD(model.parameters(), lr=args.lr, momentum=args.momentum) try: e = Experiment() except: e = Experiment.init() def train(args, model, device, train_loader, optimizer, epoch): """Training""" model.train() tot_loss = 0 for batch_idx, (data, target) in enumerate(train_loader): data, target = data.to(device), target.to(device) optimizer.zero_grad() output = model(data) loss = F.nll_loss(output, target) loss.backward() optimizer.step()