-
Notifications
You must be signed in to change notification settings - Fork 116
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Constant Initializer Error fixed (#479)
* Constant Init tests * Comments fixed
- Loading branch information
Showing
2 changed files
with
44 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import numpy as np | ||
|
||
from keras_core import backend | ||
from keras_core import initializers | ||
from keras_core import testing | ||
|
||
|
||
class ConstantInitializersTest(testing.TestCase): | ||
def test_zeros_initializer(self): | ||
shape = (3, 3) | ||
|
||
initializer = initializers.Zeros() | ||
values = initializer(shape=shape) | ||
self.assertEqual(values.shape, shape) | ||
np_values = backend.convert_to_numpy(values).data | ||
self.assertEqual(np_values, np.zeros(shape=shape)) | ||
|
||
self.run_class_serialization_test(initializer) | ||
|
||
def test_ones_initializer(self): | ||
shape = (3, 3) | ||
|
||
initializer = initializers.Ones() | ||
values = initializer(shape=shape) | ||
self.assertEqual(values.shape, shape) | ||
np_values = backend.convert_to_numpy(values).data | ||
self.assertEqual(np_values, np.ones(shape=shape)) | ||
|
||
self.run_class_serialization_test(initializer) | ||
|
||
def test_constant_initializer(self): | ||
shape = (3, 3) | ||
constant_value = 6.0 | ||
|
||
initializer = initializers.Constant(value=constant_value) | ||
values = initializer(shape=shape) | ||
self.assertEqual(values.shape, shape) | ||
np_values = backend.convert_to_numpy(values).data | ||
self.assertEqual( | ||
np_values, np.full(shape=shape, fill_value=constant_value) | ||
) | ||
|
||
self.run_class_serialization_test(initializer) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters