Add the test case
This commit is contained in:
parent
cc791f59c4
commit
49b07e6645
@ -18,6 +18,8 @@ from __future__ import absolute_import
|
||||
from __future__ import division
|
||||
from __future__ import print_function
|
||||
|
||||
import numpy as np
|
||||
|
||||
from tensorflow.python import keras
|
||||
from tensorflow.python.platform import test
|
||||
|
||||
@ -298,6 +300,53 @@ class SerializeKerasObjectTest(test.TestCase):
|
||||
self.assertEqual(new_layer.units, 3)
|
||||
self.assertIs(new_layer.units.fn, serializable_fn)
|
||||
|
||||
def test_serializable_with_old_config(self):
|
||||
# model config generated by tf-1.2.1
|
||||
old_model_config = {
|
||||
'class_name': 'Sequential',
|
||||
'config': [
|
||||
{
|
||||
'class_name': 'Dense',
|
||||
'config': {
|
||||
'name': 'dense_1',
|
||||
'trainable': True,
|
||||
'batch_input_shape': [
|
||||
None,
|
||||
784
|
||||
],
|
||||
'dtype': 'float32',
|
||||
'units': 32,
|
||||
'activation': 'linear',
|
||||
'use_bias': True,
|
||||
'kernel_initializer': {
|
||||
'class_name': 'Ones',
|
||||
'config': {
|
||||
'dtype': 'float32'
|
||||
}
|
||||
},
|
||||
'bias_initializer': {
|
||||
'class_name': 'Zeros',
|
||||
'config': {
|
||||
'dtype': 'float32'
|
||||
}
|
||||
},
|
||||
'kernel_regularizer': None,
|
||||
'bias_regularizer': None,
|
||||
'activity_regularizer': None,
|
||||
'kernel_constraint': None,
|
||||
'bias_constraint': None
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
old_model = keras.utils.generic_utils.deserialize_keras_object(
|
||||
old_model_config, module_objects={'Sequential': keras.Sequential})
|
||||
new_model = keras.Sequential(
|
||||
[keras.layers.Dense(32, input_dim=784, kernel_initializer='Ones'),])
|
||||
input_data = np.random.normal(2, 1, (5, 784))
|
||||
output = old_model.predict(input_data)
|
||||
expected_output = new_model.predict(input_data)
|
||||
self.assertAllEqual(output, expected_output)
|
||||
|
||||
class SliceArraysTest(test.TestCase):
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user