Skip to content

C-M-Gonzalez/VAE_anomaly_detection

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Variational autoencoder for anomaly detection

This repo contains my personal implementation of Variational autoencoder in tensorflow for anomaly detection, that follow Variational Autoencoder based Anomaly Detection using Reconstruction Probability by Jinwon An, Sungzoon Cho
In order to make work the variational autoencoder for anomaly detection i've to change the last layer of the decoder from a simple fully connected layer to two layers that estimate mean and variance of x~ ( p(x|z) )

How To Train a Model

  • Define your dataset into dataset.py and put in output into the function get_dataset
  • Eventually change encoder and decoder inside VAE.py to fits your data layout
  • Run in a terminal python train.py and specify required at least --input-size (pass -h to see all optional parameters)
  • Trained model, parameters and Tensorboard log goes into the folder run/{id} where {id} is an integer from 0 to +inf
  • After the model training run tensorboard --logdir=run to check all the training results

How to make predictions:

Once the model is trained (suppose for simplicity that it is under run/0/ ) just load and predict with this code snippet:

import torch

#load X_test
model = VAEAnomaly(input_size=50, latent_size=32)
# could load input_size and latent_size also 
# from run/0/train_config.yaml
model.load_state_dict(torch.load('run/0/model.pth'))
# load saved parameters from a run
outliers = model.is_anomaly(X_test)

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 100.0%