• Stars
    star
    105
  • Rank 328,196 (Top 7 %)
  • Language
    Python
  • License
    MIT License
  • Created over 7 years ago
  • Updated over 7 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Save keras weight matrices as short animated videos during training

Keras Weight Animator

Save Keras weight matrices as short animated videos to better understand what and how your neural network models are learning. Below are examples of the first LSTM layer and the final output layer of a six-class RNN model trained over one epoch. Blue represents low values and red represents high values.

Example Animation 2

Example Animation 1

Getting Started

Dependencies

# clone the repo, preferably somewhere in your PYTHONPATH
git clone https://github.com/brannondorsey/keras_weight_animator
cd keras_weight_animator

pip install -r requirements.txt

In order to render videos from the saved weight images you must also have the following packages installed on your machine:

Using the Module

This module is named keras_weight_animator. It exposes a Keras callback function that you can include in any model fit(...) method.

## you can optionally add this module to your python path by appending
## its parent directory in sys.path. Uncomment below to do this.
# import sys
# sys.path.append('path/to/keras_weight_animator/..')

from keras_weight_animator import image_saver_callback

# assumes a keras model named "model"
callbacks = [image_saver_callback(model, 'output_directory')]

model.fit(X_train, y_train, callbacks=callbacks)

The two required parameters to image_saver_callback(...) are the Keras model and an output_directory to periodically save weight images to. By default, keras_weight_animator saves layer weights every 100 batches to output_directory as PNGs in folders named epoch_XXX-layer_NAME-weights_YY. Once training is complete, you can optionally create short animated video clips from the image sequences saved in output_directory using [bin/create_image_sequence.sh](bin/create_image_sequence.sh) path/to/output_directory. This will use parallel, mogrify, and ffmpeg to create a .mp4 from the image sequences located in each folder of output_directory. Video files will be named like epoch_XXX-layer_NAME-weights_YY.mp4. You can run this script automatically from your training script by passing the render_videos=True parameter to image_saver_callback(...).

Optional Parameters

weight_image_sequences(...) takes a variety of optional keyword arguments.

  • epoch_interval (default=1): Save weight images every epoch_interval epochs. Saves weights every epoch by default, but you may want to change this if you are training for lots of epochs.
  • batch_interval (default=100): Save weight images every batch_interval batches. batch_interval=1 would save weights for every batch.
  • cmap (default='gray'): Matplotlib color map name. I recommend trying some diverging color maps, especially RdBu.
  • render_videos (default=False): Optionally make a system call to create_image_sequences.sh <output_directory> at the end of model.fit() (using the Keras on_train_end(...) function internally). Setting this to True will automagically render .mp4 videos for you (watch the console for errors).
# example
callbacks = [image_saver_callback(model, 'weight_image_sequences', epoch_interval=10, batch_interval=1000, cmap='gray', render_videos=True)]
model.fit(X_train, y_train, callbacks=callbacks)

Examples

I've included an example usage of the module in examples/wisdm.py. This example uses smartphone accelerometer data from WISDM to classify human activity tasks like walking, standing, sitting, walking upstairs, etc...

This example uses a one layer LSTM to classify a set of 60 data points (representing three seconds of data sampled at 20hz) as belonging to one of six classes. It outputs image sequences and videos to data/wisdm.

# download and uncompress the WISDM data
cd data
curl http://www.cis.fordham.edu/wisdm/includes/datasets/latest/WISDM_ar_latest.tar.gz -o WISDM_ar_latest.tar.gz
tar -xzf WISDM_ar_latest.tar.gz
rm WISDM_ar_latest.tar.gz
cd ../example

python wisdm.py

Thoughts

Using a bash script to leverage parallel, ImageMagick, and FFMPEG isn't necessarily the most elegant solution, but its the one I had time for. The goal of this here lil' project was to write a quick tool that allows me to better understand how weights change over mini-batch updates in a variety of neural networks. Perhaps in the future I will come back and clean up some of the inelegancies. If you have interest in contributing or maintaining a cleaner version of this lib, please reach out at [email protected].

Attribution and License

This module is © Brannon Dorsey 2017, released under an MIT License . You are free to use, modify, distribute, sell, etc... this software under those terms.

Example data is from the WIreless Sensor Datamining (WISDM) Actitracker dataset published by Fordham University:

Jennifer R. Kwapisz, Gary M. Weiss and Samuel A. Moore (2010). Activity Recognition using Cell Phone Accelerometers, Proceedings of the Fourth International Workshop on Knowledge Discovery from Sensor Data (at KDD-10), Washington DC. [PDF]

