4371007e154b7882062cab8696b26d520252971b,test/test_keras.py,KerasTests,test_load_model_custom_objects,#KerasTests#,133

Before Change


            y = np.random.random((1, 3, 3))
            model.train_on_batch(x, y)

            _, fname = tempfile.mkstemp(".h5")
            model.save(fname)

            custom_objects = {
                "TestOptimizer": lambda **kwargs: hvd.DistributedOptimizer(
                    TestOptimizer(**kwargs))
            }
            new_model = hvd.load_model(fname, custom_objects=custom_objects)
            new_opt = new_model.optimizer
            os.remove(fname)

            self.assertEqual(type(new_opt).__module__, "horovod._keras")
            self.assertEqual(type(new_opt).__name__, "TestOptimizer")
            self.assertEqual(K.get_value(opt.lr), K.get_value(new_opt.lr))

After Change


            y = np.random.random((1, 3, 3))
            model.train_on_batch(x, y)

            with temppath() as fname:
                model.save(fname)

                custom_objects = {
                    "TestOptimizer": lambda **kwargs: hvd.DistributedOptimizer(
                        TestOptimizer(**kwargs))
                }
                new_model = hvd.load_model(fname, custom_objects=custom_objects)
                new_opt = new_model.optimizer

            self.assertEqual(type(new_opt).__module__, "horovod._keras")
            self.assertEqual(type(new_opt).__name__, "TestOptimizer")
            self.assertEqual(K.get_value(opt.lr), K.get_value(new_opt.lr))
            self._check_optimizer_weights(opt, new_opt)
Italian Trulli
In pattern: SUPERPATTERN

Frequency: 3

Non-data size: 8

Instances


Project Name: horovod/horovod
Commit Name: 4371007e154b7882062cab8696b26d520252971b
Time: 2020-03-24
Author: github@enrico.minack.dev
File Name: test/test_keras.py
Class Name: KerasTests
Method Name: test_load_model_custom_objects


Project Name: horovod/horovod
Commit Name: 4371007e154b7882062cab8696b26d520252971b
Time: 2020-03-24
Author: github@enrico.minack.dev
File Name: test/test_keras.py
Class Name: KerasTests
Method Name: test_load_model_custom_optimizers


Project Name: horovod/horovod
Commit Name: 4371007e154b7882062cab8696b26d520252971b
Time: 2020-03-24
Author: github@enrico.minack.dev
File Name: test/test_keras.py
Class Name: KerasTests
Method Name: test_load_model