-
Notifications
You must be signed in to change notification settings - Fork 756
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Add] avgpool1d avgpool3d #5165
Conversation
zev123456
commented
Jun 10, 2021
•
edited
Loading
edited
out = out.reshape(out_shape) | ||
return out | ||
|
||
def backward(self, d_loss): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个numpy模拟的grad没有使用吧?没用的话可以删掉
output = output.sum() | ||
output.backward() | ||
doutput = np.ones_like(numpy_output, dtype=np.float64) | ||
#numpy_grad = m_numpy.backward(doutput) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
注释删了吧
output.backward() | ||
doutput = np.ones_like(numpy_output, dtype=np.float64) | ||
#numpy_grad = m_numpy.backward(doutput) | ||
numpy_grad = np.array(#torch grad out |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
numpy_grad可以直接用:numpy_grad = np.zeros(shape=xxx)
+ numpy_grad[...] = 0.125
完成
>>> inputarr = np.array([[[[[-0.74832135, 0.03151652],[ 1.08632752, 0.53338843]],[[ 0.70026413, -0.62565466], [-0.59692776, -1.00883888]]],[[[-0.26829566, -0.31759021],[ 1.46828945, -2.61885422]],[[-0.67331338, 1.31144767],[-0.85747376, -0.38252167]]]],[[[[-1.54668075, -0.935113 ],[ 0.19119924, -0.83618886]],[[ 0.17532863, 0.6574685 ],[-1.10141786, 1.1819236 ]]],[[[-1.1367412 , 0.68027652],[ 0.98564578, 0.04861313]],[[-0.69807858, 0.75021497],[ 0.62720175, -0.76607257]]]]]) | ||
>>> of_avgpool3d = flow.nn.AvgPool3d(kernel_size=(2,2,2),padding=(0,0,0),stride=(1,1,1),) | ||
>>> x = flow.Tensor(inputarr) | ||
>>> flow.enable_eager_execution() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
flow.enable_eager_execution()这个放上面吧
>>> of_y = of_avgpool3d(x) | ||
>>> print(of_y.dtype) | ||
oneflow.float32 | ||
>>> print(of_y.numpy().sum()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
直接>>>of_y 就行,不需要.numpy().sum()了