1
1
# Add keras.utils for the random seed
2
- from keras import utils
3
2
import os
4
- import numpy as np
3
+
5
4
import keras
6
- from keras import Model
5
+ import numpy as np
7
6
from keras import Input
7
+ from keras import Model
8
8
from keras import ops
9
- from keras_hub .src .layers .preprocessing .random_elastic_deformation_3d import RandomElasticDeformation3D
9
+ from keras import utils
10
+
11
+ from keras_hub .src .layers .preprocessing .random_elastic_deformation_3d import (
12
+ RandomElasticDeformation3D ,
13
+ )
10
14
from keras_hub .src .tests .test_case import TestCase
11
15
12
16
@@ -44,12 +48,15 @@ def test_serialization(self):
44
48
model = Model (inputs = [image_input , label_input ], outputs = outputs )
45
49
original_output_image , original_output_label = model (input_data )
46
50
path = os .path .join (self .get_temp_dir (), "model.keras" )
47
-
51
+
48
52
# --- FIX: Remove the deprecated save_format argument ---
49
53
model .save (path )
50
-
54
+
51
55
loaded_model = keras .models .load_model (
52
- path , custom_objects = {"RandomElasticDeformation3D" : RandomElasticDeformation3D }
56
+ path ,
57
+ custom_objects = {
58
+ "RandomElasticDeformation3D" : RandomElasticDeformation3D
59
+ },
53
60
)
54
61
loaded_output_image , loaded_output_label = loaded_model (input_data )
55
62
np .testing .assert_allclose (
@@ -71,4 +78,4 @@ def test_label_values_are_preserved(self):
71
78
_ , output_label = layer ((image , label ))
72
79
output_values = set (np .unique (ops .convert_to_numpy (output_label )))
73
80
expected_values = {0 , 1 , 2 , 3 }
74
- self .assertLessEqual (output_values , expected_values )
81
+ self .assertLessEqual (output_values , expected_values )
0 commit comments