trSet = ngsimDataset('data/TrainSet.mat') valSet = ngsimDataset('data/ValSet.mat') trDataloader = DataLoader(trSet, batch_size=batch_size, shuffle=True, num_workers=8, collate_fn=trSet.collate_fn) valDataloader = DataLoader(valSet, batch_size=batch_size, shuffle=True, num_workers=8, collate_fn=valSet.collate_fn) # Initialize network net = highwayNet(params, newFeats=newFeats, behavFeats=behavFeats) print(net) if params.use_cuda: net = net.cuda() # Set the random seed for reproducible experiments random.seed(30) torch.manual_seed(230) if params.use_cuda: torch.cuda.manual_seed(230) # This corrects for the differences in dropout, batch normalization during training and testing. # No dropout, batch norm so far; but it is a good default practice anyways net.train() ## Initialize optimizer pretrainEpochs = 0
args['use_cuda'] = True args['encoder_size'] = 64 # lstm encoder hidden state size, adjustable args['decoder_size'] = 128 # lstm decoder hidden state size, adjustable args['in_length'] = 16 args['out_length'] = 5 args['grid_size'] = (13, 3) args[ 'input_embedding_size'] = 32 # input dimension for lstm encoder, adjustable args['train_flag'] = True start_time = datetime.datetime.now() # Initialize network net = highwayNet(args) if args['use_cuda']: net = net.cuda() ## Initialize optimizer trainEpochs = 10 optimizer = torch.optim.Adam(net.parameters()) #lr = ... batch_size = 128 crossEnt = torch.nn.BCELoss() # binary cross entropy ## Initialize data loaders trSet = ngsimDataset('../../data/trajectory/TrainSet.mat') valSet = ngsimDataset('../../data/trajectory/ValSet.mat') trDataloader = DataLoader(trSet, batch_size=batch_size, shuffle=True,
utils.set_logger(os.path.join(args['model_dir'], 'evaluate.log')) json_path = os.path.join(args['model_dir'], 'params.json') assert os.path.isfile( json_path), "No json configuration file found at {}".format(json_path) params = utils.Params(json_path) params.grid_size = (params.grid_size_lon, params.grid_size_lat) # use GPU if available params.use_cuda = torch.cuda.is_available() params.train_flag = args['train_flag'] params.model_dir = args['model_dir'] # Initialize network batch_size = 128 net = highwayNet(params) net_path = os.path.join(args['model_dir'], 'best.pth.tar') assert os.path.isfile(net_path), "No net file found at {}".format(net_path) #net.load_state_dict(torch.load('trained_models/cslstm_m.tar')) utils.load_checkpoint(net_path, net) if params.use_cuda: net = net.cuda() net.eval() # https://scipython.com/blog/visualizing-the-bivariate-gaussian-distribution/ def bivariate_normal(X,