我正在尝试在google colab上的keras中可视化以下模型,并且正在生成错误。我的模型是:
in_dim=50
out_dim=50
emb_layer = Embedding(in_dim, out_dim, weights=[emb_matrix],
trainable=False)
max_len = 50
kwargs = {'max_len': max_len,
'lr': 1e-3,
'emb_layer': emb_layer}
lr=1e-3
conv1 = Conv1D(filters=32, kernel_size=2, padding='same', activation='relu')
conv2 = Conv1D(filters=32, kernel_size=3, padding='same', activation='relu')
conv3 = Conv1D(filters=32, kernel_size=4, padding='same', activation='relu') #32 units rank_04
seq1 = Input(shape=(max_len,))
seq2 = Input(shape=(max_len,))
emb1 = emb_layer(seq1)
emb2 = emb_layer(seq2)
# Run through CONV + GAP layers
conv1a = conv1(emb1)
glob1a = GlobalMaxPool1D()(conv1a)
conv1b = conv1(emb2)
glob1b = GlobalMaxPool1D()(conv1b)
conv2a = conv2(emb1)
glob2a = GlobalMaxPool1D()(conv2a)
conv2b = conv2(emb2)
glob2b = GlobalMaxPool1D()(conv2b)
conv3a = conv3(emb1)
glob3a = GlobalMaxPool1D()(conv3a)
conv3b = conv3(emb2)
glob3b = GlobalMaxPool1D()(conv3b)
concatenate = Concatenate(axis=-1)
mergea = concatenate([glob1a, glob2a, glob3a])
mergeb = concatenate([glob1b, glob2b, glob3b])
## diff = Lambda(lambda x: K.abs(x[0] - x[1]), output_shape=(4*64 + 2*32,))([mergea, mergeb])
## mul = Lambda(lambda x: x[0] * x[1], output_shape=(4*64 + 2*32,))([mergea, mergeb])
diff = Lambda(lambda x: K.abs(x[0] - x[1]), output_shape=(32+32+32,))([mergea, mergeb])
mul = Lambda(lambda x: x[0] * x[1], output_shape=(32+32+32,))([mergea, mergeb])
merged = concatenate([diff, mul])
x = Dropout(0.4)(merge)
x = BatchNormalization()(merge)
x = BatchNormalization()(x)
x = Dense(64, activation='relu')(merged) #32 rank 04
x = Dropout(0.3)(x)
x = BatchNormalization()(x)
x = Dense(128, activation='relu')(x) #64 rank 04
x = Dropout(0.5)(x)
pred = Dense(1, activation='sigmoid')(x)
model = Model(inputs=[seq1, seq2], outputs=pred)
opt = Adam(lr=lr)
model.compile(loss='binary_crossentropy', optimizer=opt, metrics=['accuracy'])
model.summary()
plot_model(model, show_shapes=True, show_layer_names=True,to_file='model.png')
它生成以下错误:
['dot', '-Tpng', '/tmp/tmp5mczx3x7'] return code: -11
stdout, stderr:
b''
b'Error: in routesplines, cannot find NORMAL edge\n'
---------------------------------------------------------------------------
AssertionError Traceback (most recent call last)
<ipython-input-25-662cf084f705> in <module>()
----> 1 plot_model(model, show_shapes=True, show_layer_names=True)
/usr/local/lib/python3.6/dist-packages/keras/utils/vis_utils.py in plot_model(model, to_file, show_shapes, show_layer_names, rankdir)
136 else:
137 extension = extension[1:]
--> 138 dot.write(to_file, format=extension)
/usr/local/lib/python3.6/dist-packages/pydot.py in write(self, path, prog, format, encoding)
1755 f.write(s)
1756 else:
-> 1757 s = self.create(prog, format, encoding=encoding)
1758 with io.open(path, mode='wb') as f:
1759 f.write(s)
/usr/local/lib/python3.6/dist-packages/pydot.py in create(self, prog, format, encoding)
1883 out=stdout_data,
1884 err=stderr_data))
-> 1885 assert p.returncode == 0, p.returncode
1886 return stdout_data
AssertionError: -11
但是,当我尝试可视化其他模型时(来自“ https://laujohn.com/2018/09/24/Plot-Keras-Model-in-Colaboratory/”的示例),它正在生成模型。因此,我相信graphviz或pydot没有任何错误。如果还有其他可视化模型的方式,有人可以更新我吗?请帮助我解决此错误。