InvalidArgumentError: logits and labels must have the same first dimension, got logits shape [20,2] and labels shape [40] 一个可能的处理方式是 model.compile(optimizer='adam', loss=tf.keras.losses.SparseCategoricalCrossentropy(from_logits=True), metrics=['accuracy']) 修改SparseCategoricalCrossentropy为CategoricalCrossentropy