tonylins / pytorch-mobilenet-v2

A PyTorch implementation of MobileNet V2 architecture and pretrained model.
Apache License 2.0
1.37k stars 328 forks source link

Pre-processing #5

Closed DrSleep closed 6 years ago

DrSleep commented 6 years ago

Thanks for this repo and the provided model.

Would you please say how you pre-process the images for evaluation (which mean and std are being used)? Cheers

tonylins commented 6 years ago

I used the following code to pre-process the dataset:

        normalize = transforms.Normalize(mean=[0.485, 0.456, 0.406],
                                         std=[0.229, 0.224, 0.225])

        train_dataset = datasets.ImageFolder(
            traindir,
            transforms.Compose([
                transforms.RandomResizedCrop(224),
                transforms.RandomHorizontalFlip(),
                transforms.ToTensor(),
                normalize,
            ]))

        val_loader = torch.utils.data.DataLoader(
            datasets.ImageFolder(valdir, transforms.Compose([
                transforms.Resize(256),
                transforms.CenterCrop(224),
                transforms.ToTensor(),
                normalize,
            ])),
            batch_size=batch_size, shuffle=False,
            num_workers=n_worker, pin_memory=True)
DrSleep commented 6 years ago

thanks!