Skip to content

Commit

Permalink
Add readme for keras iris example
Browse files Browse the repository at this point in the history
  • Loading branch information
pgleeson committed Sep 15, 2023
1 parent aacdeb6 commit 3b24a67
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 5 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -306,3 +306,4 @@ examples/TensorFlow/Keras/keras_to_MDF
/examples/TensorFlow/Keras/IRIS/keras_to_MDF
/examples/TensorFlow/Keras/MNIST/keras_to_MDF
/examples/TensorFlow/Keras/MNIST/keras_to_MDF.1
/examples/TensorFlow/Keras/IRIS/keras_to_MDF.1
34 changes: 34 additions & 0 deletions examples/TensorFlow/Keras/IRIS/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Keras to MDF example: IRIS dataset

**For more details on Keras and the current state of the Keras->MDF mapping see the [MNIST example](../MNIST).**

This model uses the [IRIS dataset](https://en.wikipedia.org/wiki/Iris_flower_data_set) in the [trained Keras model](keras_model.py) and the MDF equivalent.

### Summarize Model

Below is the summary image of the trained Keras model. We can clearly see the output shape and number of weights in each layer:

![summary](summary.png)


### Keras Model

Visualization of the model from Keras:

<p align="center"><img src="model_on_iris_plot.png"/></p>
<br>

### MDF Model

Graphviz is used to generate visualization for the MDF graph. Below is the visualization of the MDF graph after converting the keras model to MDF.

![keras_to_MDF](keras_to_MDF.1.png)

More detailed graphical representation of the MDF:

<p align="center"><img src="keras_to_MDF.png" width="400"/></p>

##### Netron
Below is the visualization of this model using netron

![keras-model-to-netron](layers_netron.png)
4 changes: 4 additions & 0 deletions examples/TensorFlow/Keras/IRIS/keras_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@
val_loss, val_acc = model.evaluate(X_test, y_test)
print(val_loss, val_acc)


# Print summary
model.summary()

# plot the model
print("Plotting the model")
plot_model(
Expand Down
Binary file added examples/TensorFlow/Keras/IRIS/keras_to_MDF.1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions examples/TensorFlow/Keras/IRIS/keras_to_MDF.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,16 @@
# Get mdf graph
mdf_graph = mdf_model.graphs[0]

# visualize mdf graph-image
mdf_model.to_graph_image(
engine="dot",
output_format="png",
view_on_render=False,
level=1,
filename_root="keras_to_MDF.1",
is_horizontal=True,
solid_color=True,
)
# visualize mdf graph-image
mdf_model.to_graph_image(
engine="dot",
Expand Down
Binary file added examples/TensorFlow/Keras/IRIS/layers_netron.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added examples/TensorFlow/Keras/IRIS/summary.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 2 additions & 4 deletions examples/TensorFlow/Keras/MNIST/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
# Keras to/from MDF

**NOTE: this is still a work in progress!**
# Keras to MDF example: MNIST

## Keras

Expand Down Expand Up @@ -69,7 +67,7 @@ The number of parameters (weights) in each layer.
The total number of parameters (weights) in the model.
The summary can be created by calling the 'summary()' function on the model that returns a string that in turn can be printed.

Below is the Summary image captured from of this model, We can clearly see the output shape and number of weights in each layer:
Below is the summary image of the trained Keras model. We can clearly see the output shape and number of weights in each layer:

![summary](summary.png)

Expand Down
2 changes: 1 addition & 1 deletion examples/TensorFlow/Keras/regenerate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ set -ex

# Script to regenerate and test the examples

cd MNIST
cd MNIST

python keras_model.py -nogui

Expand Down

0 comments on commit 3b24a67

Please sign in to comment.