(self)
| 49 | logging.set_verbosity(logging.DEBUG) |
| 50 | |
| 51 | def testAssets(self): |
| 52 | original_asset_file = os.path.join(self.get_temp_dir(), "hello.txt") |
| 53 | _write_string_to_file(original_asset_file, "hello world") |
| 54 | |
| 55 | with tf.Graph().as_default() as graph: |
| 56 | asset_tensor = tf.constant(original_asset_file, name="file") |
| 57 | graph.add_to_collection(tf.compat.v1.GraphKeys.ASSET_FILEPATHS, |
| 58 | asset_tensor) |
| 59 | saved_model_lib.add_signature("default", {}, {"default": asset_tensor}) |
| 60 | |
| 61 | handler = saved_model_lib.SavedModelHandler() |
| 62 | handler.add_graph_copy(graph) |
| 63 | |
| 64 | export_dir = os.path.join(self.get_temp_dir(), "exported") |
| 65 | handler.export(export_dir) |
| 66 | |
| 67 | # Check that asset file got written to the expected place: |
| 68 | exported_asset_file = os.path.join(export_dir, "assets", "hello.txt") |
| 69 | self.assertTrue(tf.compat.v1.gfile.Exists(exported_asset_file)) |
| 70 | |
| 71 | loaded_handler = saved_model_lib.load(export_dir) |
| 72 | with _instantiate_meta_graph(loaded_handler).as_default(): |
| 73 | with tf.compat.v1.Session() as sess: |
| 74 | self.assertEqual(sess.run("file:0"), |
| 75 | tf.compat.as_bytes(exported_asset_file)) |
| 76 | |
| 77 | def testWithMultipleAssetsWithSameBasename(self): |
| 78 | tmp_asset_dir = os.path.join(self.get_temp_dir(), "asset") |
nothing calls this directly
no test coverage detected