facebookresearch / pycls

Codebase for Image Classification Research, written in PyTorch.
MIT License
2.14k stars 237 forks source link

about random_sized_crop confused ? #123

Open ranjiewwen opened 3 years ago

ranjiewwen commented 3 years ago

i my codebase to train regnetx_200m, i use this function 'random_sized_crop' in transform, while get bad result, train acc get 90%+, while val acc get 50%+ random_sized_crop(image, size=cfg.data.image_size, area_frac=0.08)

when i use torchvision method , training result is normal.

 image = PIL.Image.fromarray(image)
 image = torchvision.transforms.RandomResizedCrop(cfg.data.image_size)(image)
 image = np.array(image)

anyone meet this problem ? i see the source code diff below, i think this shouldn't make so big different.

         # torchvision
        target_area = random.uniform(*scale) * area
        log_ratio = (math.log(ratio[0]), math.log(ratio[1]))
        aspect_ratio = math.exp(random.uniform(*log_ratio))
        # pycls
        target_area = np.random.uniform(area_frac, 1.0) * area
        aspect_ratio = np.random.uniform(3.0 / 4.0, 4.0 / 3.0)
ranjiewwen commented 3 years ago

when change the code in pycls/datasets/transforms.py , functions: random_sized_crop use torchvision aspect_ratio, training result is right !!! so different result from there ???

 target_area = random.uniform(*(area_frac, 1.0)) * area
 log_ratio = (math.log(3.0 / 4.0), math.log(4.0 / 3.0))
 aspect_ratio = math.exp(random.uniform(*log_ratio))
 # target_area = np.random.uniform(area_frac, 1.0) * area
 # aspect_ratio = np.random.uniform(3.0 / 4.0, 4.0 / 3.0)