RedaOps / ann-visualizer

A python library for visualizing Artificial Neural Networks (ANN)
MIT License
1.24k stars 216 forks source link

ValueError #7

Open adeyris opened 6 years ago

adeyris commented 6 years ago

Hi ! Thanks for this contribution :)

I'm trying to run ann-visualizer on keras-RetinaNet, but I get this error :

ValueError: invalid literal for int() with base 10: 'Non'

Any idea of how to solve it ?

RedaOps commented 6 years ago

Can you provide a code sample?

RedaOps commented 6 years ago

It seems like keras-RetinaNet uses a DenseNet object to build the network. Our library only supports Sequential objects at this time.

z2e2 commented 6 years ago

I run into the same issue. It says ValueError: invalid literal for int() with base 10: ''. I think it is because you try to parse the input shape using the following command: str(input_shape).split(',')[1][1:-1] But the problem with my keras is that my keras input shape is (None, 4, 125). I don't think the code works for this case. Is my keras version different from yours?

RedaOps commented 6 years ago

@ZZHAOatEESI Are you passing the ann_viz() function a Model or a Sequential object?

z2e2 commented 6 years ago

I passed a model object

On Apr 24, 2018, at 3:53 PM, Tudor Gheorghiu notifications@github.com<mailto:notifications@github.com> wrote:

@ZZHAOatEESIhttps://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2FZZHAOatEESI&data=02%7C01%7Czz374%40drexel.edu%7C139c5922b698493b096d08d5aa1d09ae%7C3664e6fa47bd45a696708c4f080f8ca6%7C0%7C0%7C636601964055275819&sdata=r2oaATx5HHnFx9GresQgg6O6RSTj9i19qXwyYcEqGF8%3D&reserved=0 Are you passing the ann_viz() function a Model or a Sequential object?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2FProdicode%2Fann-visualizer%2Fissues%2F7%23issuecomment-384058558&data=02%7C01%7Czz374%40drexel.edu%7C139c5922b698493b096d08d5aa1d09ae%7C3664e6fa47bd45a696708c4f080f8ca6%7C0%7C0%7C636601964055275819&sdata=j8%2FcGMLECrLRtvQI%2BjvcT00t7yCpik6aMQZaZsAvD1g%3D&reserved=0, or mute the threadhttps://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FASUuoXOeeNWoC7isdgVEbag5C9yX1L-Xks5tr4KngaJpZM4TX-_G&data=02%7C01%7Czz374%40drexel.edu%7C139c5922b698493b096d08d5aa1d09ae%7C3664e6fa47bd45a696708c4f080f8ca6%7C0%7C0%7C636601964055275819&sdata=uK%2BWPVDTMRjVNLnTubIY9yMhzFo4EpG0FHQan0Os3mA%3D&reserved=0.

shivam05011996 commented 6 years ago

@Prodicode I have a siamese network, trying to visualise it but got this error -

raise ValueError("ANN Visualizer: Layer not supported for visualizing");
ValueError: ANN Visualizer: Layer not supported for visualizing

I have tried various methods to make it visualise but nothing helps. Any help is appreciated.

Model Summary -

__________________________________________________________________________________________________
Layer (type)                    Output Shape         Param #     Connected to                     
==================================================================================================
input_1 (InputLayer)            (None, 300)          0                                            
__________________________________________________________________________________________________
input_2 (InputLayer)            (None, 300)          0                                            
__________________________________________________________________________________________________
sequential_1 (Sequential)       (None, 300)          564200      input_1[0][0]                    
                                                                 input_2[0][0]                    
__________________________________________________________________________________________________
lambda_1 (Lambda)               (None, 1)            0           sequential_1[1][0]               
                                                                 sequential_1[2][0]               
==================================================================================================
Total params: 564,200
Trainable params: 564,200
Non-trainable params: 0
RedaOps commented 6 years ago

@shivam-deepcompute Can you provide the piece of code where you build the keras Sequential model? (Layer by layer)

shivam05011996 commented 6 years ago

@Prodicode

