Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 8960F200B8E for ; Mon, 26 Sep 2016 13:18:27 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 87ECA160AC8; Mon, 26 Sep 2016 11:18:27 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id C5C93160AB8 for ; Mon, 26 Sep 2016 13:18:26 +0200 (CEST) Received: (qmail 40365 invoked by uid 500); 26 Sep 2016 11:18:26 -0000 Mailing-List: contact dev-help@singa.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@singa.incubator.apache.org Delivered-To: mailing list dev@singa.incubator.apache.org Received: (qmail 40355 invoked by uid 99); 26 Sep 2016 11:18:25 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd2-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 26 Sep 2016 11:18:25 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd2-us-west.apache.org (ASF Mail Server at spamd2-us-west.apache.org) with ESMTP id 4F8D41A04FD for ; Mon, 26 Sep 2016 11:18:25 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd2-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -5.446 X-Spam-Level: X-Spam-Status: No, score=-5.446 tagged_above=-999 required=6.31 tests=[KAM_LAZY_DOMAIN_SECURITY=1, RCVD_IN_DNSWL_HI=-5, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, RP_MATCHES_RCVD=-1.426] autolearn=disabled Received: from mx2-lw-us.apache.org ([10.40.0.8]) by localhost (spamd2-us-west.apache.org [10.40.0.9]) (amavisd-new, port 10024) with ESMTP id o5cPOTXzN7vY for ; Mon, 26 Sep 2016 11:18:21 +0000 (UTC) Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx2-lw-us.apache.org (ASF Mail Server at mx2-lw-us.apache.org) with SMTP id 7FECD5F2C5 for ; Mon, 26 Sep 2016 11:18:21 +0000 (UTC) Received: (qmail 39954 invoked by uid 99); 26 Sep 2016 11:18:20 -0000 Received: from arcas.apache.org (HELO arcas) (140.211.11.28) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 26 Sep 2016 11:18:20 +0000 Received: from arcas.apache.org (localhost [127.0.0.1]) by arcas (Postfix) with ESMTP id BFAED2C002D for ; Mon, 26 Sep 2016 11:18:20 +0000 (UTC) Date: Mon, 26 Sep 2016 11:18:20 +0000 (UTC) From: "hacker99 (JIRA)" To: dev@singa.incubator.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Commented] (SINGA-249) Convolution BP MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 archived-at: Mon, 26 Sep 2016 11:18:27 -0000 [ https://issues.apache.org/jira/browse/SINGA-249?page=3Dcom.atlassian.= jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=3D15522= 762#comment-15522762 ]=20 hacker99 commented on SINGA-249: -------------------------------- Thank you ! i am stupid,i should take a look at the code. > Convolution BP > -------------- > > Key: SINGA-249 > URL: https://issues.apache.org/jira/browse/SINGA-249 > Project: Singa > Issue Type: Wish > Environment: ubuntu 14.04=EF=BC=8Csinga 1.0 > Reporter: hacker99 > > I'm curious about how to calculate the gradient of the back propagation a= lgorithm eg. Convolution layer. Can anyone explain to me the details of the= implementation of the formula and the code? Very grateful, if there is som= e documents or just tell why dw +=3D Mult(grad_b, col_data.T())? > #code from src/model/layer/convolution.cc > const std::pair> Convolution::Backward( > int flag, const Tensor &grad) { > CHECK_EQ(grad.device()->lang(), kCpp); > CHECK_EQ(grad.nDim(), 4u); > CHECK(!buf_.empty()); > Tensor src_data =3D buf_.top(); > buf_.pop(); > vector param_grad; > Tensor dx; > Tensor db, dw; > dx.ResetLike(src_data); > db.ResetLike(bias_); > dw.ResetLike(weight_); > dw.SetValue(0.0f); > size_t batchsize =3D grad.shape(0); > size_t imagesize =3D src_data.Size() / batchsize; > if (bias_term_) { > Tensor tmp1 =3D > Reshape(grad, Shape{batchsize * num_filters_, > grad.Size() / (batchsize * num_filters_)}); > Tensor tmp2(Shape{batchsize * num_filters_}); > SumColumns(tmp1, &tmp2); > Tensor tmp3 =3D Reshape(tmp2, Shape{batchsize, num_filters_}); > SumRows(tmp3, &db); > } > auto in_data =3D src_data.data(); > Tensor col_data(Shape{col_height_, col_width_}); > float *data_col =3D new float[col_height_ * col_width_]; > float *dx_b =3D new float[imagesize]; > for (size_t b =3D 0; b < batchsize; b++) { > Im2col(in_data + b * imagesize, channels_, height_, width_, kernel_h_= , > kernel_w_, pad_h_, pad_w_, stride_h_, stride_w_, data_col); > col_data.CopyDataFromHostPtr(data_col, col_height_ * col_width_); > Tensor grad_b(Shape{num_filters_, conv_height_ * conv_width_}); > CopyDataToFrom(&grad_b, grad, grad_b.Size(), 0, b * grad_b.Size()); > dw +=3D Mult(grad_b, col_data.T()); > Tensor dcol_b =3D Mult(weight_.T(), grad_b); > auto dcol_data =3D dcol_b.data(); > Col2im(dcol_data, channels_, height_, width_, kernel_h_, kernel_w_, p= ad_h_, > pad_w_, stride_h_, stride_w_, dx_b); > dx.CopyDataFromHostPtr(dx_b, imagesize, b * imagesize); > } > param_grad.push_back(dw); > param_grad.push_back(db); > delete[] data_col; > delete[] dx_b; > return std::make_pair(dx, param_grad); > } -- This message was sent by Atlassian JIRA (v6.3.4#6332)