Search code examples
python-3.xkerasneural-network

Error: "ANN Visualizer: Layer not supported for visualizing" in the function ann_viz()


So I am using the ann_visualizer for showing my keras model neural network graphically. The model works properly, but it gives this error whenever I try to visualize it via ann_viz().

"ValueError: ANN Visualizer: Layer not supported for visualizing"

I searched the internet but couldn't find a valid solution. this is the neural network model code


model = keras.Sequential()
model.add(keras.layers.Flatten(input_shape=(28,28)))
model.add(keras.layers.Dense(128,activation=keras.activations.relu))
model.add(keras.layers.Dense(10,activation=keras.activations.softmax))


model.compile(
    optimizer="adam",
    loss=keras.losses.sparse_categorical_crossentropy,
    metrics=["accuracy"]
)
model.fit(train_data, train_lables, epochs=10)

test_loss, test_acc = model.evaluate(test_data, test_lables)

And this is the ann_viz() function call

from ann_visualizer.visualize import ann_viz

ann_viz(model, title="Model")

Any idea how to make it work?


Solution

  • I also got the same error but was able to resolve by removing the Flatten() layer.

    #Flatten the input 
    X = X.reshape(X.shape[0], 28*28)
    
    model = keras.Sequential()
    
    #added flat input shape
    model.add(keras.layers.Dense(128,activation=keras.activations.relu, input_shape=(28*28,)))
    model.add(keras.layers.Dense(10,activation=keras.activations.softmax))
    
    model.compile(
    optimizer="adam",
    loss=keras.losses.sparse_categorical_crossentropy,
    metrics=["accuracy"]
    )
    
    #now you can call the ann_viz
    from ann_visualizer.visualize import ann_viz
    ann_viz(model, title="Model")
    

    Basically, I Flattened the input, removed the Flatten layer and added the flat input shape in the next layer. Don't know the exact reason though.