You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Visualize model plot and update model summary for ep. 2 (#536)
* Updated output from model.summary() call
Looks cleaner and it should match with what the learner would get.
Got this by using the following versions of the package with Python
3.12.
Name: tensorflow
Version: 2.18.0
Name: keras
Version: 3.8.0
* Model output names it functional now
* Describe the memory footprint showing the model summary output
* Tweak the model summary so that it can be viewed without scrolling
* Add plot_model function and show its output
* Add pydot dependency to setup
* Move the instructor note before the challenge
* Reword: data type
* Fix alt text for 02_plot_model.png
* Typo: a graph -> in graph form
* Fix grammar.
Co-authored-by: Ashwin V. Mohanan <[email protected]>
* Add installation instructions for Graphviz to setup
* A minor typo: follow -> follows
* Rewrite instructions for checking if Graphviz works
Co-authored-by: Sven van der Burg <[email protected]>
* Change instructor note for optional question 3 visualizing the model
---------
Co-authored-by: Carsten Schnober <[email protected]>
Co-authored-by: Sven van der Burg <[email protected]>
Copy file name to clipboardexpand all lines: episodes/2-keras.Rmd
+76-18
Original file line number
Diff line number
Diff line change
@@ -410,6 +410,13 @@ Keras distinguishes between two types of weights, namely:
410
410
If these reasons are not clear right away, don't worry! In later episodes of this course, we will touch upon a couple of these concepts.
411
411
:::
412
412
413
+
414
+
::: instructor
415
+
For optional question 3 in the challenge below named 'Visualizing the model', the goal is to visualize the network. It supplements the textual explanation of output from `model.summary()`.
416
+
You could choose to show and discuss the resulting visualization to the learners, so that learners who did not finish the optional exercise can also learn from the visualization of the model.
417
+
:::
418
+
419
+
413
420
::: challenge
414
421
## Create the neural network
415
422
With the code snippets above, we defined a Keras model with 1 hidden layer with
@@ -419,13 +426,37 @@ With the code snippets above, we defined a Keras model with 1 hidden layer with
419
426
2. What happens to the number of parameters if we increase or decrease the number of neurons
420
427
in the hidden layer?
421
428
429
+
#### (optional) Visualizing the model
430
+
Optionally, you can also visualize the same information as `model.summary()` in graph form.
431
+
This step requires the command-line tool `dot` from Graphviz installed, you installed it by following the setup instructions.
432
+
You can check that the installation was successful by executing `dot -V` in the command line. You should get something
433
+
as follows:
434
+
435
+
```sh
436
+
$ dot -V
437
+
dot - graphviz version 2.43.0 (0)
438
+
```
439
+
440
+
3. (optional) Provided you have `dot` installed, execute the `plot_model` function
441
+
as shown below.
442
+
443
+
```python
444
+
keras.utils.plot_model(
445
+
model,
446
+
show_shapes=True,
447
+
show_layer_names=True,
448
+
show_layer_activations=True,
449
+
show_trainable=True
450
+
)
451
+
```
452
+
422
453
#### (optional) Keras Sequential vs Functional API
423
454
So far we have used the [Functional API](https://keras.io/guides/functional_api/) of Keras.
424
455
You can also implement neural networks using [the Sequential model](https://keras.io/guides/sequential_model/).
425
456
As you can read in the documentation, the Sequential model is appropriate for **a plain stack of layers**
426
457
where each layer has **exactly one input tensor and one output tensor**.
427
458
428
-
3. (optional) Use the Sequential model to implement the same network
459
+
4. (optional) Use the Sequential model to implement the same network
[sex_pairplot]: fig/02_sex_pairplot.png"Pair plot grouped by sex"
816
871
{alt='Grid of scatter plots and histograms comparing observed values of the four physicial attributes (features) measured in the penguins sampled, with data points coloured according to the sex of the individual sampled. The pair plot shows similarly-shaped distribution of values observed for each feature in male and female penguins, with the distribution of measurements for females skewed towards smaller values.'}
817
872
873
+
[plot-model]: fig/02_plot_model.png"Output of keras.utils.plot_model() function"
874
+
{alt='A directed graph showing the three layers of the neural network connected by arrows. First layer is of type InputLayer. Second layer is of type Dense with a relu activation. The third layer is also of type Dense, with a softmax activation. The input and output shapes of every layer are also mentioned. Only the second and third layers contain trainable parameters.'}
0 commit comments