From dev-return-5444-archive-asf-public=cust-asf.ponee.io@singa.apache.org Sat May 23 11:33:52 2020 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [207.244.88.153]) by mx-eu-01.ponee.io (Postfix) with SMTP id 7CA12180634 for ; Sat, 23 May 2020 13:33:52 +0200 (CEST) Received: (qmail 56748 invoked by uid 500); 23 May 2020 11:33:51 -0000 Mailing-List: contact dev-help@singa.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@singa.apache.org Delivered-To: mailing list dev@singa.apache.org Received: (qmail 56738 invoked by uid 99); 23 May 2020 11:33:51 -0000 Received: from ec2-52-202-80-70.compute-1.amazonaws.com (HELO gitbox.apache.org) (52.202.80.70) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 23 May 2020 11:33:51 +0000 From: =?utf-8?q?GitBox?= To: dev@singa.apache.org Subject: =?utf-8?q?=5BGitHub=5D_=5Bsinga=5D_XJDKC_edited_a_comment_on_pull_request_?= =?utf-8?q?=23697=3A_New_Model_Layer_Operator_API?= Message-ID: <159023363151.19379.493763215496534563.asfpy@gitbox.apache.org> Date: Sat, 23 May 2020 11:33:51 -0000 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit References: In-Reply-To: XJDKC edited a comment on pull request #697: URL: https://github.com/apache/singa/pull/697#issuecomment-633031985 Now, users can define a new layer like this. (Just three functions) ``` class MyLayer(layer.Layer): def __init__(self, a, b, c): super(MyLayer, self).__init__() self.l1 = layer.Linear(a,b) self.l2 = layer.Linear(b,c) # just need to specify names of params and states self.param_names = ['W', 'b'] self.state_names = self.param_names + ['running_mean', 'running_var'] def initialize(self, x): ## init params, no need to enable the graph manually, the graph will be enabled automatically pass def forward(self, x): y = self.l1(x) y = self.l2(y) ### other statements return y ``` An example of the result of get_params ```bash {'MyModel.l1.W': [[-0.38202214 -0.12201381] [-0.304533 -0.9495602 ] [ 0.16352855 -0.01871952] [ 0.8286818 -0.35981584]], 'MyModel.l1.b': [0. 0.], 'MyModel.bn1.scale': [1. 1.], 'MyModel.bn1.bias': [0. 0.], 'MyModel.dl1.l1.W': [[ 0.11860882 -0.79534566 -0.22841209 0.17164443] [-0.6173898 0.66481847 -0.2978943 0.30236784]], 'MyModel.dl1.l1.b': [0. 0. 0. 0.], 'MyModel.dl1.l2.W': [[ 0.4442746 -1.1191332 ] [ 0.38644505 0.8065585 ] [-0.06753294 -0.19837534] [-0.20991991 0.18191515]], 'MyModel.dl1.l2.b': [0. 0.]} ``` ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: users@infra.apache.org