Giter Site home page Giter Site logo

Comments (4)

fariasfc avatar fariasfc commented on April 27, 2024

I thought to add another class called Initializers with a function that we could pass the weights and a string with the initialization name. Also add a string argument to every layer called "initialization".

In a Linear layer the init should be something like this:

def __init__(self, in_features, out_features, bias=True, initializer=None):
    super(Linear, self).__init__()
    self.in_features = in_features
    self.out_features = out_features
    self.weight = Parameter(torch.Tensor(out_features, in_features))
    Initializers.initialize(self.weight, initializer)
    if bias:
        self.bias = Parameter(torch.Tensor(out_features))
    else:
        self.register_parameter('bias', None)
    self.reset_parameters()

Do you think that this is the best approach? If not, what would be the best way to do this?

from pytorch.

apaszke avatar apaszke commented on April 27, 2024

I think it's better to pass in a function as the initializer and call it with weights as argument. It's clean, verbose, and you don't have to do error checking for invalid/incompatible strings. For example:

nn.Linear(20, 20, weight_init=nn.init.orthogonal)

Do you want to implement it, or was your comment only a suggestion?

from pytorch.

jekbradbury avatar jekbradbury commented on April 27, 2024

Chainer has a nice approach, where the initializer argument is a little polymorphic (can be a callable or a scalar/matrix value). Looks like this:

super().__init__(
    maxout=Maxout(maxout_size, maxout_size, 2, initialW=initializers.GlorotUniform()),
    softmax_linear=Linear(maxout_size, task.num_classes, initialW=0))

from pytorch.

fariasfc avatar fariasfc commented on April 27, 2024

@apaszke, I am thinking to implement it.

I think that String-like is cleaner. But we could go the way Chainer implements it, as shown by @jekbradbury. With strings or class names being accepted.

What do you guys think?

from pytorch.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.