(self)
| 412 | compat.as_str_any(imported_path)) |
| 413 | |
| 414 | def test_table(self): |
| 415 | initializer = lookup_ops.TextFileInitializer( |
| 416 | self._vocab_path, |
| 417 | key_dtype=dtypes.string, |
| 418 | key_index=lookup_ops.TextFileIndex.WHOLE_LINE, |
| 419 | value_dtype=dtypes.int64, |
| 420 | value_index=lookup_ops.TextFileIndex.LINE_NUMBER) |
| 421 | root = util.Checkpoint(table=lookup_ops.HashTable( |
| 422 | initializer, default_value=-1)) |
| 423 | root.table_user = def_function.function( |
| 424 | root.table.lookup, |
| 425 | input_signature=[tensor_spec.TensorSpec(None, dtypes.string)]) |
| 426 | self.assertEqual( |
| 427 | 2, |
| 428 | self.evaluate(root.table_user(constant_op.constant("gamma")))) |
| 429 | save_dir = os.path.join(self.get_temp_dir(), "saved_model") |
| 430 | save.save(root, save_dir) |
| 431 | file_io.delete_file(self._vocab_path) |
| 432 | self.assertAllClose( |
| 433 | {"output_0": [2, 0]}, |
| 434 | _import_and_infer(save_dir, {"keys": ["gamma", "alpha"]})) |
| 435 | second_dir = os.path.join(self.get_temp_dir(), "second_dir") |
| 436 | # Asset paths should track the location the SavedModel is loaded from. |
| 437 | file_io.rename(save_dir, second_dir) |
| 438 | self.assertAllClose( |
| 439 | {"output_0": [2, 1]}, |
| 440 | _import_and_infer(second_dir, {"keys": ["gamma", "beta"]})) |
| 441 | |
| 442 | def test_unused_asset(self): |
| 443 | root = tracking.AutoTrackable() |
nothing calls this directly
no test coverage detected