Beispiel #1
0
    def testConvertSignaturesToSignatureDefs(self):
        base_path = tf.test.test_src_dir_path(SESSION_BUNDLE_PATH)
        meta_graph_filename = os.path.join(base_path,
                                           constants.META_GRAPH_DEF_FILENAME)
        metagraph_def = meta_graph.read_meta_graph_file(meta_graph_filename)
        default_signature_def, named_signature_def = (
            bundle_shim._convert_signatures_to_signature_defs(metagraph_def))
        self.assertEqual(default_signature_def.method_name,
                         signature_constants.REGRESS_METHOD_NAME)
        self.assertEqual(len(default_signature_def.inputs), 1)
        self.assertEqual(len(default_signature_def.outputs), 1)
        self.assertProtoEquals(
            default_signature_def.inputs[signature_constants.REGRESS_INPUTS],
            meta_graph_pb2.TensorInfo(name="tf_example:0"))
        self.assertProtoEquals(
            default_signature_def.outputs[signature_constants.REGRESS_OUTPUTS],
            meta_graph_pb2.TensorInfo(name="Identity:0"))
        self.assertEqual(named_signature_def.method_name,
                         signature_constants.PREDICT_METHOD_NAME)
        self.assertEqual(len(named_signature_def.inputs), 1)
        self.assertEqual(len(named_signature_def.outputs), 1)
        self.assertProtoEquals(named_signature_def.inputs["x"],
                               meta_graph_pb2.TensorInfo(name="x:0"))
        self.assertProtoEquals(named_signature_def.outputs["y"],
                               meta_graph_pb2.TensorInfo(name="y:0"))

        # Now try default signature only
        collection_def = metagraph_def.collection_def
        signatures_proto = manifest_pb2.Signatures()
        signatures = collection_def[constants.SIGNATURES_KEY].any_list.value[0]
        signatures.Unpack(signatures_proto)
        named_only_signatures_proto = manifest_pb2.Signatures()
        named_only_signatures_proto.CopyFrom(signatures_proto)

        default_only_signatures_proto = manifest_pb2.Signatures()
        default_only_signatures_proto.CopyFrom(signatures_proto)
        default_only_signatures_proto.named_signatures.clear()
        default_only_signatures_proto.ClearField("named_signatures")
        metagraph_def.collection_def[constants.SIGNATURES_KEY].any_list.value[
            0].Pack(default_only_signatures_proto)
        default_signature_def, named_signature_def = (
            bundle_shim._convert_signatures_to_signature_defs(metagraph_def))
        self.assertEqual(default_signature_def.method_name,
                         signature_constants.REGRESS_METHOD_NAME)
        self.assertEqual(named_signature_def, None)

        named_only_signatures_proto.ClearField("default_signature")
        metagraph_def.collection_def[constants.SIGNATURES_KEY].any_list.value[
            0].Pack(named_only_signatures_proto)
        default_signature_def, named_signature_def = (
            bundle_shim._convert_signatures_to_signature_defs(metagraph_def))
        self.assertEqual(named_signature_def.method_name,
                         signature_constants.PREDICT_METHOD_NAME)
        self.assertEqual(default_signature_def, None)
    def testBasic(self):
        base_path = test.test_src_dir_path(SESSION_BUNDLE_PATH)
        ops.reset_default_graph()
        sess, meta_graph_def = session_bundle.load_session_bundle_from_path(
            base_path,
            target="",
            config=config_pb2.ConfigProto(device_count={"CPU": 2}))

        self.assertTrue(sess)
        asset_path = os.path.join(base_path, constants.ASSETS_DIRECTORY)
        with sess.as_default():
            path1, path2 = sess.run(["filename1:0", "filename2:0"])
            self.assertEqual(
                compat.as_bytes(os.path.join(asset_path, "hello1.txt")), path1)
            self.assertEqual(
                compat.as_bytes(os.path.join(asset_path, "hello2.txt")), path2)

            collection_def = meta_graph_def.collection_def

            signatures_any = collection_def[
                constants.SIGNATURES_KEY].any_list.value
            self.assertEquals(len(signatures_any), 1)

            signatures = manifest_pb2.Signatures()
            signatures_any[0].Unpack(signatures)
            self._checkRegressionSignature(signatures, sess)
            self._checkNamedSignatures(signatures, sess)
