Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Data Augmentation #22

Open
illuminoplanet opened this issue Jul 21, 2020 · 1 comment
Open

Data Augmentation #22

illuminoplanet opened this issue Jul 21, 2020 · 1 comment

Comments

@illuminoplanet
Copy link
Collaborator

No description provided.

@illuminoplanet
Copy link
Collaborator Author

import os, warnings
warnings.filterwarnings('ignore')

import pandas as pd
import numpy as np
from torchvision import transforms

class Augmenter:

  def __init__(self, data):

    self.data = data.copy()
    self.transform = transforms.Compose([
      transforms.ToPILImage(),
      transforms.RandomHorizontalFlip(p=0.5),
      transforms.RandomVerticalFlip(p=0.5),
      transforms.RandomRotation((0, 360)),
    ])
  
  def get(self, amount):

    df = pd.DataFrame()
    for ft, cnt in amount.items():
      sample = self.data[self.data['failure_type']==ft].sample(cnt, replace=True).reset_index()
      sample.loc[:, 'wafer_map'] = sample['wafer_map'].apply(lambda x : np.array(self.transform(x)))

      df = pd.concat([df, sample], axis=0)
    
    return df

if __name__ == "__main__":

    data = pd.read_pickle('data/sample.pkl')
    aug = Augmenter(data)

    amount = {
        'Center': 600, 
        'Donut': 600, 
        'Edge-Loc': 600, 
        'Edge-Ring': 600, 
        'Loc': 600, 
        'Near-full': 600, 
        'Random': 600, 
        'Scratch': 600, 
        'none': 600
    } 
    augmented = aug.get(amount)
    print(augmented.shape)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants