Giter Club home page Giter Club logo

efficient-gan-based-anomaly-detection-tf2's Introduction

Efficient GAN-Based Anomaly Detection (EGBAD) TensorFlow 2.x Implementation

This repository was created as a lean, easy to use & adapt implementation of the Efficient GAN-Based Anomaly Detection 2018 paper

architecture_scheme

Setup

This repository was built in Anaconda (Python 3.7) on Ubuntu 18.04. It is highly recommended you use Anaconda to rebuild this repository as it will ensure your environment will be solved in terms of dependencies such as CUDA/cuDNN for GPU use.
You have 2 ways to build this environment (both using conda environment):

$ conda create --name <your_venv> --file requirements.txt
or
$ conda env update -n <your_venv> --file environment.yml

Project Structure

bigan Module

  • bigan_model.py - includes all the part needed to build and initialize a BiGAN model
  • bigan_trainer.py - code for the training the BiGAN, saving checkpoints and visualizations to TensorBoard
  • bigan_eval.py - code for running inference on the trained BiGAN with the logic implementated to use it as an anomaly detector + metric visualizations

dataloader Module

My specific use case for the EGBAD was for large 4K images, which were needed to be sliced and labeled to be fed to the BiGAN efficiently. So this module expects large images + json annotations in the same directory like so:

data_dir/

images/img_*.png

annotations/img_*.png.json

The module creates a generator which yields batches of (image_batch, label_batch) where the label is whether there's an anomaly or not (relevant only for testing) It may not be relevant for your use-case, but I've included it anyway so you can better understand the project's flow. Bottom line is you only need to create a generator yielding (image_batch, label_batch) in order for the train/test to work. There are some recommendations however:

  • input shape should be - (32, 32, c) or (64, 64, c).
    Anything bigger would be very difficult to train.
  • inputs should be normalized to [-1 , 1]
    You have tools in the repo in the shape of flags crop_size, resize, and a center_and_scale function to help you prepare the data in such a way.

egbad_train_main.py / egbad_eval_main.py

These are the runner scripts for the trainin phase / inference phase respectivly. You can understand the API and parameter configurations through the abseil app flags listed below the imports. Some of the flags are meant for the data preparation logic of my "slice and label" use case, so feel free to alter it for your use.

efficient-gan-based-anomaly-detection-tf2's People

Contributors

danbochman avatar

Stargazers

 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.