2016-04-26 16 views
1

Gibt es eine Möglichkeit, die Theano-Graphendarstellung eines Sequential-Modells in Keras auszudrucken?Theano-Grafikdruck in Keras

ein einfaches Modell wie folgt gegeben:

model = Sequential() 

model.add(Dense(input_dim=100, 
       output_dim=50, 
       W_regularizer=l2(0.0001), 
       init='he_normal', 
       activation='tanh')) 

model.add(Dense(input_dim=50, 
       output_dim=1, 
       W_regularizer=l2(0.0001), 
       init='he_normal', 
       activation='sigmoid')) 

sgd = SGD(lr=0.01, decay=1e-7, momentum=.9) 
model.compile(loss='binary_crossentropy', optimizer=sgd, metrics=["accuracy"]) 

ich ausführen möchten:

theano.printing.debugprint(model) 

mich so etwas zu geben (von Theano Tutorial genommen):

Elemwise{mul,no_inplace} [id A] '' 
|TensorConstant{2.0} [id B] 
|x [id C] 

Ich hoffe, dass die Grafik hilft, die Ausgabe von Theano Profiler zu verstehen.

Keras Version 1.0, Theano Version 0.8.1.

Antwort

1

Falls jemand anderes etwas Ähnliches machen möchte, hier ist ein Ansatz, den ich herausgefunden habe.

import theano 
for i in model.layers: 
    theano.printing.debugprint(i.input) 
    theano.printing.debugprint(i.output) 

Es gibt:

dense_input_2 [id A] 
Elemwise{tanh,no_inplace} [id A] '' 
|Elemwise{add,no_inplace} [id B] '' 
    |dot [id C] '' 
    | |dense_input_2 [id D] 
    | |dense_4_W [id E] 
    |DimShuffle{x,0} [id F] '' 
    |dense_4_b [id G] 
Elemwise{tanh,no_inplace} [id A] '' 
|Elemwise{add,no_inplace} [id B] '' 
    |dot [id C] '' 
    | |dense_input_2 [id D] 
    | |dense_4_W [id E] 
    |DimShuffle{x,0} [id F] '' 
    |dense_4_b [id G] 
sigmoid [id A] '' 
|Elemwise{add,no_inplace} [id B] '' 
    |dot [id C] '' 
    | |Elemwise{tanh,no_inplace} [id D] '' 
    | | |Elemwise{add,no_inplace} [id E] '' 
    | | |dot [id F] '' 
    | | | |dense_input_2 [id G] 
    | | | |dense_4_W [id H] 
    | | |DimShuffle{x,0} [id I] '' 
    | |  |dense_4_b [id J] 
    | |dense_5_W [id K] 
    |DimShuffle{x,0} [id L] '' 
    |dense_5_b [id M]