File tree Expand file tree Collapse file tree 1 file changed +15
-6
lines changed Expand file tree Collapse file tree 1 file changed +15
-6
lines changed Original file line number Diff line number Diff line change 1
- from typing import Text , Union
1
+ from typing import Union
2
2
3
3
import keras
4
4
5
5
6
6
def clone_initializer (
7
- initializer : Union [Text , keras .initializers .Initializer ],
7
+ initializer : Union [str , keras .initializers .Initializer ],
8
8
) -> keras .initializers .Initializer :
9
9
"""Clones an initializer to ensure a new seed.
10
10
11
+ Args:
12
+ initializer: The initializer to clone.
13
+
14
+ Returns:
15
+ A cloned initializer if it is clonable, otherwise the original one.
16
+
11
17
As of tensorflow 2.10, we need to clone user passed initializers when
12
18
invoking them twice to avoid creating the same randomized initialization.
13
19
"""
20
+ if isinstance (initializer , keras .initializers .Initializer ):
21
+ config = initializer .get_config ()
22
+ initializer_class : type [keras .initializers .Initializer ] = (
23
+ initializer .__class__
24
+ )
25
+ return initializer_class .from_config (config )
14
26
# If we get a string or dict, just return as we cannot and should not clone.
15
- if not isinstance (initializer , keras .initializers .Initializer ):
16
- return initializer
17
- config = initializer .get_config ()
18
- return initializer .__class__ .from_config (config )
27
+ return initializer
You can’t perform that action at this time.
0 commit comments