(self)
| 310 | _import_and_infer(save_dir, {"x": 3.})) |
| 311 | |
| 312 | def test_datastructures(self): |
| 313 | |
| 314 | class HasDatastructures(util.Checkpoint): |
| 315 | |
| 316 | def __init__(self): |
| 317 | self.a = [1.] |
| 318 | self.a.append(variables.Variable(2.)) |
| 319 | self.b = {"a": variables.Variable(3.)} |
| 320 | |
| 321 | @def_function.function(input_signature=[tensor_spec.TensorSpec( |
| 322 | shape=None, dtype=dtypes.float32)]) |
| 323 | def add(self, x): |
| 324 | return x + math_ops.add_n(self.a) + self.b["a"] |
| 325 | |
| 326 | to_save = HasDatastructures() |
| 327 | to_save.add(constant_op.constant(1.)) |
| 328 | save_dir = os.path.join(self.get_temp_dir(), "saved_model") |
| 329 | save.save(to_save, save_dir) |
| 330 | self.assertAllClose({"output_0": 10.}, |
| 331 | _import_and_infer(save_dir, {"x": 4.})) |
| 332 | |
| 333 | def test_default_attr_stripping(self): |
| 334 |
nothing calls this directly
no test coverage detected