def scan_meta_graph_def(meta_graph_def): """Scans meta_graph_def and reports if there are ops on blacklist. Print ops if they are on black list, or print success if no blacklisted ops found. Args: meta_graph_def: MetaGraphDef protocol buffer. """ all_ops_set = set( meta_graph_lib.ops_used_by_graph_def(meta_graph_def.graph_def)) blacklisted_ops = _OP_BLACKLIST & all_ops_set if blacklisted_ops: # TODO(yifeif): print more warnings print( 'MetaGraph with tag set %s contains the following blacklisted ops:' % meta_graph_def.meta_info_def.tags, blacklisted_ops) else: print('MetaGraph with tag set %s does not contain blacklisted ops.' % meta_graph_def.meta_info_def.tags)
def scan_meta_graph_def(meta_graph_def): """Scans meta_graph_def and reports if there are ops on blacklist. Print ops if they are on black list, or print success if no blacklisted ops found. Args: meta_graph_def: MetaGraphDef protocol buffer. """ all_ops_set = set( meta_graph_lib.ops_used_by_graph_def(meta_graph_def.graph_def)) blacklisted_ops = _OP_BLACKLIST & all_ops_set if blacklisted_ops: # TODO(yifeif): print more warnings print('MetaGraph with tag set %s contains the following blacklisted ops:' % meta_graph_def.meta_info_def.tags, blacklisted_ops) else: print('MetaGraph with tag set %s does not contain blacklisted ops.' % meta_graph_def.meta_info_def.tags)
def _verify_ops(graph_def, namespace_whitelist): """Verifies that all namespaced ops in the graph are whitelisted.""" invalid_ops = [] invalid_namespaces = set() all_operations = [] all_operations.extend(meta_graph.ops_used_by_graph_def(graph_def)) for op in all_operations: if ">" in op: namespace = op.split(">")[0] if namespace not in namespace_whitelist: invalid_ops.append(op) invalid_namespaces.add(namespace) if invalid_ops: raise ValueError( "Attempted to save ops from non-whitelisted namespaces to SavedModel: " "{}.\nPlease verify that these ops should be saved, since they must be " "available when loading the SavedModel. If loading from Python, you " "must import the library defining these ops. From C++, link the custom " "ops to the serving binary. Once you've confirmed this, please add the " "following namespaces to the `namespace_whitelist` argument in " "tf.saved_model.SaveOptions: {}.".format( invalid_ops, invalid_namespaces))