Beispiel #3
0
def _convert_signatures_to_signature_defs(metagraph_def):
  """Produce default and named upconverted SignatureDef objects from Signatures.

  Args:
    metagraph_def: object of type meta_graph_pb2.MetaGraphDef containing legacy
    format Session Bundle signatures

  Returns:
    default_signature_def: object of type SignatureDef which contains an
        upconverted version of default signatures in metagraph_def
    named_signature_def: object of type SignatureDef which contains an
        upconverted version of named signatures in metagraph_def
  """

  collection_def = metagraph_def.collection_def
  signatures_proto = manifest_pb2.Signatures()
  signatures = collection_def[legacy_constants.SIGNATURES_KEY].any_list.value[0]
  signatures.Unpack(signatures_proto)

  default_signature_def = None
  named_signature_def = None
  if signatures_proto.HasField("default_signature"):
    default_signature_def = _convert_default_signature_to_signature_def(
        signatures_proto)
  if len(signatures_proto.named_signatures) > 1:
    named_signature_def = _convert_named_signatures_to_signature_def(
        signatures_proto)
  return default_signature_def, named_signature_def
Beispiel #4
0
def load_from_file():
    sess, meta_graph_def = session_bundle.LoadSessionBundleFromPath("/tmp/fam/00000001") 

    with sess.as_default():

        test_i, test_o = getdata(range(1), [3], process) 
        collection_def = meta_graph_def.collection_def
        signatures_any = collection_def[constants.SIGNATURES_KEY].any_list.value
        signatures = manifest_pb2.Signatures()
        signatures_any[0].Unpack(signatures)
        default_signature = signatures.default_signature

        input_name = default_signature.classification_signature.input.tensor_name
        output_name = default_signature.classification_signature.scores.tensor_name
    
        for s in range(len(test_i)):

            gd = 0
            z = 0
            allv = test_i[s]

            if len(allv) > 0:

                for v in allv:
                    if np.argmax(sess.run ([output_name],{input_name: [ v ]})[0]) == np.argmax(test_o[s][z]):
                        gd += 1
                    z = z + 1

                print ("SNR",SNR[s],"ACC",gd/z)
Beispiel #5
0
    def testConvertNamedSignatureToSignatureDef(self):
        signatures_proto = manifest_pb2.Signatures()
        generic_signature = manifest_pb2.GenericSignature()
        generic_signature.map["input_key"].CopyFrom(
            manifest_pb2.TensorBinding(tensor_name="input"))
        signatures_proto.named_signatures[
            signature_constants.PREDICT_INPUTS].generic_signature.CopyFrom(
                generic_signature)

        generic_signature = manifest_pb2.GenericSignature()
        generic_signature.map["output_key"].CopyFrom(
            manifest_pb2.TensorBinding(tensor_name="output"))
        signatures_proto.named_signatures[
            signature_constants.PREDICT_OUTPUTS].generic_signature.CopyFrom(
                generic_signature)
        signature_def = bundle_shim._convert_named_signatures_to_signature_def(
            signatures_proto)
        self.assertEqual(signature_def.method_name,
                         signature_constants.PREDICT_METHOD_NAME)
        self.assertEqual(len(signature_def.inputs), 1)
        self.assertEqual(len(signature_def.outputs), 1)
        self.assertProtoEquals(signature_def.inputs["input_key"],
                               meta_graph_pb2.TensorInfo(name="input"))
        self.assertProtoEquals(signature_def.outputs["output_key"],
                               meta_graph_pb2.TensorInfo(name="output"))
Beispiel #6
0
    def testConvertDefaultSignatureRegressionToSignatureDef(self):
        signatures_proto = manifest_pb2.Signatures()
        regression_signature = manifest_pb2.RegressionSignature()
        regression_signature.input.CopyFrom(
            manifest_pb2.TensorBinding(
                tensor_name=signature_constants.REGRESS_INPUTS))
        regression_signature.output.CopyFrom(
            manifest_pb2.TensorBinding(
                tensor_name=signature_constants.REGRESS_OUTPUTS))
        signatures_proto.default_signature.regression_signature.CopyFrom(
            regression_signature)
        signature_def = bundle_shim._convert_default_signature_to_signature_def(
            signatures_proto)

        # Validate regression signature correctly copied over.
        self.assertEqual(signature_def.method_name,
                         signature_constants.REGRESS_METHOD_NAME)
        self.assertEqual(len(signature_def.inputs), 1)
        self.assertEqual(len(signature_def.outputs), 1)
        self.assertProtoEquals(
            signature_def.inputs[signature_constants.REGRESS_INPUTS],
            meta_graph_pb2.TensorInfo(name=signature_constants.REGRESS_INPUTS))
        self.assertProtoEquals(
            signature_def.outputs[signature_constants.REGRESS_OUTPUTS],
            meta_graph_pb2.TensorInfo(
                name=signature_constants.REGRESS_OUTPUTS))
