import os import time import shutil import random import torch import numpy as np import sys sys.path.append("..") from util import util, transformer, dataloader, statistics, plot, options from util import array_operation as arr from models import creatnet, core # -----------------------------Init----------------------------- opt = options.Options() opt.parser.add_argument('--rec_tmp', type=str, default='./server_data/rec_data', help='') opt = opt.getparse() opt.k_fold = 0 opt.save_dir = './checkpoints' util.makedirs(opt.save_dir) util.makedirs(opt.rec_tmp) # -----------------------------Load original data----------------------------- signals, labels = dataloader.loaddataset(opt) ori_signals_train,ori_labels_train,ori_signals_eval,ori_labels_eval = \ signals[:opt.fold_index[0]].copy(),labels[:opt.fold_index[0]].copy(),signals[opt.fold_index[0]:].copy(),labels[opt.fold_index[0]:].copy() label_cnt, label_cnt_per, label_num = statistics.label_statistics(labels) opt = options.get_auto_options(opt, label_cnt_per, label_num,
import os import time import numpy as np import torch from torch import nn, optim import warnings warnings.filterwarnings("ignore") from util import util, plot, options from data import augmenter, transforms, dataloader, statistics import core opt = options.Options().getparse() """Use your own data to train * step1: Generate signals.npy and labels.npy in the following format. # 1.type:numpydata signals:np.float32 labels:np.int64 # 2.shape signals:[num,ch,length] labels:[num] # num:samples_num, ch :channel_num, length:length of each sample # for example: signals = np.zeros((10,1,10),dtype='np.float64') labels = np.array([0,0,0,0,0,1,1,1,1,1]) #0->class0 1->class1 * step2: input ```--dataset_dir your_dataset_dir``` when running code. """ #----------------------------Load Data---------------------------- t1 = time.time() signals, labels = dataloader.loaddataset(opt) if opt.gan: signals, labels = augmenter.dcgan(opt, signals, labels) label_cnt, label_cnt_per, label_num = statistics.label_statistics(labels)