我想在 TF2 中构建一个模型,它由以下组件组成:MobilenetV2
, 2 层,BLSTM
然后CTC
附加到它。下面演示了该模型:
def build_model():
img_width = 200
img_height = 50
input_img = layers.Input(shape=(img_width, img_height, 3), name="input_1", dtype="float32")
labels = layers.Input(name="label", shape=(None,), dtype="float32")
base_model=tf.keras.applications.MobileNet(
input_shape=(img_width, img_height, 3),
alpha=1.0,
depth_multiplier=1,
dropout=0.001,
include_top=False,
weights="imagenet",
input_tensor=None,
pooling=None,
classes=1000,
classifier_activation="softmax",
)
x = base_model.output
x = layers.Reshape(target_shape=(6,1024), name="reshape")(x)
x = Bidirectional(layers.LSTM(128, return_sequences=True, dropout=0.25))(x)
x = Bidirectional(layers.LSTM(64, return_sequences=True, dropout=0.25))(x)
output = CTCLayer(name="ctc_loss")(labels, x)
# Define the model
model = keras.models.Model(
inputs=[base_model.input, labels], outputs=output, name="ocr_model_v1"
)
# Optimizer
opt = keras.optimizers.Adam()
# Compile the model and return
model.compile(optimizer=opt)
return model
当我调用该build_model
函数时,它会引发以下错误:
ValueError:输入“input_1”缺少数据。您传递了一个带有键 ['image', 'label'] 的数据字典。需要以下键:['input_1', 'label']
知道如何解决吗?