EfficientNet-PyTorch icon indicating copy to clipboard operation
EfficientNet-PyTorch copied to clipboard

question about the image size

Open baoyufuyou opened this issue 6 years ago • 1 comments

I just had some questions about the image size in the main.py of training code. If I choose efficientnet b3, is the input image size absolutely 300x300? I try to train with other image size, the train works fine. So a little bit confused~ Otherwise, the code of defining train_dataset, as follows, defined a constant image size of 224. Is it better to be similar with the code of defining the val_transforms?? Thanks a lot.

`

define train_dataset

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

define val_transforms

if 'efficientnet' in args.arch:
    image_size = EfficientNet.get_image_size(args.arch)
    val_transforms = transforms.Compose([
        transforms.Resize(image_size, interpolation=PIL.Image.BICUBIC),
        transforms.CenterCrop(image_size),
        transforms.ToTensor(),
        normalize,
    ])
    print('Using image size', image_size)
else:
    val_transforms = transforms.Compose([
        transforms.Resize(256),
        transforms.CenterCrop(224),
        transforms.ToTensor(),
        normalize,
    ])
    print('Using image size', 224)

`

baoyufuyou avatar Apr 13 '20 19:04 baoyufuyou

The different versions of EfficientNet are trained to be used on images of specific sizes. This is explained in detail in the paper: https://arxiv.org/abs/1905.11946

The training code is done at the moment (the model is only ready to be loaded from pretrained weights, not trained from scratch), so the training transforms are not correct (they should be 300px for b3 as you said).

lukemelas avatar Apr 20 '20 18:04 lukemelas