GAN-based data generation in Python.
This project was created to enable synthetic generation of different types of data.
The GAN generator notebook looks at how to generate data based on an existing database to extend this database retaining the same distribution of information. It is a first look at the SDV models which are used in the 'synthetic generation - Telemetric data' notebook.
The Synthetic generation - Telemetric data notebook looks at the raspberry pi data generated and experiments with different ways of generating synthetic data. First looking a manual waz. Then using the SDV library models.
The JSON generator notebook initialises a function which can generate customizable json objects giving distribution types and parameters. It currently takes in manual inputs which should be easy to port onto an app taking user inputs.
The IMAGE generator notebook uses data generated by the JSON generator in the format given by the raspberry pi with stock images of the object detailed in the json object and generates a new image of the image in the correct coordinates.
- Create environment: python3 -m venv py-env
- Activate environment: source py-env/bin/activate
- Check pip list: pip list
- Update pip if required: pip install --upgrade pip
- pip install -r requirements.txt
- Clone repo
No files should run into any errors when using 'run-all' on jupyter notebooks but in interest of time the latest checkpoint should have the metadata of each cell open.
The most important part of this project has been the exploration of the sdv library and its models. This library aims to have its models intiliazed and run in a similar fashion to scikit-learn so there are a few easy steps to running and fitting all models:
- Import the models and load the dataset
- Understand and establish the fields of the dataset and set field transformer and constraints if neccessary
- Initialize model with constraints
- Train/fit model on real data
- Sample/Generate new data
The data has a column for boxes in which the content represents coordinates, but is formated as a string of a list. Best way I have found to deal with this is to create a function which formats these coordinates in their own columns as floats before training the model and create another function to refortmatting it into the string of a list when sampling has been accomplished.
The different models perform better with different constraints applied to them (see Synthetic generation - Telemetric Data, Section 4.3.2). It is important to know the fields of the data you are modelling well to apply these constraints.
Two different usecases were explained and here is how they could be handled:
-
in the case where the raspberry is seen as a typical sensor which sends the data on a regular basis; we can train the model on the data we have, then have the Raspberry Pi sample a datapoint from the model adding the current timestamp and formatting the message appropriately.
-
in the case where the raspberry is seen as an 'edge data aggregator'; we can similarly train the model on the data we have, and have the raspberry sample multiple points from the model (or mulitple models are required to be trained different sensors used). Important to note in this case, the model can generate timestamps from its training set, but these stamps will be in the same data range as the training set.
-
if training set timestamps are on one day and every day should have the same distribution, changing the day in the data generated as required is an easy task (same with different units of time ie week, month...)
-
if training set is set on a small data range ie. a few minute, this method can not be used as no real distribution exists.
Suggestion: when discussing the type of data to be sent from the client, knowing it will be limited, it would be best to request the data they send follows the distribution with which they generate them, even if it is merely a fraction of the total amount.
-
The models are capable of learning and modelling the entire message, however, there is a lot of information in the data I was provided which was unchanged and superfluous. Evaluating how well the models work is made more difficult due to this and more analysis on a complete dataset would provide more clarity. Until then, dismissing these superfluous columns using the models to generate solely the sensor data and timestamps is a far better allocation of resources.
SDV library is has an active community is currently already well developped, it allows you to code as you would in sklearn using 'blackbox' functions making it very simple to initialize models. However other libraries do it differently and these require more understanding of neural nets:
-
TorchGan library with various deep learning tools and different GAN models available. It supports console logging as well as visualization of performance using TensorBoard and Vizdom. https://torchgan.readthedocs.io/en/latest/index.html
-
Tensorflow GANs also known as TF- GAN is an open-source lightweight python library. It was developed by Google AI researchers for the easy and effective implementation of GANs. https://github.com/tensorflow/gan
-
pyGAN This library incorperates GANs, Conditional GANs, Adversarial Auto-Encoders(AAEs), and Energy-based Generative Adversarial Network(EBGAN) to practice algorithm design for semi-supervised learning. https://pypi.org/project/pygan/
-
Not a library but LSTM NN might be worth looking in to for timeseries generation
Please consider citing dataGAN if it has helped you in your research or work:
Max Dehaut. (2018, November 11). dataGAN: GAN-based data generation in Python.
BibTex:
@misc{max\_dehaut\_2018_1111111,
author = {Max Dehaut},
title = {dataGAN: GAN-based data generation in Python},
month = nov,
year = 2018
}
https://colab.research.google.com/drive/1MCTkTj9-93Ei-cLDQoj9AXaqPhpue7a3 https://github.com/sdv-dev