@@ -4865,7 +4865,7 @@ def autoincreased_step_counter(counter_name=None, begin=1, step=1):
4865
4865
return counter
4866
4866
4867
4867
4868
- def reshape (x , shape , actual_shape = None , act = None , inplace = True , name = None ):
4868
+ def reshape (x , shape , actual_shape = None , act = None , inplace = False , name = None ):
4869
4869
"""
4870
4870
Gives a new shape to the input Tensor without changing its data.
4871
4871
@@ -4913,15 +4913,22 @@ def reshape(x, shape, actual_shape=None, act=None, inplace=True, name=None):
4913
4913
:attr:`shape` specifying shape. That is to
4914
4914
say :attr:`actual_shape` has a higher priority
4915
4915
than :attr:`shape`.
4916
- act (str): The non-linear activation to be applied to output variable.
4917
- inplace(bool): If this flag is set true, the output
4918
- shares data with input without copying, otherwise
4919
- a new output tensor is created
4920
- whose data is copied from input x.
4916
+ act (str): The non-linear activation to be applied to the reshaped tensor
4917
+ variable.
4918
+ inplace(bool): Must use :attr:`False` if :attr:`x` is used in multiple
4919
+ operators. If this flag is set :attr:`True`, reuse input
4920
+ :attr:`x` to reshape, which will change the shape of
4921
+ tensor variable :attr:`x` and might cause errors when
4922
+ :attr:`x` is used in multiple operators. If :attr:`False`,
4923
+ preserve the shape :attr:`x` and create a new output tensor
4924
+ variable whose data is copied from input x but reshaped.
4921
4925
name (str): The name of this layer. It is optional.
4922
4926
4923
4927
Returns:
4924
- Variable: The output tensor.
4928
+ Variable: The reshaped tensor variable if :attr:`act` is None. It is a \
4929
+ new tensor variable if :attr:`inplace` is :attr:`False`, \
4930
+ otherwise it is :attr:`x`. If :attr:`act` is not None, return \
4931
+ the activated tensor variable.
4925
4932
4926
4933
Raises:
4927
4934
TypeError: if actual_shape is neither Variable nor None.
@@ -4932,7 +4939,7 @@ def reshape(x, shape, actual_shape=None, act=None, inplace=True, name=None):
4932
4939
data = fluid.layers.data(
4933
4940
name='data', shape=[2, 4, 6], dtype='float32')
4934
4941
reshaped = fluid.layers.reshape(
4935
- x=data, shape=[-1, 0, 3, 2], act='tanh', inplace=True)
4942
+ x=data, shape=[-1, 0, 3, 2], inplace=True)
4936
4943
"""
4937
4944
4938
4945
if not (isinstance (shape , list ) or isinstance (shape , tuple )):
@@ -4959,7 +4966,8 @@ def reshape(x, shape, actual_shape=None, act=None, inplace=True, name=None):
4959
4966
"except one unknown dimension." )
4960
4967
4961
4968
helper = LayerHelper ("reshape2" , ** locals ())
4962
- out = helper .create_variable_for_type_inference (dtype = x .dtype )
4969
+ out = x if inplace else helper .create_variable_for_type_inference (
4970
+ dtype = x .dtype )
4963
4971
x_shape = helper .create_variable_for_type_inference (dtype = x .dtype )
4964
4972
helper .append_op (
4965
4973
type = "reshape2" ,
0 commit comments