Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] graph_view() does not work #79

Closed
dudung opened this issue Nov 23, 2024 · 12 comments
Closed

[BUG] graph_view() does not work #79

dudung opened this issue Nov 23, 2024 · 12 comments

Comments

@dudung
Copy link

dudung commented Nov 23, 2024

Describe the bug
The use of visualkeras.graph_view(model) does not produce the graph.

Minimal Code To Reproduce

import visualkeras
import tensorflow as tf

model = tf.keras.Sequential([
    tf.keras.layers.Dense(64, input_dim=10, activation='relu'),
    tf.keras.layers.Dense(1)
])
visualkeras.graph_view(model)

Expected behavior
It should show the model in graph mode.

Screenshots
image

Environment:

  • OS: Windows Version 10.0.22631.4460
  • Python 3.12.3
  • Module Version
    • TensorFlow 2.16.1
    • Keras 3.3.3
    • Visualkeras 0.1.3
    • Graphviz 0.20.3

Additional context
It works with visualkeras.layered_view(model) but not with visualkeras.graph_view(model).

Example in #67 have not worked anymore.

@Soontosh
Copy link
Collaborator

On it

@Soontosh
Copy link
Collaborator

This seems to be a compatability error between visualkeras and keras >= 3.0.0. The Tensorflow version you are using requires a version of keras greater than 3.0.0, and the Python version you are using cannot use a Tensorflow version lower than 2.16, meaning you'd have to downgrade Python to get graph_view working.

I'll try and find the change that broke compatability past keras 3.0.0 for this function. For now, if possible, I'd recommend downgrading Tensorflow to a point where you can run Keras 2 without running into dependency conflicts so you can use graph_view. This will probably mean you'll have to downgrade your Python version too.

I'll try to get this fixed today. Thank you for using visualkeras.

@dudung
Copy link
Author

dudung commented Nov 23, 2024

@Soontosh, thank you for the prompt response. I will wait for your fix and would it be available on PyPI or from this repo?

And for the suggestion, I should make new virtual environment that is able to run Keras 2, by downgrading any related modules including TensorFlow and Python, right?

Other question, why there are more examples using layered_view() than graph_view()? I like the first than the second since I just begin to learn NN and need to know the detail of a layer visually.

@Soontosh
Copy link
Collaborator

@dudung Yes, I'd recommend you make a new venv that is able to run Keras version 2.12 by downgrading Python to version 3.11 and Tensorflow to version 2.12. 2.12 is the highest version currently supported.

But there is no longer any need to do so. I am merging a fix to your issue (along with some other issues) right now. Thanks for helping me catch this, graph_view didn't work for versions Keras 2.12 and above at all.

To answer your question: The library was originally made with just layered_view. The graph_view function was added later down the line. That's why there aren't many examples for the latter. This is actually something I noticed while fixing the bug you caught. I'll be sure to add more examples for graph_view in future updates.

Once I merge the changes, run the following command to get the updates:

pip install git+https://github.com/paulgavrikov/visualkeras

Soontosh added a commit that referenced this issue Nov 24, 2024
Fix to issue #79 + adjacent bugs
@Soontosh
Copy link
Collaborator

Just made the merge. Let me know if you run into any issues. I'll add this plus a fix for #77 to Pypi once I'm done testing the changes.

@dudung
Copy link
Author

dudung commented Nov 24, 2024

installation

I am able to install it with

pip install git+https://github.com/paulgavrikov/visualkeras

but only after uninstall version 0.1.3 first.

result

image

I am expecting that the first layer is a layer with 6 neurons, and the boxes on the left and right are not required, right? It should be layers with (6 - 8 - 4 - 2) neurons.

The expected result is as follow.

image

code

import keras
from keras import Input, Model
from keras.models import Sequential
from keras.layers import Dense
import visualkeras

inputs = Input(shape=(6,))
hiddens1 = Dense(8, activation='relu')(inputs)
hiddens2 = Dense(4, activation='relu')(hiddens1)
outputs = Dense(2, activation='tanh')(hiddens2)
model = Model(inputs=inputs, outputs=outputs)
visualkeras.graph_view(model)

The graph_view does not produce any error messages with Sequential API (first example) and Functional API (last example), but the results are not as expected.

@Soontosh
Copy link
Collaborator

You have to set input_as_tensor to false to get the nodes to show properly. We use a box by default because the input shape is sometimes very large, so it looks better to display it as a single rectangle rather than, for example, 100 nodes (for a 10 by 10 input shape).

@dudung
Copy link
Author

dudung commented Nov 24, 2024

Do you mean inout_as_tensor?

image

Previous result is when it is set to True, but when I is set it to False following result is obtained.

image

@Soontosh
Copy link
Collaborator

Yes, I meant inout_as_tensor, sorry about that.

This seems to be a new bug. Could you open up a new issue for this bug? With information about your environment and venv packages?

@dudung
Copy link
Author

dudung commented Nov 24, 2024

I will do that. Thank you for the direction.

@dudung
Copy link
Author

dudung commented Nov 24, 2024

This seems to be a new bug. Could you open up a new issue for this bug? With information about your environment and venv packages?

Done in #82.

@Soontosh
Copy link
Collaborator

Bug has been squashed as part of the latest release. Access it at: https://pypi.org/project/visualkeras/0.1.4/

Closing this issue now. Thank you so much for your help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants