使用plot_model绘制网络模式失败。
import tensorflow as tf fashion_mnist = tf.keras.datasets.mnist (x_train, y_train), (x_test, y_test) = fashion_mnist.load_data() x_train, x_test = x_train / 255.0, x_test / 255.0 model = tf.keras.models.Sequential([ tf.keras.layers.Flatten(input_shape=(28, 28)), tf.keras.layers.Dense(128, activation='relu'), tf.keras.layers.Dropout(0.2), # tf.keras.layers.Dense(128, activation='relu'), # tf.keras.layers.Dropout(0.2), tf.keras.layers.Dense(10, activation='softmax') ]) loss_fn = tf.keras.losses.SparseCategoricalCrossentropy(from_logits=True) model.compile(optimizer='adam', loss=loss_fn, metrics=['accuracy']) model.fit(x_train, y_train, epochs=1, batch_size=600, verbose=1) model.evaluate(x_test, y_test, verbose=2) model.summary() tf.keras.utils.plot_model(model, "my_first_model.png")
出错提示如下:
'Failed to import pydot. You must install pydot'
ImportError: Failed to import pydot. You must install pydot and graphviz for `pydotprint` to work.
解决:
1. https://graphviz.gitlab.io/ ,下载windows版本的安装包。安装。
2. 读代码,C:Userslj.huangAppDataRoamingPythonPython37site-packages ensorflow_corepythonkerasutilsvis_utils.py
try: # pydot-ng is a fork of pydot that is better maintained. import pydot_ng as pydot
3. 从上以来看,pydot-ng是最好的。
pip install pydot-ng
4.再试,可以了。