Giter Site home page Giter Site logo

ecs-vlc / fmix Goto Github PK

View Code? Open in Web Editor NEW
330.0 16.0 40.0 1.14 MB

Official implementation of 'FMix: Enhancing Mixed Sample Data Augmentation'

Home Page: https://arxiv.org/abs/2002.12047

License: MIT License

Python 35.15% Jupyter Notebook 64.35% Shell 0.50%
augmentation pytorch pytorch-lightning torchbearer tensorflow

fmix's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

fmix's Issues

DenseNet , ResNet , WRN models

Hi,

Thank you so much for giving us new data augmentation technique. I am bit confused, when I explore your models folder.
My main question is, are you training your ImageNet models with Pre-trained weights? It seems, you don't use pre-trained but you are building your own models and training without using "imagenet" weights.. Please, correct me If I am wrong here..

Secondly, the context of the first question is in the second question about baseline accuracies. Are you getting the baseline accuracies without "Imagenet" weights?

Any guideline to use FMix in keras?

Thank you!

Mix of images with own dataset

Hi, thank you very much, your work is very interesting; I have a question regarding the datset, I'm working with the code that you uploaded in Colab, if I want to train with my own data, how do I modify the line of code?

I modify la line of torchvision, I chance CIFAR10 to ImageFolder and I structure the folders according to ImageNet but I'm still having problems.

testset = torchvision.datasets.ImageFolder(root="/root/test/all/", transform=transforms.Compose([transforms.ToTensor()]), target_transform=None).

I thank you very much for your time and attention

cheers

Training vs validation accuracy

Hi there! Thanks for sharing your work! The paper is very impressive!

I ran the cifar_experiment.sh with cifar data, resnet model, and fmix. However, I'm a little confused about two things:
1- Training accuracy is much lower than validation accuracy. Is this an artifact of using the masks and therefore making the learning phase much harder? Am I missing something? I confess that I'm not 100% sure I understand all the moving parts.
2- When it runs, it says running_mixup_acc etc. I had selected fmix so it's confusing to see mixup here. Can you help me understand this?

Thank you in advance!

Question: Is there any examole notebook availaible with you with fmix implemetation.

I understood the concepts here , but I am unable to figure out how I should use this github repo wth my pytorch dataset even after going throught h colab implementations.

I am using this classification dataset.

class FlowerDataset(Dataset):
    def __init__(self, id , classes , image , img_height , img_width, mean , std , is_valid):
        self.id = id
        self.classes = classes
        self.image = image
        self.is_valid = is_valid
        if self.is_valid == 1:
            self.aug = albumentations.Compose([
               albumentations.Resize(img_height , img_width, always_apply = True) ,
               albumentations.Normalize(mean , std , always_apply = True) 
            ])
        else:
            self.aug = albumentations.Compose([
                albumentations.Resize(img_height , img_width, always_apply = True) ,
                albumentations.Normalize(mean , std , always_apply = True),
                albumentations.ShiftScaleRotate(shift_limit = 0.0625,
                                                scale_limit = 0.1 ,
                                                rotate_limit = 5,
                                                p = 0.9)
            ]) 
        
    def __len__(self):
        return len(self.id)
    
    def __getitem__(self, index):
        id = self.id[index]
        img = np.array(Image.open(io.BytesIO(self.image[index]))) 
        img = cv2.resize(img, dsize=(128, 128), interpolation=cv2.INTER_CUBIC)
        img = self.aug(image = img)['image']
        img = np.transpose(img , (2,0,1)).astype(np.float32)
       
        return torch.tensor(img, dtype = torch.float),int(self.classes[index])

Pleas help

For MSDA between images, my mask is always a vertical block.

I just use the def in fmix.py to generate blended images independently using a batch-size images. But the end result is always a mix of vertical blocks, just like the cutmix. I didn't use pytorch or tf, just the fmix.py and pass in batch data alone. I don't know what the problem is, if you can help me to answer this question, I would be very grateful.

On Using FMIX my dataloader is unable to mix the data in training loop

I have used the following training loop for my plant image dataset

def train_loop_fn(data_loader, model, optimizer, device, scheduler=None):
    running_loss = 0.0
    running_corrects = 0
    
    model.train()
    
    alpha, decay_power = 1.0, 3.0
    
    for batch_index,dataset in enumerate(data_loader):
        image = dataset["image"]
        label = dataset["label"]
        
        image = image.to(device, dtype=torch.float)
        label = label.to(device, dtype=torch.float)
        
        image, perm, lambda_value = sample_and_apply(image, alpha, decay_power, (224, 224))
        optimizer.zero_grad()

        outputs = model(image)
        
        loss = loss_fn(outputs, label) * lambda_value + loss_fn(outputs, label[perm]) * (1 - lambda_value)

        loss.backward()
        xm.optimizer_step(optimizer)

        running_loss += loss.item()

    scheduler.step()
            
    train_loss = running_loss / float(len(train_dataset))
    
    xm.master_print('training Loss: {:.4f} '.format(train_loss))

and my dataset class look like this

import cv2
import torch
from torchvision import transforms
import albumentations
from PIL import Image

class leaf_classification(Dataset):
    def __init__(self, ids, image_id, label, mean , std , is_valid):
        self.ids = ids
        self.image_id = image_id
        self.label = label
        self.is_valid = is_valid
        if self.is_valid == 1: # transforms for validation images
            self.aug = albumentations.Compose([
               albumentations.Normalize(mean , std , always_apply = True) 
            ])
        else:                  # transfoms for training images 
            self.aug = albumentations.Compose([
                albumentations.Normalize(mean , std , always_apply = True),
                albumentations.ShiftScaleRotate(shift_limit = 0.0625,
                                                scale_limit = 0.1 ,
                                                rotate_limit = 5,
                                                p = 0.9)
            ]) 
        
    def __len__(self):
        return len(self.ids)
    
    def __getitem__(self, index):
        # converting jpg format of images to numpy array
        img = np.array(Image.open('../input/cassava-leaf-disease-classification/train_images/' + self.image_id[index])) 
        
        img = cv2.resize(img, dsize=(224, 224), interpolation=cv2.INTER_CUBIC)
        img = self.aug(image = img)['image']
        img = np.transpose(img , (2,0,1)).astype(np.float32) # 2,0,1 because pytorch excepts image channel first then dimension of image
        
       
        return {
            'image' : torch.tensor(img, dtype = torch.float) , 
            'label' : torch.tensor(self.label[index], dtype = torch.float)
        }

And its generating the error

while training it generating this error

image

please help me in resolving this error . Here's the link to my notebook

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.