DEV Community

Tim van Mourik
Tim van Mourik

Posted on • Originally published at Medium on

Visual machine learning (Keras) with GiraffeTools

***NOTE: the main article about GiraffeTools can be found here***

When I started to go down the rabbit hole of ‘machine learning’, it was a puzzling and bewildering experience. After building my first digit recognition network, it did not feel like the concatenation of obscure modules named Conv2D, MaxPooling, or DropOut was very intuitive. Although the outcome brilliantly predicted every new hand-written digit that I fed the model, it did not feel like I knew what I was doing. And more importantly, that I would know how to apply it to my own data.

This is quite a barrier for people that are new to the machine learning space. Add to that the proficiency in coding that is required for running the network on your data. Wouldn’t it be cool if we could lower this barrier?

Introducing: Keras with GiraffeTools

What if you could graphically build your machine learning network? And easily integrate the network with the rest of your code and share the results? If only there were tools for a G raphical I nterface for R eproducible A nalysis F or work F low E xperiments!

That’s what GiraffeTools is: a completely open source web application that allows you to build Keras networks. It automatically creates code that you can save directly to a GitHub repository as a new commit. Your model is now accessible at: https://giraffe.tools/workflow/ [YOUR_GITHUB_HANDLE] / [YOUR_REPOSITORY] / [YOUR_BRANCH_OR_COMMIT].

As an example, take a simple digit recognition network using Keras. The master branch from my keras-giraffetools-digit-recognition repository within my TimVanMourik Github account can be inspected at:

https://giraffe.tools/workflow/TimVanMourik/keras-giraffetools-digit-recognition/master

https://giraffe.tools/workflow/TimVanMourik/keras-giraffetools-digit-recognition/master

How did I construct this?

  • I dragged-and-dropped Keras modules into the editor
  • I connected them to generate a sequential network (designed after this tutorial)
  • GiraffeTools automatically generates the analogous Python-Keras code
  • The ‘Save to GitHub’ button saves the Python code to my repository (this Python file), as well as the visual pipeline representation (this JSON file)
  • I manually wrote Python code to load MNIST data, load the GiraffeTools NeuralNet (plain python or Jupyter Notebook)
# Load MNIST data
from keras.datasets import mnist
# Load NeuralNet as defined and saved by the editor
from GIRAFFE.code.neural\_net import NeuralNet
  • As you would with any Keras network, from here you build, compile, and fit your NeuralNet:
# Preprocess MNIST data
...
# build the model
model = NeuralNet(num_classes)
# Compile the model
model.compile(
   loss='categorical_crossentropy',
   optimizer='adam', 
   metrics=['accuracy']
)
# Fit the model
model.fit(
   X_train, 
   y_train,
   validation_data=(X_test, y_test),         
   epochs=10,         
   batch_size=200
)

All code for this example is available at:

TimVanMourik/keras-giraffetools-digit-recognition

Getting started

The easiest way is to fork the repo above and get started from there! If you want to start from scratch, go ahead: https://giraffe.tools/workflow.

But there is one caveat: at this moment you have to point to the keras nodes in a GIRAFFE.yml file in the root of your repository. How this works under the hood you can read here, in the GiraffeTools main article. The TLDR is: you can use GiraffeTools for any other data analysis pipelines as well if you point to your a library file of function. I pre-made and linked this for the Keras application.

Your input!

I am relatively new to machine learning, so any help to improve this is much appreciated! Via the comment section, GitHub, or the GiraffeTools Slack. Also, I would love to make the same connection to PyTorch, but I have never used it. If you have PyTorch experience, please get in touch and we’ll build it together!

Top comments (0)