parser.add_argument('--num-ref-points', type=int, default=128) parser.add_argument('--classify-pertp', action='store_true') args = parser.parse_args() if __name__ == '__main__': experiment_id = int(SystemRandom().random() * 100000) print(args, experiment_id) seed = args.seed torch.manual_seed(seed) np.random.seed(seed) torch.cuda.manual_seed(seed) random.seed(seed) device = torch.device('cuda' if torch.cuda.is_available() else 'cpu') if args.dataset == 'physionet': data_obj = utils.get_physionet_data(args, 'cpu', args.quantization) elif args.dataset == 'mimiciii': data_obj = utils.get_mimiciii_data(args) train_loader = data_obj["train_dataloader"] test_loader = data_obj["test_dataloader"] val_loader = data_obj["val_dataloader"] dim = data_obj["input_dim"] if args.enc == 'enc_rnn3': rec = models.enc_rnn3(dim, torch.linspace(0, 1., 128), args.latent_dim, args.rec_hidden, 128, learn_emb=args.learn_emb).to(device)
import numpy as np from sklearn.model_selection import train_test_split from utils import get_physionet_data from models.ecg import ECGModel # Load Physionet ECG data _, data = get_physionet_data() print('%i subjects loaded' % len(data)) # Train-validation split ids = np.array(list(data.keys())) train_ids, val_ids = train_test_split(ids, test_size=0.2, random_state=38) train_data = [data[id] for id in train_ids] val_data = [data[id] for id in val_ids] # Train and save weights trained_model_path = './trained_models/physionet' model = ECGModel(latent_space_dim=8, batch_size=64, hidden_dim=128, learning_rate=5e-4, log_dir=trained_model_path) model.fit(train_data, val_data) model.save_weights(trained_model_path)