<p><strong>更新(2021年1月4日):似乎这是可能的;见@M.Innat的<a href="https://stackoverflow.com/a/63898244/2099607">answer</a>。</strong></p>
<hr/>
<p>这项工作无法完成,因为与使用函数/顺序API(在TF术语中称为图形网络)创建的模型相比,基本上在TensorFlow中实现的模型子分类在特性和功能上受到限制。如果您检查<code>plot_model</code>源代码,您将在<code>model_to_dot</code>函数中看到<a href="https://github.com/tensorflow/tensorflow/blob/dc8f74544578756bad9d62f18349b35e31fba30a/tensorflow/python/keras/utils/vis_utils.py#L132-L135" rel="nofollow noreferrer">the following check</a>(由<code>plot_model</code>调用):</p>
<pre><code>if not model._is_graph_network:
node = pydot.Node(str(id(model)), label=model.name)
dot.add_node(node)
return dot
</code></pre>
<p>正如我所提到的,子类模型不是图网络,因此只会为这些模型绘制一个包含模型名称的节点(即,与您观察到的相同)</p>
<p>这已经在a<a href="https://github.com/tensorflow/tensorflow/issues/31647" rel="nofollow noreferrer">Github issue</a>中讨论过,TensorFlow的一位开发人员通过给出以下论点证实了这一行为:</p>
<blockquote>
<p>@omalleyt12 commented:</p>
<p>Yes in general we can't assume anything about the structure of a subclassed Model. If your Model can be though of as blocks of Layers and you wish to visualize it like that, we recommend you view the Functional API</p>
</blockquote>