def _create_base_network(self, input_dim):
    a = 'softsign'
    network = Sequential()
    network.add(Dense(1000, input_shape=(input_dim,), activation=a)
    network.add(Dense(150, input_shape=(input_dim,), activation=a))
    network.add(Dense(250, input_shape=(input_dim,), activation=a))
    network.add(Dense(300, input_shape=(input_dim,), activation='sigmoid')
    return network

This is my base sequential network, which accepts two inputs, as mentioned in the model summary. I hope this what you asked.

thpatty commented 6 years ago

@Prodicode

hello, i use your example , but i met this error below, can you help me ? i use windows 10 and jupyter notebook. i can see the two files in the same file directory with *.ipynb i can open the network.gv.pdf with chrome, i just only can see the first two layers. what is wrong with it?

thanks firstly.

OSError Traceback (most recent call last)

in () 50 51 model = build_cnn_model() ---> 52 ann_viz(model, title="") C:\ProgramData\Anaconda3\lib\site-packages\ann_visualizer\visualize.py in ann_viz(model, view, filename, title) 204 g.edge_attr.update(arrowhead="none", color="#707070"); 205 if view == True: --> 206 g.view(); C:\ProgramData\Anaconda3\lib\site-packages\graphviz\files.py in view(self, filename, directory, cleanup) 201 """ 202 return self.render(filename=filename, directory=directory, view=True, --> 203 cleanup=cleanup) 204 205 def _view(self, filepath, format): C:\ProgramData\Anaconda3\lib\site-packages\graphviz\files.py in render(self, filename, directory, view, cleanup) 180 181 if view: --> 182 self._view(rendered, self._format) 183 184 return rendered C:\ProgramData\Anaconda3\lib\site-packages\graphviz\files.py in _view(self, filepath, format) 216 raise RuntimeError('%r has no built-in viewer support for %r ' 217 'on %r platform' % (self.__class__, format, backend.PLATFORM)) --> 218 view_method(filepath) 219 220 _view_darwin = staticmethod(backend.view.darwin) C:\ProgramData\Anaconda3\lib\site-packages\graphviz\backend.py in view_windows(filepath) 227 def view_windows(filepath): 228 """Start filepath with its associated application (windows).""" --> 229 os.startfile(os.path.normpath(filepath)) OSError: [WinError -2147221003] Application not found: 'network.gv.pdf' import keras; from keras.models import Sequential; from keras.layers import Conv2D, Dense, Dropout, MaxPooling2D, Flatten; from ann_visualizer.visualize import ann_viz def build_cnn_model(): model = keras.models.Sequential() model.add( Conv2D( 32, (3, 3), padding="same", input_shape=(32, 32, 3), activation="relu")) model.add(Dropout(0.2)) model.add( Conv2D( 32, (3, 3), padding="same", input_shape=(32, 32, 3), activation="relu")) model.add(MaxPooling2D(pool_size=(2, 2))) model.add(Dropout(0.2)) model.add( Conv2D( 64, (3, 3), padding="same", input_shape=(32, 32, 3), activation="relu")) model.add(Dropout(0.2)) model.add( Conv2D( 64, (3, 3), padding="same", input_shape=(32, 32, 3), activation="relu")) model.add(MaxPooling2D(pool_size=(2, 2))) model.add(Dropout(0.2)) model.add(Flatten()) model.add(Dense(512, activation="relu")) model.add(Dropout(0.2)) model.add(Dense(10, activation="softmax")) return model model = build_cnn_model() ann_viz(model, title="")
LeandroRitter commented 6 years ago

Hi!

I am using ANN Visualizer to display concatenated/merged layers but get errors, could you direct me how to properly visualize concatenated layers? Here is my code:

import keras; from keras.models import Sequential; from keras.layers import Dense, Concatenate, Merge;

network = Sequential(); network.add(Dense(units=6, activation='relu', kernel_initializer='uniform', input_dim=11));

network.add(Dense(units=6, activation='relu', kernel_initializer='uniform'));

another_network = Sequential(); another_network.add(Dense(units=6, activation='relu', kernel_initializer='uniform', input_dim=11));

result = Sequential();

result = Merge([network, another_network], mode='concat')

result.add(Dense(units=1,

activation='sigmoid',

kernel_initializer='uniform'));

from ann_visualizer.visualize import ann_viz;

ann_viz(result, title = "", view = True);

and here is the error:


ValueError Traceback (most recent call last)

in () 28 from ann_visualizer.visualize import ann_viz; 29 ---> 30 ann_viz(result, title = "Autoencoder", view = True); 31 #convert -density 200 network.gv.pdf network.gv.png ~/miniconda3/lib/python3.6/site-packages/ann_visualizer/visualize.py in ann_viz(model, view, filename, title) 121 c.node(str(n), label="Image\n"+pxls[1]+" x"+pxls[2]+" pixels\n"+clrmap, fontcolor="white"); 122 else: --> 123 raise ValueError("ANN Visualizer: Layer not supported for visualizing"); 124 for i in range(0, hidden_layers_nr): 125 with g.subgraph(name="cluster_"+str(i+1)) as c: ValueError: ANN Visualizer: Layer not supported for visualizing
endolith commented 6 years ago

Same error:

model = Sequential([
    Dense(2, input_shape=(N, 2), use_bias=False)
    ])

ann_viz(model)
Traceback (most recent call last):

  File "<ipython-input-79-02a59322b308>", line 1, in <module>
    ann_viz(model)

  File "C:\Anaconda3\lib\site-packages\ann_visualizer\visualize.py", line 42, in ann_viz
    input_layer = int(str(layer.input_shape).split(",")[1][1:-1]);

ValueError: invalid literal for int() with base 10: ''
smholsen commented 5 years ago

I am also having the same issue with the following model. Do you know how to fix this? :)

            self.base_model = Sequential()
            self.base_model.add(Conv2D(20, input_shape=(5, 25, 1), kernel_size=(3, 3), strides=(1, 1), padding='same', activation='relu'))
            self.base_model.add(Flatten())
            self.base_model.add(Dropout(.4))
            self.base_model.add(Dense(1))
            # Compile model
            # self.base_model.summary()
            self.base_model.compile(loss='mse', optimizer='adam')
            self.base_model.fit(X1, y1, epochs=500, batch_size=128)
            ann_viz(self.base_model, title="ANN Topology")
  File "...\venv\lib\site-packages\ann_visualizer\visualize.py", line 42, in ann_viz
    input_layer = int(str(layer.input_shape).split(",")[1][1:-1]);
ValueError: invalid literal for int() with base 10: ''
thpatty commented 5 years ago

sorry, i cant kill this problem.

On Wed, Nov 14, 2018 at 5:58 PM Simon Olsen notifications@github.com wrote:

I am also having the same issue with the following model. Do you know how to fix this? :)

        self.base_model = Sequential()
        self.base_model.add(Conv2D(20, input_shape=(5, 25, 1), kernel_size=(3, 3), strides=(1, 1), padding='same', activation='relu'))
        self.base_model.add(Flatten())
        self.base_model.add(Dropout(.4))
        self.base_model.add(Dense(1))
        # Compile model
        # self.base_model.summary()
        self.base_model.compile(loss='mse', optimizer='adam')
        self.base_model.fit(X1, y1, epochs=500, batch_size=128)
        ann_viz(self.base_model, title="ANN Topology")

File "...\venv\lib\site-packages\ann_visualizer\visualize.py", line 42, in ann_viz input_layer = int(str(layer.input_shape).split(",")[1][1:-1]); ValueError: invalid literal for int() with base 10: ''

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/Prodicode/ann-visualizer/issues/7#issuecomment-438604895, or mute the thread https://github.com/notifications/unsubscribe-auth/Adqn8eqYqnmCjsh00gONa4hdcE1VRsnlks5uu-kwgaJpZM4TX-_G .

Asrix-AI commented 5 years ago

@shivam05011996 Did you get the solution?

ShrikanthSingh commented 4 years ago

<ipython-input-271-6323c76e75d0> in <module>()
     16 # load weights into new model
     17 model.load_weights("model.h5")
---> 18 ann_viz(model, title="Artificial Neural network - Model Visualization")

/usr/local/lib/python3.6/dist-packages/ann_visualizer/visualize.py in ann_viz(model, view, filename, title)
     40     for layer in model.layers:
     41         if(layer == model.layers[0]):
---> 42             input_layer = int(str(layer.input_shape).split(",")[1][1:-1]);
     43             hidden_layers_nr += 1;
     44             if (type(layer) == keras.layers.core.Dense):

ValueError: invalid literal for int() with base 10: ''```