Beispiel #7
0
 def testConvertDefaultSignatureBadTypeToSignatureDef(self):
     signatures_proto = manifest_pb2.Signatures()
     generic_signature = manifest_pb2.GenericSignature()
     signatures_proto.default_signature.generic_signature.CopyFrom(
         generic_signature)
     with self.assertRaises(RuntimeError) as cm:
         _ = bundle_shim._convert_default_signature_to_signature_def(
             signatures_proto)
Beispiel #8
0
 def testConvertDefaultSignatureGenericToSignatureDef(self):
     signatures_proto = manifest_pb2.Signatures()
     generic_signature = manifest_pb2.GenericSignature()
     signatures_proto.default_signature.generic_signature.CopyFrom(
         generic_signature)
     signature_def = bundle_shim._convert_default_signature_to_signature_def(
         signatures_proto)
     self.assertEquals(signature_def, None)
 def testConvertNamedSignatureNonGenericToSignatureDef(self):
   signatures_proto = manifest_pb2.Signatures()
   regression_signature = manifest_pb2.RegressionSignature()
   signatures_proto.named_signatures[
       signature_constants.PREDICT_INPUTS].regression_signature.CopyFrom(
           regression_signature)
   with self.assertRaises(RuntimeError):
     _ = bundle_shim._convert_named_signatures_to_signature_def(
         signatures_proto)
   signatures_proto = manifest_pb2.Signatures()
   classification_signature = manifest_pb2.ClassificationSignature()
   signatures_proto.named_signatures[
       signature_constants.PREDICT_INPUTS].classification_signature.CopyFrom(
           classification_signature)
   with self.assertRaises(RuntimeError):
     _ = bundle_shim._convert_named_signatures_to_signature_def(
         signatures_proto)
def read_serving_signatures(meta_file):
    tf.reset_default_graph()
    with tf.Session() as sess:
        new_saver = tf.train.import_meta_graph(meta_file)
 
        graph = tf.get_default_graph()
        pb = graph.get_collection("serving_signatures")[0]
        signatures = manifest_pb2.Signatures()
        pb.Unpack(signatures)
        
        return signatures
Beispiel #11
0
  def _get_default_signature(self, export_meta_filename):
    """Gets the default signature from the export.meta file."""
    with tf.Session():
      save = tf.train.import_meta_graph(export_meta_filename)
      meta_graph_def = save.export_meta_graph()
      collection_def = meta_graph_def.collection_def

      signatures_any = collection_def['serving_signatures'].any_list.value
      self.assertEquals(len(signatures_any), 1)
      signatures = manifest_pb2.Signatures()
      signatures_any[0].Unpack(signatures)
      default_signature = signatures.default_signature
      return default_signature
Beispiel #12
0
def load_graph(output_graph_path):

    #sess, meta_graph_def = session_bundle.load_session_bundle_from_path(output_graph_path)
    sess, meta_graph_def = bundle_shim.load_session_bundle_or_saved_model_bundle_from_path(
        output_graph_path)

    with sess.as_default():
        collection_def = meta_graph_def.collection_def
        signatures_any = collection_def[
            constants.SIGNATURES_KEY].any_list.value
        signatures = manifest_pb2.Signatures()
        signatures_any[0].Unpack(signatures)
        default_signature = signatures.default_signature
        input_name = default_signature.classification_signature.input.tensor_name
        output_name = default_signature.classification_signature.scores.tensor_name
        classes = default_signature.classification_signature.classes.tensor_name
        classes = sess.run(sess.graph.get_tensor_by_name(classes))
        return (sess, input_name, output_name, classes)
