def get_dataloader(type='segment'): COMP_PATH = './' split = 'test' test_split = path.join(COMP_PATH, 'splits/test.split1.bundle') mapping_loc = path.join(COMP_PATH, 'splits/mapping_bf.txt') GT_folder = path.join( COMP_PATH, 'groundTruth/') #Ground Truth Labels for each training video DATA_folder = path.join(COMP_PATH, 'Data/') #Frame I3D features for all videos actions_dict = read_mapping_dict(mapping_loc) test_feat = load_data(test_split, actions_dict, GT_folder, DATA_folder, datatype=split, target=type) # if type == 'segment': test_dataset = TestDataset(test_feat, test_seg_txt, seed=2) else: # todo pass test_dataloader = tud.DataLoader(test_dataset, batch_size=batch_size, shuffle=False, num_workers=8, pin_memory=True) return test_dataloader
def get_dataloader(type='segment'): valid_feat, valid_labels = load_data(val_split, actions_dict, GT_folder, DATA_folder, datatype=split, target=type) # if type == 'segment': valid_dataset = SegmentDataset(valid_feat, valid_labels) else: valid_dataset = VideoDataset(valid_feat, valid_labels) valid_dataloader = tud.DataLoader(valid_dataset, batch_size=batch_size, shuffle=False, num_workers=8, pin_memory=True) return valid_dataloader
train_split = os.path.join(COMP_PATH, 'splits/train.exclude_val.bundle') #Train Split # train_split = os.path.join(COMP_PATH, 'splits/dev_train.split1.bundle') #Train Split val_split = os.path.join(COMP_PATH, 'splits/val.split1.bundle') test_split = os.path.join(COMP_PATH, 'splits/test.split1.bundle') #Test Split GT_folder = os.path.join( COMP_PATH, 'groundTruth/') #Ground Truth Labels for each training video DATA_folder = os.path.join(COMP_PATH, 'Data/') #Frame I3D features for all videos mapping_loc = os.path.join(COMP_PATH, 'splits/mapping_bf.txt') actions_dict = read_mapping_dict(mapping_loc) data_feat, data_labels = load_data(train_split, actions_dict, GT_folder, DATA_folder, datatype=split, target='file') # valid_feat, valid_labels = load_data(val_split, actions_dict, GT_folder, DATA_folder, datatype=split, target='file') # # balance data # label_dict = b.generate_label_dictionary(data_feat, data_labels) # total_segments = len(data_labels) # data_feat, data_labels = b.balance_data(label_dict, total_segments) # # model part
train_split = os.path.join(COMP_PATH, 'splits/train.exclude_val.bundle') #Train Split # train_split = os.path.join(COMP_PATH, 'splits/dev_train.split1.bundle') #Train Split val_split = os.path.join(COMP_PATH, 'splits/val.split1.bundle') test_split = os.path.join(COMP_PATH, 'splits/test.split1.bundle') #Test Split GT_folder = os.path.join( COMP_PATH, 'groundTruth/') #Ground Truth Labels for each training video DATA_folder = os.path.join(COMP_PATH, 'Data/') #Frame I3D features for all videos mapping_loc = os.path.join(COMP_PATH, 'splits/mapping_bf.txt') actions_dict = read_mapping_dict(mapping_loc) data_feat, data_labels = load_data(train_split, actions_dict, GT_folder, DATA_folder, datatype=split, target='frame') # x = torch.cat(data_feat).reshape(-1, 400) print(len(data_labels)) labels = torch.cat([torch.Tensor(labels) for labels in data_labels]).long().flatten() print(x.shape, labels.shape) # filter 'silent' data mask = labels == 0 labels = labels[~mask] x = x[~mask]
''' training to load train set test to load test set ''' split = 'training' #split = 'test' train_split = os.path.join(COMP_PATH, 'splits/train.split1.bundle') #Train Split test_split = os.path.join(COMP_PATH, 'splits/test.split1.bundle') #Test Split GT_folder = os.path.join(COMP_PATH, 'groundTruth/') #Ground Truth Labels for each training video DATA_folder = os.path.join(COMP_PATH, 'Data/') #Frame I3D features for all videos mapping_loc = os.path.join(COMP_PATH, 'splits/mapping_bf.txt') actions_dict = read_mapping_dict(mapping_loc) data_feat, data_labels = load_data( train_split, actions_dict, GT_folder, DATA_folder, datatype = split) #Get features and labels validation_split = os.path.join(COMP_PATH, 'splits/val.split1.bundle') #Validation split val_data_feat, val_data_labels = load_data( validation_split, actions_dict, GT_folder, DATA_folder, datatype = split) #Get features and labels def train(log_interval, model, device, train_loader, optimizer, epoch): model.train() losses = [] scores = [] for batch_idx, (in_feature, label, seq_length) in enumerate(train_loader): in_feature = in_feature.to(device) label = label.to(device) seq_length = seq_length.to(device) packed_input = u.rnn.pack_padded_sequence(in_feature, seq_length, batch_first=True, enforce_sorted=False).to( device)