Creates an `Operation` in this graph. This is a low-level interface for creating an `Operation`. Most programs will not call this method directly, and instead use the Python op constructors, such as `tf.constant()`, which add ops to the default graph. Args: op_type: The `
(
self,
op_type,
inputs,
dtypes=None, # pylint: disable=redefined-outer-name
input_types=None,
name=None,
attrs=None,
op_def=None,
compute_shapes=True,
compute_device=True)
| 3306 | "Shapes are always computed; don't use the compute_shapes " |
| 3307 | "as it has no effect.", "compute_shapes") |
| 3308 | def create_op( |
| 3309 | self, |
| 3310 | op_type, |
| 3311 | inputs, |
| 3312 | dtypes=None, # pylint: disable=redefined-outer-name |
| 3313 | input_types=None, |
| 3314 | name=None, |
| 3315 | attrs=None, |
| 3316 | op_def=None, |
| 3317 | compute_shapes=True, |
| 3318 | compute_device=True): |
| 3319 | """Creates an `Operation` in this graph. |
| 3320 | |
| 3321 | This is a low-level interface for creating an `Operation`. Most |
| 3322 | programs will not call this method directly, and instead use the |
| 3323 | Python op constructors, such as `tf.constant()`, which add ops to |
| 3324 | the default graph. |
| 3325 | |
| 3326 | Args: |
| 3327 | op_type: The `Operation` type to create. This corresponds to the |
| 3328 | `OpDef.name` field for the proto that defines the operation. |
| 3329 | inputs: A list of `Tensor` objects that will be inputs to the `Operation`. |
| 3330 | dtypes: (Optional) A list of `DType` objects that will be the types of the |
| 3331 | tensors that the operation produces. |
| 3332 | input_types: (Optional.) A list of `DType`s that will be the types of the |
| 3333 | tensors that the operation consumes. By default, uses the base `DType` |
| 3334 | of each input in `inputs`. Operations that expect reference-typed inputs |
| 3335 | must specify `input_types` explicitly. |
| 3336 | name: (Optional.) A string name for the operation. If not specified, a |
| 3337 | name is generated based on `op_type`. |
| 3338 | attrs: (Optional.) A dictionary where the key is the attribute name (a |
| 3339 | string) and the value is the respective `attr` attribute of the |
| 3340 | `NodeDef` proto that will represent the operation (an `AttrValue` |
| 3341 | proto). |
| 3342 | op_def: (Optional.) The `OpDef` proto that describes the `op_type` that |
| 3343 | the operation will have. |
| 3344 | compute_shapes: (Optional.) Deprecated. Has no effect (shapes are always |
| 3345 | computed). |
| 3346 | compute_device: (Optional.) If True, device functions will be executed to |
| 3347 | compute the device property of the Operation. |
| 3348 | |
| 3349 | Raises: |
| 3350 | TypeError: if any of the inputs is not a `Tensor`. |
| 3351 | ValueError: if colocation conflicts with existing device assignment. |
| 3352 | |
| 3353 | Returns: |
| 3354 | An `Operation` object. |
| 3355 | """ |
| 3356 | del compute_shapes |
| 3357 | for idx, a in enumerate(inputs): |
| 3358 | if not isinstance(a, Tensor): |
| 3359 | raise TypeError("Input #%d is not a tensor: %s" % (idx, a)) |
| 3360 | return self._create_op_internal(op_type, inputs, dtypes, input_types, name, |
| 3361 | attrs, op_def, compute_device) |
| 3362 | |
| 3363 | def _create_op_internal( |
| 3364 | self, |