|
85 | 85 | 'one_hot',
|
86 | 86 | 'autoincreased_step_counter',
|
87 | 87 | 'reshape',
|
| 88 | + 'squeeze', |
| 89 | + 'unsqueeze', |
88 | 90 | 'lod_reset',
|
89 | 91 | 'lrn',
|
90 | 92 | 'pad',
|
@@ -4532,6 +4534,89 @@ def reshape(x, shape, actual_shape=None, act=None, inplace=True, name=None):
|
4532 | 4534 | return helper.append_activation(out)
|
4533 | 4535 |
|
4534 | 4536 |
|
| 4537 | +def squeeze(input, axes, name=None): |
| 4538 | + """ |
| 4539 | + Remove single-dimensional entries from the shape of a tensor. Takes a |
| 4540 | + parameter axes with a list of axes to squeeze. If axes is not provided, all |
| 4541 | + the single dimensions will be removed from the shape. If an axis is |
| 4542 | + selected with shape entry not equal to one, an error is raised. |
| 4543 | + |
| 4544 | + Examples: |
| 4545 | + Case 1: |
| 4546 | + Given |
| 4547 | + X.shape = (1, 3, 1, 5) |
| 4548 | + and |
| 4549 | + axes = [0] |
| 4550 | + we get: |
| 4551 | + Out.shape = (3, 1, 5) |
| 4552 | + Case 2: |
| 4553 | + Given |
| 4554 | + X.shape = (1, 3, 1, 5) |
| 4555 | + and |
| 4556 | + axes = [] |
| 4557 | + we get: |
| 4558 | + Out.shape = (3, 5) |
| 4559 | + |
| 4560 | + Args: |
| 4561 | + input (Variable): The input variable to be squeezed. |
| 4562 | + axes (list): List of integers, indicating the dimensions to be squeezed. |
| 4563 | + name (str|None): Name for this layer. |
| 4564 | +
|
| 4565 | + Returns: |
| 4566 | + Variable: Output squeezed variable. |
| 4567 | +
|
| 4568 | + Examples: |
| 4569 | + .. code-block:: python |
| 4570 | +
|
| 4571 | + x = layers.data(name='x', shape=[5, 1, 10]) |
| 4572 | + y = layers.sequeeze(input=x, axes=[1]) |
| 4573 | + """ |
| 4574 | + helper = LayerHelper("squeeze", **locals()) |
| 4575 | + out = helper.create_tmp_variable(dtype=input.dtype) |
| 4576 | + helper.append_op( |
| 4577 | + type="squeeze", |
| 4578 | + inputs={"X": input}, |
| 4579 | + attrs={"axes": axes}, |
| 4580 | + outputs={"Out": out}) |
| 4581 | + |
| 4582 | + return out |
| 4583 | + |
| 4584 | + |
| 4585 | +def unsqueeze(input, axes, name=None): |
| 4586 | + """ |
| 4587 | + Insert single-dimensional entries to the shape of a tensor. Takes one |
| 4588 | + required argument axes, a list of dimensions that will be inserted. |
| 4589 | + Dimension indices in axes are as seen in the output tensor. |
| 4590 | +
|
| 4591 | + For example: |
| 4592 | + Given a tensor such that tensor with shape [3, 4, 5], |
| 4593 | + then Unsqueezed tensor with axes=[0, 4] has shape [1, 3, 4, 5, 1]. |
| 4594 | + |
| 4595 | + Args: |
| 4596 | + input (Variable): The input variable to be unsqueezed. |
| 4597 | + axes (list): List of integers, indicating the dimensions to be inserted. |
| 4598 | + name (str|None): Name for this layer. |
| 4599 | +
|
| 4600 | + Returns: |
| 4601 | + Variable: Output unsqueezed variable. |
| 4602 | +
|
| 4603 | + Examples: |
| 4604 | + .. code-block:: python |
| 4605 | +
|
| 4606 | + x = layers.data(name='x', shape=[5, 10]) |
| 4607 | + y = layers.unsequeeze(input=x, axes=[1]) |
| 4608 | + """ |
| 4609 | + helper = LayerHelper("unsqueeze", **locals()) |
| 4610 | + out = helper.create_tmp_variable(dtype=input.dtype) |
| 4611 | + helper.append_op( |
| 4612 | + type="unsqueeze", |
| 4613 | + inputs={"X": input}, |
| 4614 | + attrs={"axes": axes}, |
| 4615 | + outputs={"Out": out}) |
| 4616 | + |
| 4617 | + return out |
| 4618 | + |
| 4619 | + |
4535 | 4620 | def lod_reset(x, y=None, target_lod=None):
|
4536 | 4621 | """
|
4537 | 4622 | Set LoD of :attr:`x` to a new one specified by :attr:`y` or
|
|
0 commit comments