本文整理汇总了Python中tensorflow.python.eager.execute.execute函数的典型用法代码示例。如果您正苦于以下问题:Python execute函数的具体用法?Python execute怎么用?Python execute使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了execute函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testExecuteListTypeListShapeAttr
def testExecuteListTypeListShapeAttr(self):
execute.execute(
'Barrier',
num_outputs=1,
inputs=[],
attrs=('component_types', [dtypes.float64.as_datatype_enum], 'shapes',
[[1, 2]], 'capacity', -1, 'container', '', 'shared_name', ''))
示例2: testExecuteListFloatAttrBadValue
def testExecuteListFloatAttrBadValue(self):
with self.assertRaises(errors.InvalidArgumentError):
execute.execute(
'Bucketize',
num_outputs=1,
inputs=[tensor.Tensor([3.0, 5.0, 7.0])],
attrs=('T', dtypes.float32.as_datatype_enum, 'boundaries', 4.0))
示例3: testExecuteListIntAttrBadValue
def testExecuteListIntAttrBadValue(self):
with self.assertRaises(errors.InvalidArgumentError):
execute.execute(
'Squeeze',
num_outputs=1,
inputs=[tensor.Tensor([[[3.0]]])],
attrs=('T', dtypes.float32.as_datatype_enum, 'squeeze_dims', 0))
示例4: testExecuteShapeAttr
def testExecuteShapeAttr(self):
execute.execute(
'VarHandleOp',
num_outputs=1,
inputs=[],
attrs=('shape', [1, 2], 'dtype', dtypes.int32.as_datatype_enum,
'container', '', 'shared_name', ''))
示例5: testExecuteUnknownAttr
def testExecuteUnknownAttr(self):
with self.assertRaises(errors.InvalidArgumentError):
execute.execute(
'Identity',
num_outputs=1,
inputs=[tensor.Tensor(3)],
attrs=('T', dtypes.int32.as_datatype_enum, 'unknown_attr', 'blah'))
示例6: testExecuteListTypeAttrBadListValue
def testExecuteListTypeAttrBadListValue(self):
with self.assertRaises(errors.InvalidArgumentError):
execute.execute(
b'Barrier',
num_outputs=1,
inputs=[],
attrs=('component_types', '1', 'shapes', [[1, 2]], 'capacity', -1,
'container', '', 'shared_name', ''))
示例7: testExecuteListIntAttrBadListValue
def testExecuteListIntAttrBadListValue(self):
with self.assertRaises(errors.InvalidArgumentError):
execute.execute(
b'Squeeze',
num_outputs=1,
inputs=[constant_op.constant([[[3.0]]])],
attrs=('T', dtypes.float32.as_datatype_enum, 'squeeze_dims',
['0', '2']))
示例8: testExecuteListFloatAttrBadListValue
def testExecuteListFloatAttrBadListValue(self):
with self.assertRaises(errors.InvalidArgumentError):
execute.execute(
b'Bucketize',
num_outputs=1,
inputs=[constant_op.constant([3.0, 5.0, 7.0])],
attrs=('T', dtypes.float32.as_datatype_enum, 'boundaries',
['4.0', '6.0']))
示例9: testExecuteListShapeAttrBadListValue
def testExecuteListShapeAttrBadListValue(self):
with self.assertRaises(errors.InvalidArgumentError):
execute.execute(
'Barrier',
num_outputs=1,
inputs=[],
attrs=('component_types', [dtypes.float64.as_datatype_enum], 'shapes',
[1], 'capacity', -1, 'container', '', 'shared_name', ''))
示例10: testExecuteListStringAttrBadListValue
def testExecuteListStringAttrBadListValue(self):
with self.assertRaises(errors.InvalidArgumentError):
execute.execute(
'TensorSummary',
num_outputs=1,
inputs=[tensor.Tensor(3.0)],
attrs=('T', dtypes.float32.as_datatype_enum, 'description', '',
'labels', [3], 'display_name', 'test'))
示例11: testExecuteListStringAttr
def testExecuteListStringAttr(self):
execute.execute(
'TensorSummary',
num_outputs=1,
inputs=[tensor.Tensor(3.0)],
attrs=('T', dtypes.float32.as_datatype_enum, 'description',
'tensor_summary', 'labels', ['3',
'summary'], 'display_name', 'test'))
示例12: testExecuteShapeAttrBadValue
def testExecuteShapeAttrBadValue(self):
with self.assertRaises(errors.InvalidArgumentError):
execute.execute(
'VarHandleOp',
num_outputs=1,
inputs=[],
attrs=('shape', 1, 'dtype', dtypes.int32.as_datatype_enum,
'container', '', 'shared_name', ''))
示例13: testOperationWithNoInputsRunsOnDevice
def testOperationWithNoInputsRunsOnDevice(self):
if not context.context().num_gpus():
self.skipTest('No GPUs found')
shape = tensor.Tensor([], dtype=dtypes.int32)
# x: Run the "TruncatedNormal" op CPU and copy result to GPU.
x = truncated_normal(shape).as_gpu_tensor()
# y: Explicitly run the "TruncatedNormal" op on GPU.
with context.device('gpu:0'):
y = truncated_normal(shape)
# Add would fail if x and y were not on the same device.
execute.execute(
'Add', 1, inputs=[x, y], attrs=('T', x.dtype.as_datatype_enum))
示例14: xla_launch_eager_fallback
def xla_launch_eager_fallback(constants, args, resources, Tresults, function, name=None, ctx=None):
r"""This is the slowpath function for Eager mode.
This is for function xla_launch
"""
_ctx = ctx if ctx else _context.context()
if not isinstance(resources, (list, tuple)):
raise TypeError(
"Expected list for 'resources' argument to "
"'xla_launch' Op, not %r." % resources)
_attr_Nresources = len(resources)
if not isinstance(Tresults, (list, tuple)):
raise TypeError(
"Expected list for 'Tresults' argument to "
"'xla_launch' Op, not %r." % Tresults)
Tresults = [_execute.make_type(_t, "Tresults") for _t in Tresults]
_attr_Tconstants, constants = _execute.convert_to_mixed_eager_tensors(constants, _ctx)
_attr_Targs, args = _execute.convert_to_mixed_eager_tensors(args, _ctx)
resources = _ops.convert_n_to_tensor(resources, _dtypes.resource)
_inputs_flat = list(constants) + list(args) + list(resources)
_attrs = ("Tconstants", _attr_Tconstants, "Targs", _attr_Targs,
"Nresources", _attr_Nresources, "Tresults", Tresults, "function", function)
_result = _execute.execute(b"XlaLaunch", len(Tresults), inputs=_inputs_flat,
attrs=_attrs, ctx=_ctx, name=name)
_execute.record_gradient(
"XlaLaunch", _inputs_flat, _attrs, _result, name)
return _result
示例15: _capture_by_value
def _capture_by_value(
self,
op_type,
inputs,
dtypes, # pylint: disable=redefined-outer-name
input_types=None,
name=None,
attrs=None,
op_def=None,
compute_shapes=True,
compute_device=True):
# When capturing by value, do the read outside
reverse_captures = dict((v, k) for k, v in self.captures.items())
uncaptured_inputs = [reverse_captures.get(t, t) for t in inputs]
with ops.init_scope():
if context.executing_eagerly():
attr_list = ("dtype", int(attrs["dtype"].type))
value, = execute.execute(
compat.as_bytes(op_type), 1, uncaptured_inputs, attr_list,
context.context())
else:
op = ops.get_default_graph().create_op(
op_type, uncaptured_inputs, dtypes, input_types, name, attrs,
op_def, compute_shapes, compute_device)
value = op.outputs[0]
captured_value = self.capture(value)
return captured_value.op