Visual machine learning (Keras) with GiraffeTools
Tags: keras, pytorch, visualthinking, machinelearning
Published: 2019-09-17 07:43:50

---
title: Visual machine learning (Keras) with GiraffeTools
published: true
tags: keras,pytorch,visual-thinking,machine-learning
canonical_url: 
---

\*\*\*NOTE: the main article about GiraffeTools can be found [here](https://dev.to/timvanmourik/giraffetools-a-generic-online-workflow-editor-4f6j-temp-slug-2730789)\*\*\*

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](https://github.com/GiraffeTools/GiraffeTools) 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**]](https://giraffe.tools/workflow/%5BYOUR_GITHUB_HANDLE%5D) / [**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/porcupine/TimVanMourik/keras-giraffetools-digit-recognition/master)

![](https://cdn-images-1.medium.com/max/1024/1*LeAUSZgqZrRlL57SXvk8Ug.png)<figcaption><a href="https://giraffe.tools/porcupine/TimVanMourik/keras-giraffetools-digit-recognition/master">https://giraffe.tools/</a><a href="https://giraffe.tools/porcupine/TimVanMourik/keras-giraffetools-digit-recognition/master">workflow</a><a href="https://giraffe.tools/porcupine/TimVanMourik/keras-giraffetools-digit-recognition/master">/TimVanMourik/keras-giraffetools-digit-recognition/master</a></figcaption>

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](https://machinelearningmastery.com/handwritten-digit-recognition-using-convolutional-neural-networks-python-keras))
- GiraffeTools automatically generates the analogous Python-Keras code
- The ‘Save to GitHub’ button saves the Python code to my repository ([this Python file](https://github.com/TimVanMourik/keras-giraffetools-digit-recognition/blob/master/GIRAFFE/code/neural_net.py)), as well as the visual pipeline representation ([this JSON file](https://github.com/TimVanMourik/keras-giraffetools-digit-recognition/blob/master/GIRAFFE/porcupipeline.pork))
- I manually wrote Python code to load MNIST data, load the GiraffeTools NeuralNet ([plain python](https://github.com/TimVanMourik/keras-giraffetools-digit-recognition/blob/master/digit_recognition.py) or [Jupyter Notebook](https://github.com/TimVanMourik/keras-giraffetools-digit-recognition/blob/master/digit_recognition.ipynb))

```
# 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](https://github.com/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](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](https://dev.to/timvanmourik/giraffetools-a-generic-online-workflow-editor-4f6j-temp-slug-2730789), 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](https://giraffe.tools/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!