Beispiel #13
0
    def testConvertDefaultSignatureClassificationToSignatureDef(self):
        signatures_proto = manifest_pb2.Signatures()
        classification_signature = manifest_pb2.ClassificationSignature()
        classification_signature.input.CopyFrom(
            manifest_pb2.TensorBinding(
                tensor_name=signature_constants.CLASSIFY_INPUTS))
        classification_signature.classes.CopyFrom(
            manifest_pb2.TensorBinding(
                tensor_name=signature_constants.CLASSIFY_OUTPUT_CLASSES))
        classification_signature.scores.CopyFrom(
            manifest_pb2.TensorBinding(
                tensor_name=signature_constants.CLASSIFY_OUTPUT_SCORES))
        signatures_proto.default_signature.classification_signature.CopyFrom(
            classification_signature)

        signatures_proto.default_signature.classification_signature.CopyFrom(
            classification_signature)
        signature_def = bundle_shim._convert_default_signature_to_signature_def(
            signatures_proto)

        # Validate classification signature correctly copied over.
        self.assertEqual(signature_def.method_name,
                         signature_constants.CLASSIFY_METHOD_NAME)
        self.assertEqual(len(signature_def.inputs), 1)
        self.assertEqual(len(signature_def.outputs), 2)
        self.assertProtoEquals(
            signature_def.inputs[signature_constants.CLASSIFY_INPUTS],
            meta_graph_pb2.TensorInfo(
                name=signature_constants.CLASSIFY_INPUTS))
        self.assertProtoEquals(
            signature_def.outputs[signature_constants.CLASSIFY_OUTPUT_SCORES],
            meta_graph_pb2.TensorInfo(
                name=signature_constants.CLASSIFY_OUTPUT_SCORES))
        self.assertProtoEquals(
            signature_def.outputs[signature_constants.CLASSIFY_OUTPUT_CLASSES],
            meta_graph_pb2.TensorInfo(
                name=signature_constants.CLASSIFY_OUTPUT_CLASSES))
    def testBasic(self):
        base_path = tf.test.test_src_dir_path(
            "contrib/session_bundle/example/half_plus_two/00000123")
        tf.reset_default_graph()
        sess, meta_graph_def = session_bundle.load_session_bundle_from_path(
            base_path,
            target="",
            config=tf.ConfigProto(device_count={"CPU": 2}))

        self.assertTrue(sess)
        asset_path = os.path.join(base_path, constants.ASSETS_DIRECTORY)
        with sess.as_default():
            path1, path2 = sess.run(["filename1:0", "filename2:0"])
            self.assertEqual(
                compat.as_bytes(os.path.join(asset_path, "hello1.txt")), path1)
            self.assertEqual(
                compat.as_bytes(os.path.join(asset_path, "hello2.txt")), path2)

            collection_def = meta_graph_def.collection_def

            signatures_any = collection_def[
                constants.SIGNATURES_KEY].any_list.value
            self.assertEquals(len(signatures_any), 1)

            signatures = manifest_pb2.Signatures()
            signatures_any[0].Unpack(signatures)
            default_signature = signatures.default_signature
            input_name = default_signature.regression_signature.input.tensor_name
            output_name = default_signature.regression_signature.output.tensor_name
            y = sess.run([output_name],
                         {input_name: np.array([[0], [1], [2], [3]])})
            # The operation is y = 0.5 * x + 2
            self.assertEqual(y[0][0], 2)
            self.assertEqual(y[0][1], 2.5)
            self.assertEqual(y[0][2], 3)
            self.assertEqual(y[0][3], 3.5)
