You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@singa.apache.org by GitBox <gi...@apache.org> on 2020/05/23 11:31:21 UTC

[GitHub] [singa] XJDKC edited a comment on pull request #697: New Model Layer Operator API

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
   ```


----------------------------------------------------------------
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