keras plot_model not showing the input layer appropriately

  • Last Update :
  • Techknowledgy :

Comment this out:

@property
def layers(self):
   # Historically, `sequential.layers`
only returns layers that were added
# via `add`, and omits the auto - generated `InputLayer`
# that comes at the bottom of the stack.
if self._layers and isinstance(self._layers[0], InputLayer):
   return self._layers[1: ]
return self._layers

Suggestion : 2

Where the input layer is a series of numbers. Does anybody know how it let it show the input properly?, 6 days ago Keras plot_model 没有正确显示输入层(Keras plot_model not showing the input layer appropriately) 【问题标题】:Keras plot_model 没有正确显示输入层(Keras plot_model not showing the input layer appropriately) 【发布时间】:2019-01-14 00:15:38 【问题描述】: ,Keras Plot Model Not Showing The Input Layer Appropriately, model: A Keras model instance to_file: File name of the plot image. show_shapes: whether to display shape information. show_dtype: whether to display layer dtypes. show_layer_names: whether to display layer names.


model = keras.models.Sequential() model.add(layers.Embedding(max_features, 128, input_length = max_len, input_shape = (max_len, ), name = 'embed')) model.add(layers.Conv1D(32, 7, activation = 'relu')) model.add(layers.MaxPooling1D(5)) model.add(layers.Conv1D(32, 7, activation = 'relu')) model.add(layers.GlobalMaxPooling1D()) model.add(layers.Dense(1))

@property def layers(self): # Historically, `sequential.layers`
only returns layers that were added # via `add`, and omits the auto - generated `InputLayer`
# that comes at the bottom of the stack.if self._layers and isinstance(self._layers[0], InputLayer): return self._layers[1: ]
return self._layers

Suggestion : 3

Last updated 2022-06-28 UTC.

View aliases

Compat aliases for migration

See Migration guide for more details.

tf.compat.v1.keras.utils.plot_model

tf.keras.utils.plot_model(
   model,
   to_file = 'model.png',
   show_shapes = False,
   show_dtype = False,
   show_layer_names = True,
   rankdir = 'TB',
   expand_nested = False,
   dpi = 96,
   layer_range = None,
   show_layer_activations = False
)

Example:

input = tf.keras.Input(shape = (100, ), dtype = 'int32', name = 'input')
x = tf.keras.layers.Embedding(
   output_dim = 512, input_dim = 10000, input_length = 100)(input)
x = tf.keras.layers.LSTM(32)(x)
x = tf.keras.layers.Dense(64, activation = 'relu')(x)
x = tf.keras.layers.Dense(64, activation = 'relu')(x)
x = tf.keras.layers.Dense(64, activation = 'relu')(x)
output = tf.keras.layers.Dense(1, activation = 'sigmoid', name = 'output')(x)
model = tf.keras.Model(inputs = [input], outputs = [output])
dot_img_file = '/tmp/model_1.png'
tf.keras.utils.plot_model(model, to_file = dot_img_file, show_shapes = True)