You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

e2emodel.py 987 B

7 years ago
12345678910111213141516171819202122232425262728293031323334
  1. from keras import backend as K
  2. from keras.models import *
  3. from keras.layers import *
  4. import e2e
  5. def ctc_lambda_func(args):
  6. y_pred, labels, input_length, label_length = args
  7. y_pred = y_pred[:, 2:, :]
  8. return K.ctc_batch_cost(labels, y_pred, input_length, label_length)
  9. def construct_model(model_path):
  10. input_tensor = Input((None, 40, 3))
  11. x = input_tensor
  12. base_conv = 32
  13. for i in range(3):
  14. x = Conv2D(base_conv * (2 ** (i)), (3, 3),padding="same")(x)
  15. x = BatchNormalization()(x)
  16. x = Activation('relu')(x)
  17. x = MaxPooling2D(pool_size=(2, 2))(x)
  18. x = Conv2D(256, (5, 5))(x)
  19. x = BatchNormalization()(x)
  20. x = Activation('relu')(x)
  21. x = Conv2D(1024, (1, 1))(x)
  22. x = BatchNormalization()(x)
  23. x = Activation('relu')(x)
  24. x = Conv2D(len(e2e.chars)+1, (1, 1))(x)
  25. x = Activation('softmax')(x)
  26. base_model = Model(inputs=input_tensor, outputs=x)
  27. base_model.load_weights(model_path)
  28. return base_model