automl / NASLib

NASLib is a Neural Architecture Search (NAS) library for facilitating NAS research for the community by providing interfaces to several state-of-the-art NAS search spaces and optimizers.
Apache License 2.0
512 stars 117 forks source link

How can I use NASLib with my own data? #150

Open JuliaWasala opened 1 year ago

JuliaWasala commented 1 year ago

Hi, I'd like to use NASLib with my own dataset. Is there an option to do that?

jr2021 commented 1 year ago

Hi Julia,

Thanks for your question. NASLib does not natively support custom datasets, so we added this as a feature.

We've created a class at naslib/utils/custom_dataset.py which allows you to use your own dataset. An example of how to use this class can be found at examples/custom_data.py. You can also find a code snippet from this example below:

class MyCustomDataset(CustomDataset):
        def __init__(self, config, mode="train"):
            super().__init__(config, mode)

        def get_transforms(self, config):
            train_transform, valid_transform = _data_transforms_cifar10(config)
            return train_transform, valid_transform

        def get_data(self, data, train_transform, valid_transform):
            train_data = dset.CIFAR10(
                root=data, train=True, download=True, transform=train_transform
            )
            test_data = dset.CIFAR10(
                root=data, train=False, download=True, transform=valid_transform
            )

            return train_data, test_data

    config = get_config_from_args()
    dataset = MyCustomDataset(config)
    train_queue, valid_queue, test_queue, train_transform, valid_transform = dataset.get_loaders()

Let us know if you have any further questions :)

Best, Jake, on behalf of the NASLib team