File tree Expand file tree Collapse file tree 1 file changed +27
-8
lines changed Expand file tree Collapse file tree 1 file changed +27
-8
lines changed Original file line number Diff line number Diff line change 18
18
PLAIN_TYPES = (str , int , float , bool )
19
19
20
20
# List of Keras modules with built-in string representations for Keras defaults
21
- BUILTIN_MODULES = (
22
- "activations" ,
23
- "constraints" ,
24
- "initializers" ,
25
- "losses" ,
26
- "metrics" ,
27
- "optimizers" ,
28
- "regularizers" ,
21
+ BUILTIN_MODULES = frozenset (
22
+ {
23
+ "activations" ,
24
+ "constraints" ,
25
+ "initializers" ,
26
+ "losses" ,
27
+ "metrics" ,
28
+ "optimizers" ,
29
+ "regularizers" ,
30
+ }
31
+ )
32
+
33
+ LOADING_APIS = frozenset (
34
+ {
35
+ "keras.models.load_model" ,
36
+ "keras.preprocessing.image.load_img" ,
37
+ "keras.saving.load_model" ,
38
+ "keras.saving.load_weights" ,
39
+ "keras.utils.get_file" ,
40
+ "keras.utils.load_img" ,
41
+ }
29
42
)
30
43
31
44
@@ -765,6 +778,12 @@ def _retrieve_class_or_fn(
765
778
if module == "keras" or module .startswith ("keras." ):
766
779
api_name = module + "." + name
767
780
781
+ if api_name in LOADING_APIS :
782
+ raise ValueError (
783
+ f"Cannot deserialize `{ api_name } `, loading functions are "
784
+ "not allowed during deserialization"
785
+ )
786
+
768
787
obj = api_export .get_symbol_from_name (api_name )
769
788
if obj is not None :
770
789
return obj
You can’t perform that action at this time.
0 commit comments