Beispiel #15
0
    def doBasicsOneExportPath(self,
                              export_path,
                              clear_devices=False,
                              global_step=GLOBAL_STEP,
                              sharded=True):
        # Build a graph with 2 parameter nodes on different devices.
        tf.reset_default_graph()
        with tf.Session(target="",
                        config=config_pb2.ConfigProto(
                            device_count={"CPU": 2})) as sess:
            # v2 is an unsaved variable derived from v0 and v1.  It is used to
            # exercise the ability to run an init op when restoring a graph.
            with sess.graph.device("/cpu:0"):
                v0 = tf.Variable(10, name="v0")
            with sess.graph.device("/cpu:1"):
                v1 = tf.Variable(20, name="v1")
            v2 = tf.Variable(1, name="v2", trainable=False, collections=[])
            assign_v2 = tf.assign(v2, tf.add(v0, v1))
            init_op = tf.group(assign_v2, name="init_op")

            tf.add_to_collection("v", v0)
            tf.add_to_collection("v", v1)
            tf.add_to_collection("v", v2)

            global_step_tensor = tf.Variable(global_step, name="global_step")
            named_tensor_bindings = {
                "logical_input_A": v0,
                "logical_input_B": v1
            }
            signatures = {
                "foo":
                exporter.regression_signature(input_tensor=v0,
                                              output_tensor=v1),
                "generic":
                exporter.generic_signature(named_tensor_bindings)
            }

            asset_filepath_orig = os.path.join(tf.test.get_temp_dir(),
                                               "hello42.txt")
            asset_file = tf.constant(asset_filepath_orig, name="filename42")
            tf.add_to_collection(tf.GraphKeys.ASSET_FILEPATHS, asset_file)

            with gfile.FastGFile(asset_filepath_orig, "w") as f:
                f.write("your data here")
            assets_collection = tf.get_collection(tf.GraphKeys.ASSET_FILEPATHS)

            ignored_asset = os.path.join(tf.test.get_temp_dir(), "ignored.txt")
            with gfile.FastGFile(ignored_asset, "w") as f:
                f.write("additional data here")

            tf.initialize_all_variables().run()

            # Run an export.
            save = tf.train.Saver({
                "v0": v0,
                "v1": v1
            },
                                  restore_sequentially=True,
                                  sharded=sharded)
            export = exporter.Exporter(save)
            export.init(
                sess.graph.as_graph_def(),
                init_op=init_op,
                clear_devices=clear_devices,
                default_graph_signature=exporter.classification_signature(
                    input_tensor=v0),
                named_graph_signatures=signatures,
                assets_collection=assets_collection)
            export.export(export_path,
                          global_step_tensor,
                          sess,
                          exports_to_keep=gc.largest_export_versions(2))

        # Restore graph.
        compare_def = tf.get_default_graph().as_graph_def()
        tf.reset_default_graph()
        with tf.Session(target="",
                        config=config_pb2.ConfigProto(
                            device_count={"CPU": 2})) as sess:
            save = tf.train.import_meta_graph(
                os.path.join(export_path,
                             constants.VERSION_FORMAT_SPECIFIER % global_step,
                             constants.META_GRAPH_DEF_FILENAME))
            self.assertIsNotNone(save)
            meta_graph_def = save.export_meta_graph()
            collection_def = meta_graph_def.collection_def

            # Validate custom graph_def.
            graph_def_any = collection_def[constants.GRAPH_KEY].any_list.value
            self.assertEquals(len(graph_def_any), 1)
            graph_def = tf.GraphDef()
            graph_def_any[0].Unpack(graph_def)
            if clear_devices:
                for node in compare_def.node:
                    node.device = ""
            self.assertProtoEquals(compare_def, graph_def)

            # Validate init_op.
            init_ops = collection_def[constants.INIT_OP_KEY].node_list.value
            self.assertEquals(len(init_ops), 1)
            self.assertEquals(init_ops[0], "init_op")

            # Validate signatures.
            signatures_any = collection_def[
                constants.SIGNATURES_KEY].any_list.value
            self.assertEquals(len(signatures_any), 1)
            signatures = manifest_pb2.Signatures()
            signatures_any[0].Unpack(signatures)
            default_signature = signatures.default_signature
            self.assertEqual(
                default_signature.classification_signature.input.tensor_name,
                "v0:0")
            bindings = signatures.named_signatures[
                "generic"].generic_signature.map
            self.assertEquals(bindings["logical_input_A"].tensor_name, "v0:0")
            self.assertEquals(bindings["logical_input_B"].tensor_name, "v1:0")
            read_foo_signature = (
                signatures.named_signatures["foo"].regression_signature)
            self.assertEquals(read_foo_signature.input.tensor_name, "v0:0")
            self.assertEquals(read_foo_signature.output.tensor_name, "v1:0")

            # Validate the assets.
            assets_any = collection_def[constants.ASSETS_KEY].any_list.value
            self.assertEquals(len(assets_any), 1)
            asset = manifest_pb2.AssetFile()
            assets_any[0].Unpack(asset)
            assets_path = os.path.join(
                export_path, constants.VERSION_FORMAT_SPECIFIER % global_step,
                constants.ASSETS_DIRECTORY, "hello42.txt")
            asset_contents = gfile.GFile(assets_path).read()
            self.assertEqual(asset_contents, "your data here")
            self.assertEquals("hello42.txt", asset.filename)
            self.assertEquals("filename42:0", asset.tensor_binding.tensor_name)
            ignored_asset_path = os.path.join(
                export_path, constants.VERSION_FORMAT_SPECIFIER % global_step,
                constants.ASSETS_DIRECTORY, "ignored.txt")
            self.assertFalse(gfile.Exists(ignored_asset_path))

            # Validate graph restoration.
            if sharded:
                save.restore(
                    sess,
                    os.path.join(
                        export_path,
                        constants.VERSION_FORMAT_SPECIFIER % global_step,
                        constants.VARIABLES_FILENAME_PATTERN))
            else:
                save.restore(
                    sess,
                    os.path.join(
                        export_path,
                        constants.VERSION_FORMAT_SPECIFIER % global_step,
                        constants.VARIABLES_FILENAME))
            self.assertEqual(10, tf.get_collection("v")[0].eval())
            self.assertEqual(20, tf.get_collection("v")[1].eval())
            tf.get_collection(constants.INIT_OP_KEY)[0].run()
            self.assertEqual(30, tf.get_collection("v")[2].eval())
