Create a Keras model for testing. Args: layer_name_prefix: A prefix string for layer names. This helps avoid clashes in layer names between different test methods. h5_path: Optional string path for a HDF5 (.h5) file to save the model in. Returns: An instance of tf_keras
(layer_name_prefix, h5_path=None)
| 42 | |
| 43 | |
| 44 | def _createKerasModel(layer_name_prefix, h5_path=None): |
| 45 | """Create a Keras model for testing. |
| 46 | |
| 47 | Args: |
| 48 | layer_name_prefix: A prefix string for layer names. This helps avoid |
| 49 | clashes in layer names between different test methods. |
| 50 | h5_path: Optional string path for a HDF5 (.h5) file to save the model |
| 51 | in. |
| 52 | |
| 53 | Returns: |
| 54 | An instance of tf_keras.Model. |
| 55 | """ |
| 56 | input_tensor = tf_keras.layers.Input((3, )) |
| 57 | dense1 = tf_keras.layers.Dense( |
| 58 | 4, |
| 59 | use_bias=True, |
| 60 | kernel_initializer='ones', |
| 61 | bias_initializer='zeros', |
| 62 | name=layer_name_prefix + '1')(input_tensor) |
| 63 | output = tf_keras.layers.Dense( |
| 64 | 2, |
| 65 | use_bias=False, |
| 66 | kernel_initializer='ones', |
| 67 | name=layer_name_prefix + '2')(dense1) |
| 68 | model = tf_keras.models.Model(inputs=[input_tensor], outputs=[output]) |
| 69 | model.compile(optimizer='adam', loss='binary_crossentropy') |
| 70 | model.predict(tf.ones((1, 3)), steps=1) |
| 71 | |
| 72 | if h5_path: |
| 73 | model.save(h5_path, save_format='h5') |
| 74 | return model |
| 75 | |
| 76 | def _createTensorFlowSavedModelV1(name_scope, save_path): |
| 77 | """Create a TensorFlow SavedModel for testing. |
no test coverage detected
searching dependent graphs…