层密集_20 的输入 0 与层不兼容:输入形状的预期轴 -1 具有值 1152,但接收到形状为 (1, 530880) 的输入

时间:2021-04-04 21:03:23

标签: python tensorflow

我定义了我的模型,然后将我的模型保存在一个文件夹中。但是,我正在尝试加载我的模型,但我不明白如何解决这个形状问题。

num_classes = len(class_names)
    model = tf.keras.Sequential([
      layers.experimental.preprocessing.Rescaling(1./255),
      layers.Conv2D(32, (3, 3), activation='relu', input_shape=(32, 32, 3)),
      layers.MaxPooling2D((2, 2)),
      layers.Conv2D(32, (3, 3), activation='relu'),
      layers.MaxPooling2D((2, 2)),
      layers.Conv2D(32, (3, 3), activation='relu'),
      layers.MaxPooling2D((2,2)),
      layers.Flatten(),
      layers.Dense(64, activation='relu'),
      #layers.Dense(128, activation='relu'),
      layers.Dense(num_classes)
    ])

model.compile(
  #loss='binary_crossentropy',
  optimizer='adam',
  loss=tf.losses.SparseCategoricalCrossentropy(from_logits=True),
  metrics=['accuracy']
)

history = model.fit(
  train_ds,
  validation_data=validation_ds,
  epochs=20,
  batch_size=32,
  verbose=0
)

model.summary()

tf.saved_model.save(model, '/content/drive/MyDrive/Colab Notebooks/Archivos para CodeChallenge2/trained_waldo_model')

enter image description here

enter image description here

enter image description here

0 个答案:

没有答案