python - ValueError: Input 0 is in compatible with layersimilarity_model: 预期形状=(None, 224, 224, 3), found shape=(None, None, 224, 224, 3)
问题描述
我正在使用 tensorflow_similarity 创建模型。第一个 epoch 结束时引发的错误。
INPUT_SHAPE = (224,224,3)
我的模型(与示例回购https://github.com/tensorflow/similarity/blob/master/examples/supervised_hello_world.ipynb相同)
def create_model():
inputs = tf.keras.layers.Input(shape=INPUT_SHAPE)
x = tf.keras.layers.experimental.preprocessing.Rescaling(1./255)(inputs)
x = tf.keras.layers.Conv2D(32, 7, activation='relu')(x)
x = tf.keras.layers.Conv2D(32, 3, activation='relu')(x)
x = tf.keras.layers.MaxPool2D()(x)
x = tf.keras.layers.Conv2D(64, 7, activation='relu')(x)
x = tf.keras.layers.Conv2D(64, 3, activation='relu')(x)
x = tf.keras.layers.Flatten()(x)
x = tf.keras.layers.Dense(64, activation='relu')(x)
outputs = MetricEmbedding(64)(x)
return SimilarityModel(inputs, outputs)
我也尝试过通过 api 使用不同的模型
model = EfficientNetSim(input_shape=INPUT_SHAPE,embedding_size = 128,variant = "B0",augmentation = False,weights = None)
该错误也与以前相同。
ValueError: Input 0 is incompatible with layer similarity_model: expected shape=(None, 224, 224, 3), found shape=(None, None, 224, 224, 3)
解决方案
我解决了错误。合适的是validation_data。tensorflow_similarity 中的采样器生成不等于 validation_data 的新批次。通过在 ( x_val , y_val ) 中给出验证数据或使等于采样器的批次来解决。
推荐阅读
- javascript - 倒计时结束后重定向
- python - 确定时间戳的可能日期时间范围
- bash - Makefile .tar:展平源文件的目录结构
- docker - Docker Compose 通过 SSH 失败
- python - 获取错误 AttributeError: 'datetime.datetime' 对象在尝试添加一些日期时间时没有属性 'timedelta'
- sqlite - 将 Nesper 连接到外部数据库 PgSQL/SQLite
- synchronization - 如何在 p2p 游戏的 2 个对等方之间同步时钟
- google-cloud-platform - 验证模型从 Cloud Scheduler 上传到 VertexAI 作业
- python - 通过 django SMTP 发送电子邮件而不在刷新时发送表单数据?
- docusignapi - 如何使用 C# DocuSign 的 API 查看一批信封的自定义字段