Beispiel #16
0
  def init(self,
           graph_def=None,
           init_op=None,
           clear_devices=False,
           default_graph_signature=None,
           named_graph_signatures=None,
           assets_collection=None,
           assets_callback=gfile_copy_callback):
    """Initialization.

    Args:
      graph_def: A GraphDef message of the graph to be used in inference.
        GraphDef of default graph is used when None.
      init_op: Op to be used in initialization.
      clear_devices: If device info of the graph should be cleared upon export.
      default_graph_signature: Default signature of the graph.
      named_graph_signatures: Map of named input/output signatures of the graph.
      assets_collection: A collection of constant asset filepath tensors. If set
        the assets will be exported into the asset directory.
      assets_callback: callback with two argument called during export with the
        list of files to copy and the asset path.
    Raises:
      RuntimeError: if init is called more than once.
      TypeError: if init_op is not an Operation or None.
      ValueError: if asset file path tensors are not non-empty constant string
        scalar tensors.
    """
    # Avoid Dangerous default value []
    if named_graph_signatures is None:
      named_graph_signatures = {}
    assets = []
    if assets_collection:
      for asset_tensor in assets_collection:
        asset_filepath = self._file_path_value(asset_tensor)
        if not asset_filepath:
          raise ValueError("invalid asset filepath tensor %s" % asset_tensor)
        basename = os.path.basename(asset_filepath)
        assets.append((basename, asset_tensor))
        self._assets_to_copy[asset_filepath] = basename

    if self._has_init:
      raise RuntimeError("init should be called only once")
    self._has_init = True

    if graph_def or clear_devices:
      copy = graph_pb2.GraphDef()
      if graph_def:
        copy.CopyFrom(graph_def)
      else:
        copy.CopyFrom(ops.get_default_graph().as_graph_def())
      if clear_devices:
        for node in copy.node:
          node.device = ""
      graph_any_buf = Any()
      graph_any_buf.Pack(copy)
      ops.add_to_collection(constants.GRAPH_KEY, graph_any_buf)

    if init_op:
      if not isinstance(init_op, ops.Operation):
        raise TypeError("init_op needs to be an Operation: %s" % init_op)
      ops.add_to_collection(constants.INIT_OP_KEY, init_op)

    signatures_proto = manifest_pb2.Signatures()
    if default_graph_signature:
      signatures_proto.default_signature.CopyFrom(default_graph_signature)
    for signature_name, signature in six.iteritems(named_graph_signatures):
      signatures_proto.named_signatures[signature_name].CopyFrom(signature)
    signatures_any_buf = Any()
    signatures_any_buf.Pack(signatures_proto)
    ops.add_to_collection(constants.SIGNATURES_KEY, signatures_any_buf)

    for filename, tensor in assets:
      asset = manifest_pb2.AssetFile()
      asset.filename = filename
      asset.tensor_binding.tensor_name = tensor.name
      asset_any_buf = Any()
      asset_any_buf.Pack(asset)
      ops.add_to_collection(constants.ASSETS_KEY, asset_any_buf)

    self._assets_callback = assets_callback