Giter Site home page Giter Site logo

happyllin / alphagan-matting Goto Github PK

View Code? Open in Web Editor NEW

This project forked from cdotad/alphagan-matting

0.0 1.0 0.0 34.18 MB

This project is an unofficial implementation of AlphaGAN: Generative adversarial networks for natural image matting published at the BMVC 2018

Python 89.24% Jupyter Notebook 10.76%

alphagan-matting's Introduction

AlphaGAN

This project is an unofficial implementation of AlphaGAN: Generative adversarial networks for natural image matting published at the BMVC 2018. As for now, the result of my experiment is not as good as the paper's.

Dataset

Adobe Deep Image Matting Dataset

Follow the instruction to contact the author for the dataset

You might need to follow the method mentioned in the Deep Image Matting to generate the trimap using the alpha mat.

The trimap are generated while the data are loaded.

import numpy as np
import cv2 as cv

def generate_trimap(alpha):
   k_size = random.choice(range(2, 5))
   iterations = np.random.randint(5, 15)
   kernel = cv.getStructuringElement(cv.MORPH_ELLIPSE, (k_size, k_size))
   dilated = cv.dilate(alpha, kernel, iterations=iterations)
   eroded = cv.erode(alpha, kernel, iterations=iterations)
   trimap = np.zeros(alpha.shape, dtype=np.uint8)
   trimap.fill(128)

   trimap[eroded >= 255] = 255
   trimap[dilated <= 0] = 0

   return trimap

See scripts/MattingTrain.ipynb and scripts/MattingTest.ipynb to compose the training/testing set.

The Dataset structure in my project

Train
  ├── alpha  # the alpha ground-truth
  ├── fg     # the foreground image
  ├── merged_cv  # the real image composed by the fg & bg
MSCOCO
  ├── train2014 # the background image

Running the Codes

   python train.py --dataroot ${YOUR_DIM_DATASET_ROOT} \
                     --training_file ${THE TRAINING FILE OF THE DIM DATASET}

Differences from the original paper

  • SyncBatchNorm instead of pytorch original BatchNorm when use multi GPU.

  • Training batch_size = 1 [1] [2]

  • Using GroupNorm [2]

  • Using Warmup [3] [4]

Records

4 GPUS 32 batch size, and SyncBatchNorm

  • Achieved SAD=78.22 after 21 epoches.

1 GPU 1 batch size, and GroupNorm

Results

image trimap alpha(predicted)

Acknowledgments

My code is inspired by:

alphagan-matting's People

Contributors

cdotad avatar imgbotapp avatar

Watchers

James Cloos 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.