示例#1
0
def get_train_test_loaders(is_vid, config, dataset):
    # TODO: REFACTOR LOGIC @!
    batch_size = config['batch_size']
    test_split = .2
    shuffle_dataset = True
    random_seed = 42

    dataset_size = 32560
    indices = list(range(dataset_size))
    split = int(np.floor(test_split * dataset_size))

    if shuffle_dataset:
        np.random.seed(random_seed)
        np.random.shuffle(indices)

    train_indices, test_indices = indices[split:], indices[:split]

    train_sampler = SubsetRandomSampler(train_indices)
    test_sampler = SubsetRandomSampler(test_indices)

    train_dataset = dataset(
        config=config,
        excluded_indices=test_indices,
        transform=NpToTensor(),
        is_vid=is_vid,
    )

    test_dataset = dataset(
        config=config,
        excluded_indices=train_indices,
        transform=NpToTensor(),
        is_vid=is_vid,
    )

    train_loader = DataLoader(train_dataset, batch_size=batch_size,
                              sampler=train_sampler)
    test_loader = DataLoader(test_dataset, batch_size=batch_size,
                             sampler=test_sampler)

    return train_loader, test_loader
示例#2
0
def get_validation_loader(is_vid, config, dataset, augment):
    validation_dataset = dataset(
        config,
        transform=NpToTensor(),
        is_vid=is_vid,
        augment=augment
    )

    validation_dataloader = DataLoader(
        validation_dataset,
        batch_size=config['batch_size'],
        shuffle=True
    )

    return validation_dataloader
示例#3
0
import torch

from configs.config_s1 import CONFIG_S1
from datasets.frei_dataset_s1 import FreiDatasetS1
from models.model_s1 import ModelS1
from trainers.trainer_s1 import TrainerS1
from transforms.np_to_tensor import NpToTensor
from utils.data_utils import get_loaders
from utils.utils import init_build_id

if __name__ == '__main__':
    config = init_build_id(CONFIG_S1)
    print(f"INITIATED BUILD WITH ID: {config['build_id']}")
    dataset = FreiDatasetS1(
        config=config,
        transform=NpToTensor()
    )
    train_loader, test_loader = get_loaders(config['batch_size'], dataset)
    model = ModelS1()
    test_in = next(iter(train_loader))
    # print(test_in['img'])

    # device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
    # model.to(device)
    #
    # hz = model(test_in['img'])

    trainer = TrainerS1(config, train_loader, test_loader, model)
    trainer.train(config['epochs'])
示例#4
0
    print(f"INITIATED BUILD WITH ID: {config['build_id']}")

    test_split = .2
    shuffle_dataset = True
    random_seed = 42
    # Creating data indices for training and validation splits:
    dataset_size = 32560
    indices = list(range(dataset_size))
    split = int(np.floor(test_split * dataset_size))
    if shuffle_dataset:
        np.random.seed(random_seed)
        np.random.shuffle(indices)
    train_indices, test_indices = indices[split:], indices[:split]

    train_dataset = ManoDatasetC(config['train_dataset_path'], NpToTensor(), train_indices)
    test_dataset = ManoXYZDataset(config['test_dataset_path'], NpToTensor())

    # Creating PT data samplers and loaders:
    train_sampler = SubsetRandomSampler(train_indices)
    test_sampler = SubsetRandomSampler(test_indices)

    train_loader = torch.utils.data.DataLoader(train_dataset, batch_size=batch_size,
                                               sampler=train_sampler)
    test_loader = torch.utils.data.DataLoader(test_dataset, batch_size=batch_size,
                                              sampler=test_sampler)

    models = {
        "C0": ModelC(7),
        "C1": ModelC(9)
    }