This idea is tangentially inspired by much of the work on Visualizing and Understanding Recurrent Networks by Andrej Karpathy, Justin Johnson, and Fei-Fei Li.

@article{DBLP:journals/corr/KarpathyJL15,
  author    = {Andrej Karpathy and
               Justin Johnson and
               Fei{-}Fei Li},
  title     = {Visualizing and Understanding Recurrent Networks},
  journal   = {CoRR},
  volume    = {abs/1506.02078},
  year      = {2015},
  url       = {http://arxiv.org/abs/1506.02078},
  timestamp = {Wed, 07 Jun 2017 14:42:54 +0200},
  biburl    = {http://dblp.uni-trier.de/rec/bib/journals/corr/KarpathyJL15},
  bibsource = {dblp computer science bibliography, http://dblp.org}
}

GNU Parallel is adamant about citation to the point of excess IMHO, but for what its worth, here is their bibtex:

@article{Tange2011a,
  title = {GNU Parallel - The Command-Line Power Tool},
  author = {O. Tange},
  address = {Frederiksberg, Denmark},
  journal = {;login: The USENIX Magazine},
  month = {Feb},
  number = {1},
  volume = {36},
  url = {http://www.gnu.org/s/parallel},
  year = {2011},
  pages = {42-47},
  doi = {http://dx.doi.org/10.5281/zenodo.16303}
}

More Repositories

1

wifi-cracking

Crack WPA/WPA2 Wi-Fi Routers with Airodump-ng and Aircrack-ng/Hashcat
10,642
star
2

PassGAN

A Deep Learning Approach for Password Guessing (https://arxiv.org/abs/1709.00440)
Python
1,749
star
3

naive-hashcat

Crack password hashes without the fuss 🐈
C
1,075
star
4

chattervox

📡 An AX.25 packet radio chat protocol with support for digital signatures and binary compression. Like IRC over radio waves.
TypeScript
748
star
5

whonow

A "malicious" DNS server for executing DNS Rebinding attacks on the fly (public instance running on rebind.network:53)
JavaScript
618
star
6

dns-rebind-toolkit

A front-end JavaScript toolkit for creating DNS rebinding attacks.
JavaScript
482
star
7

sniff-probes

Plug-and-play bash script for sniffing 802.11 probes requests 👃
Shell
231
star
8

apibuilder

Easy API builder mini library for PHP
PHP
202
star
9

host-validation

Express.js middleware for "Host" and "Referer" header validation to protect against DNS rebinding attacks.
JavaScript
190
star
10

distributed-password-cracking

Borrow CPU cycles from visitor's web browsers to crack MD5 password hashes 😲
JavaScript
181
star
11

midi-rnn

Generate monophonic melodies with machine learning using a basic LSTM RNN
Python
155
star
12

ProbeKit

SSID Probe Request Collection Workshop
JavaScript
133
star
13

ml4music-workshop

Machine Learning for Music and Sound Synthesis workshop
Jupyter Notebook
104
star
14

GloVe-experiments

GloVe word vector embedding experiments (similar to Word2Vec)
Python
60
star
15

radio-thermostat

Radio Thermostat CT50 & CT80 REST API notes
33
star
16

rust-incompatible-transitive-dependencies

An example demonstrating how Rust and cargo support incompatible transitive dependencies (like Node.js + npm not Python + pip)
Rust
29
star
17

letterpress

A nefarious keylogger for Ubuntu. Encrypts keylogs and uploads to pastebin.
Python
26
star
18

the-wandering-dreamer

The Wandering Dreamer: An Synthetic Feedback Loop
JavaScript
22
star
19

pw

Generate strong passwords using /dev/urandom 👻
Shell
15
star
20

markov-passwords

Markov-chain password generator
Python
13
star
21

chirp-files

A collection of notable radio frequencies near Philadelphia PA and beyond
11
star
22

chattervox-examples

A collection of example applications and use cases for the Chattervox protocol
Python
11
star
23

quartzite

Auto-log screenshots and metadata to your personal cloud server when surfing the web
PHP
11
star
24

aprsc-docker

A dockerized aprsc APRS-IS server
Dockerfile
11
star
25

xmrig-k8s

Mine Monero using leftover resources in a Kubernetes cluster
10
star
26

chattervox-keys

A public chattervox key server 🔑
Python
9
star
27

cve

A collection of vulnerabilities found through independent security research.
8
star
28

DreamMachines

Research into using Machine Learning to hallucinate circuit board schematics
KiCad Layout
8
star
29

pokemods

A small collection of Pokémon Red & Blue Gameboy game mods.
Assembly
7
star
30

attacker-personas

🏴‍☠️ Use attacker personas to improve your threat modeling and cybersecurity practices
7
star
31

vanity-keygen

A vanity key generator for the P224, P256, P384, and P521 elliptic curves.
Go
7
star
32

go-runway

A small Go module for interfacing with RunwayML
Go
7
star
33

helm-charts

A small collection of helm charts
HTML
6
star
34

ofTutoring

Course repository for 1-on-1 openFrameworks/C++ tutoring
6
star
35

markov

A small Markov chain generator 📃
Go
5
star
36

distance-sort

Sort geographic locations by their distance from eachother
Python
5
star
37

twilio-cleverbot

Talk to Cleverbot from your phone
JavaScript
4
star
38

BetweenTheTwoOfThese

Custom openFrameworks applications for an 80ft projection installation in Atlanta
C++
4
star
39

spectrum-wrangler-docker

A Dockerized version of Spectrum Wrangler that downloads and geo indexes public FCC license data
Dockerfile
4
star
40

indexd

Archive and connect independent artists websites
PHP
4
star
41

exchatter

A personalized chatbot framework for Node js
JavaScript
4
star
42

application-security-workshop

HTML
4
star
43

LANlockED

PirateBox style LAN tutorial website for EmptyBox
HTML
3
star
44

LEDWallVideoPlayer

Video player application for the Moment LED wall installation at Dolby Labs
C++
3
star
45

pastebin-mirror-docker

A dockerized version of the pastebin-mirror service.
Dockerfile
3
star
46

manifesto

A young art and technologist's manifesto
3
star
47

picamstreaming

Stream directly to Youtube from the Raspberry Pi camera module
Python
2
star
48

thisisatrackingdevice

An interactive map to display data from a public tracking device project
Processing
2
star
49

osm-museums

Open Street Maps data for all museums on earth (36,694 as of June 5th, 2017)
Python
2
star
50

gpssandbox

Sandbox to play with gps/gpx data visualization using google maps api
Processing
2
star
51

kiss-tnc

Talk to a packet radio KISS TNC over a serial port.
JavaScript
2
star
52

runway-glove

A Runway model for experimenting with GloVe vector embeddings
Python
2
star
53

rtl-433-influxdb-importer

Import data from an Acurite 5-in-1 weather station into influxdb
Python
2
star
54

osm-syria-poi

Open Street Maps data for cultural/historic points of interest in Syria
Python
2
star
55

ofxCanvasEvents

Broadcasts mouse, touch, and key events from an HTML5 Canvas to an openFrameworks app
JavaScript
2
star
56

P5AlbersColorTheory

Materials for an introduction to P5.js lecture themed around Josef Albers inspired color theory.
JavaScript
1
star
57

oculusself

Self reflection with the Oculus Rift
C++
1
star
58

projectortracking

A sandbox repo for projects aimed to make any projector touch screen
Processing
1
star
59

OculusWebcamExperiments

Experimental webcam projects for the Oculus Rift. Built with openFrameworks.
C++
1
star
60

nodesandbox

A sandbox repo for node.js + RPi experiments
JavaScript
1
star
61

ChessEmbeddings

GloVe vector embeddings of chess moves
Jupyter Notebook
1
star
62

ofBook_IntroToGraphics

1
star
63

looplamp

Raspberry Pi + Node.js interactive lamp project
JavaScript
1
star
64

ml-sandbox

Machine Learning sandbox
Python
1
star
65

brannondorsey.com

My portfolio website
PHP
1
star
66

website

Personal Website. Using Kirby CMS.
PHP
1
star
67

scarecrow

A Node.js chat bot that learns.
JavaScript
1
star
68

tvtalker-app

TVTalker Display app made with openFrameworks
C++
1
star
69

OpenNIWebSocketDaemon

Stream depth and skeleton tracking data from OpenNI2 + NiTE2 to the browser via WebSockets
JavaScript
1
star
70

UBox

Generalized modular framework to create software like PirateBox or LibraryBox
JavaScript
1
star
71

oFMaskTool

C
1
star
72

webconnections

A node.js powered command-line app for illustrating the degrees of separation between webpages
JavaScript
1
star
73

brbxoxo

PHP
1
star
74

vectorpi

C++
1
star
75

LEDWallInteractive

Interactive scenes for the Moment LED wall installation at Dolby Labs (Authored by Jason Van Cleave and Brannon Dorsey)
C++
1
star
76

exes

A romantic artificial intelligence project
Python
1
star
77

zetamaze

Repo for the Zetamaze threejs project
JavaScript
1
star
78

ProgrammingForArtists

Art && Programming Lecture @ The School of the Art Institute of Chicago, March 2017
JavaScript
1
star