albumentations-team / autoalbument

AutoML for image augmentation. AutoAlbument uses the Faster AutoAugment algorithm to find optimal augmentation policies. Documentation - https://albumentations.ai/docs/autoalbument/

Home Page:https://albumentations.ai/docs/autoalbument/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How can I fixed this problem?

1chimaruGin opened this issue · comments

Hello,
I'm trying autoalbument on cats-vs-dogs classification dataset.

my dataset.py

class SearchDataset(torch.utils.data.Dataset):
    def __init__(self, root=os.path.join(
        os.path.dirname(__file__), 'cats-vs-dogs/PetImages'), transform=None):
        self.imagespath = self.__get_imgpath(root)
        self.transform = transform

    @staticmethod
    def __get_imgpath(root):
        cat_directory = os.path.join(root, "Cat")
        dog_directory = os.path.join(root, "Dog")
        cat_images_filepaths = sorted(
            [os.path.join(cat_directory, f) for f in os.listdir(cat_directory)])
        dog_images_filepaths = sorted(
            [os.path.join(dog_directory, f) for f in os.listdir(dog_directory)])
        images_filepaths = [*cat_images_filepaths, *dog_images_filepaths]
        correct_images_filepaths = [
            i for i in images_filepaths if cv2.imread(i) is not None]
        random.seed(42)
        random.shuffle(correct_images_filepaths)
        train_images_filepaths = correct_images_filepaths[:20000]
        # val_images_filepaths = correct_images_filepaths[20000:-10]
        # test_images_filepaths = correct_images_filepaths[-10:]
        return train_images_filepaths
        
    def __len__(self):
        return len(self.imagespath)

    def __getitem__(self, idx):
        imgpath = self.imagespath[idx]
        image = cv2.imread(imgpath, cv2.IMREAD_COLOR)
        image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
        # image = self.letterbox(image, new_shape=(224, 224), auto=False)[0]
        if os.path.normpath(imgpath).split(os.sep)[-2] == 'Cat':
            label = 1.0
        else:
            label = 0.0

        if self.transform is not None:
            image = self.transform(image=image)['image']
        return image, label

I got this error.

policy_model:
  task_factor: 0.1
  gp_factor: 10.0
  temperature: 0.05
  num_sub_policies: 50        
  num_chunks: 8
  operation_count: 4
optim:
  epochs: 20
  main:
    _target_: torch.optim.Adam
    lr: 0.001
    betas:
    - 0
    - 0.999
  policy:
    _target_: torch.optim.Adam
    lr: 0.001
    betas:
    - 0
    - 0.999
device: cuda
task: classification
cudnn_benchmark: true
save_checkpoints: false
checkpoint_path: null
tensorboard_logs_dir: null
classification_model:
  _target_: autoalbument.faster_autoaugment.models.ClassificationModel
  num_classes: 2
  architecture: resnet18
  pretrained: false
data:
  normalization:
    mean:
    - 0.485
    - 0.456
    - 0.406
    std:
    - 0.229
    - 0.224
    - 0.225
  dataloader:
    _target_: torch.utils.data.DataLoader
    batch_size: 64
    shuffle: true
    num_workers: 8
    pin_memory: true
    drop_last: true
  preprocessing:
  - PadIfNeeded:
      min_height: 512
      min_width: 512
  - Resize:
      height: 256
      width: 256
  dataset_file: null
  dataset:
    _target_: dataset.SearchDataset
  input_dtype: uint8
seed: null

Working directory: S:\shared_DataSet\1chimaruGin\augmentation\search-dog-vs-cat\outputs\2021-01-13\15-47-19
[2021-01-13 15:47:19,723][autoalbument.faster_autoaugment.search][INFO] - Preprocessing transform:
Compose([
  PadIfNeeded(always_apply=False, p=1.0, min_height=512, min_width=512, pad_height_divisor=None, pad_width_divisor=None, border_mode=4, value=None, mask_value=None),
  Resize(always_apply=False, p=1, height=256, width=256, interpolation=1),
  Normalize(always_apply=False, p=1.0, mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225], max_pixel_value=255),
  ToTensorV2(always_apply=True, p=1.0, transpose_mask=True),
], p=1.0, bbox_params=None, keypoint_params=None, additional_targets={})
...
RuntimeError: Expected object of scalar type Long but got scalar type Double for argument #2 'target' in call to _thnn_nll_loss_forward

Looks like your configuration expects an integer (input_dtype: uint8) as an input, but your input is a float64. You can try either changing configuration to input_dtype: float32 and/or casting your input to integer/float32.

Got it! Thanks you @jwitos