Giter Site home page Giter Site logo

deepfakeclassification's Introduction

2021 Real/Fake image classification

Challenge Details

Team

Solution Description

  • Source : solution.ipynb

  • Augmentations

    • Reference
    • Code
      import albumentations as A
      from albumentations.pytorch import ToTensorV2
      transforms_tr = A.Compose([
          A.Resize(256, 256),
          A.ImageCompression(quality_lower=60, quality_upper=100, p=0.5),
          A.GaussNoise(p=0.1),
          A.GaussianBlur(blur_limit=3, p=0.05),
          A.HorizontalFlip(),
          A.OneOf([
              A.RandomBrightnessContrast(), 
              A.FancyPCA(), 
              A.HueSaturationValue(),
          ], p=0.7),
          A.ToGray(p=0.2),
          A.ShiftScaleRotate(shift_limit=0.1, scale_limit=0.2, rotate_limit=10, border_mode=cv2.BORDER_CONSTANT, p=0.5),
          A.CenterCrop(156, 156),
          A.Normalize(mean=(0.485, 0.456, 0.406), std=(0.229, 0.224, 0.225)),
          ToTensorV2(),
      ])
      • Resize(256, 256) : Required to resize input image consistently
      • ImageCompression ~ ShiftScaleRotate : Added some modifications to the code in the reference
      • CenterCrop(156, 156) : Features of fake images appear mainly in the center of the face. Most of the datasets have faces in the center front. Therefore, only the center part of the image is extracted.
  • Model

    • Reference
    • Code
      from facenet_pytorch import InceptionResnetV1
      model = InceptionResnetV1(pretrained=None, classify=True, num_classes=2, dropout_prob=0.6)
  • Optimizer and Scheduler

    • Reference
    • Code
      import torch_optimizer as optim
      optimizer = optim.RAdam(model.parameters(), lr=learning_rate, betas=betas, weight_decay=weight_decay)
      lr_sched = torch.optim.lr_scheduler.CosineAnnealingLR(optimizer,T_max=T_max)
  • K-fold and Soft voting

    • Reference
    • Code
      # Training
      from sklearn.model_selection import KFold
      kfold = KFold(n_splits=n_splits, shuffle=True, random_state=random_seed)
      
      best_models = {}
      for fold, (train_ids, test_ids) in enumerate(kfold.split(train_df)):
        ...
        for e in range(num_epochs) :
          ...
          best_models[fold] = best_model
      
      # Inference
      scores_result = []
      for fold in range(n_splits):
        model = best_models[fold]
        ...
        scores_result.append(score_list)
      
      # Soft voting
      import torch.nn.functional as F
      myresult = F.softmax(torch.tensor(scores_result), dim=2)
      myresult = torch.sum(myresult, dim=0)
      _, preds = myresult.max(dim=1)

Contributors

deepfakeclassification's People

Contributors

hrxorxm avatar

Watchers

 avatar

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.