本文整理匯總了Python中tensorflow.python.pywrap_tensorflow.TryFindKernelClass方法的典型用法代碼示例。如果您正苦於以下問題:Python pywrap_tensorflow.TryFindKernelClass方法的具體用法?Python pywrap_tensorflow.TryFindKernelClass怎麽用?Python pywrap_tensorflow.TryFindKernelClass使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類tensorflow.python.pywrap_tensorflow
的用法示例。
在下文中一共展示了pywrap_tensorflow.TryFindKernelClass方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: get_ops_and_kernels
# 需要導入模塊: from tensorflow.python import pywrap_tensorflow [as 別名]
# 或者: from tensorflow.python.pywrap_tensorflow import TryFindKernelClass [as 別名]
def get_ops_and_kernels(proto_fileformat, proto_files, default_ops_str):
"""Gets the ops and kernels needed from the model files."""
ops = set()
for proto_file in proto_files:
tf_logging.info('Loading proto file %s', proto_file)
# Load GraphDef.
file_data = gfile.GFile(proto_file, 'rb').read()
if proto_fileformat == 'rawproto':
graph_def = graph_pb2.GraphDef.FromString(file_data)
else:
assert proto_fileformat == 'textproto'
graph_def = text_format.Parse(file_data, graph_pb2.GraphDef())
# Find all ops and kernels used by the graph.
for node_def in graph_def.node:
if not node_def.device:
node_def.device = '/cpu:0'
kernel_class = pywrap_tensorflow.TryFindKernelClass(
node_def.SerializeToString())
if kernel_class:
op_and_kernel = (str(node_def.op), kernel_class.decode('utf-8'))
if op_and_kernel not in ops:
ops.add(op_and_kernel)
else:
print(
'Warning: no kernel found for op %s' % node_def.op, file=sys.stderr)
# Add default ops.
if default_ops_str and default_ops_str != 'all':
for s in default_ops_str.split(','):
op, kernel = s.split(':')
op_and_kernel = (op, kernel)
if op_and_kernel not in ops:
ops.add(op_and_kernel)
return list(sorted(ops))
示例2: get_ops_and_kernels
# 需要導入模塊: from tensorflow.python import pywrap_tensorflow [as 別名]
# 或者: from tensorflow.python.pywrap_tensorflow import TryFindKernelClass [as 別名]
def get_ops_and_kernels(proto_fileformat, proto_files, default_ops_str):
"""Gets the ops and kernels needed from the model files."""
ops = set()
for proto_file in proto_files:
tf_logging.info('Loading proto file %s', proto_file)
# Load GraphDef.
file_data = gfile.GFile(proto_file).read()
if proto_fileformat == 'rawproto':
graph_def = graph_pb2.GraphDef.FromString(file_data)
else:
assert proto_fileformat == 'textproto'
graph_def = text_format.Parse(file_data, graph_pb2.GraphDef())
# Find all ops and kernels used by the graph.
for node_def in graph_def.node:
if not node_def.device:
node_def.device = '/cpu:0'
kernel_class = pywrap_tensorflow.TryFindKernelClass(
node_def.SerializeToString())
if kernel_class:
op_and_kernel = (str(node_def.op), kernel_class.decode('utf-8'))
if op_and_kernel not in ops:
ops.add(op_and_kernel)
else:
print(
'Warning: no kernel found for op %s' % node_def.op, file=sys.stderr)
# Add default ops.
if default_ops_str != 'all':
for s in default_ops_str.split(','):
op, kernel = s.split(':')
op_and_kernel = (op, kernel)
if op_and_kernel not in ops:
ops.add(op_and_kernel)
return list(sorted(ops))
示例3: get_ops_and_kernels
# 需要導入模塊: from tensorflow.python import pywrap_tensorflow [as 別名]
# 或者: from tensorflow.python.pywrap_tensorflow import TryFindKernelClass [as 別名]
def get_ops_and_kernels(proto_fileformat, proto_files, default_ops_str):
"""Gets the ops and kernels needed from the model files."""
ops = set()
for proto_file in proto_files:
tf.logging.info('Loading proto file %s', proto_file)
# Load GraphDef.
file_data = tf.gfile.GFile(proto_file).read()
if proto_fileformat == 'rawproto':
graph_def = graph_pb2.GraphDef.FromString(file_data)
else:
assert proto_fileformat == 'textproto'
graph_def = text_format.Parse(file_data, graph_pb2.GraphDef())
# Find all ops and kernels used by the graph.
for node_def in graph_def.node:
if not node_def.device:
node_def.device = '/cpu:0'
kernel_class = pywrap_tensorflow.TryFindKernelClass(
node_def.SerializeToString())
if kernel_class:
op_and_kernel = (str(node_def.op), kernel_class.decode('utf-8'))
if op_and_kernel not in ops:
ops.add(op_and_kernel)
else:
print(
'Warning: no kernel found for op %s' % node_def.op, file=sys.stderr)
# Add default ops.
if default_ops_str != 'all':
for s in default_ops_str.split(','):
op, kernel = s.split(':')
op_and_kernel = (op, kernel)
if op_and_kernel not in ops:
ops.add(op_and_kernel)
return list(sorted(ops))