Giter VIP home page Giter VIP logo

Comments (4)

zsdonghao avatar zsdonghao commented on May 13, 2024 1

@JindongJiang Good idea, indeed.

I think we can create 2 functions for Layer class : network.get_layers_by_name("conv2") and network.get_params_by_name("W").

network.get_params_by_name("W") should be similar with tl.layer. get_variables_with_name() as follow:

def get_variables_with_name(name, train_only=True, printable=False):
    """Get variable list by a given name scope.

    Examples
    ---------
    >>> dense_vars = get_variable_with_name('dense', True, True)
    """
    print("  Get variables with %s" % name)
    t_vars = tf.trainable_variables() if train_only else tf.all_variables()
    d_vars = [var for var in t_vars if name in var.name]
    if printable:
        for idx, v in enumerate(d_vars):
            print("  got {:3}: {:15}   {}".format(idx, v.name, str(v.get_shape())))
    return d_vars

You can try this code by adding it to Layer:

def get_params_by_name(self, name, printable=False):
    print("  Get params in a network with %s" % name)
    t_vars = self.all_params
    d_vars = [var for var in t_vars if name in var.name]
    if printable:
        for idx, v in enumerate(d_vars):
            print("  got {:3}: {:15}   {}".format(idx, v.name, str(v.get_shape())))
    return d_vars

from tensorlayer.

JindongJiang avatar JindongJiang commented on May 13, 2024

@zsdonghao Thx. And w.r.t network.get_layers_by_name maybe :

self.all_layers = layer.all_layers
...
self.all_layers[name] = self.output

and:

def get_layers_by_name(self, name):
    print("  Get layers in a network with %s" % name)
    d_layers = self.all_layers.get(name, None)
    if d_layers is None:
        print(" %s not implemented ".format(name))
    return d_layers

Could work ?

from tensorlayer.

zsdonghao avatar zsdonghao commented on May 13, 2024

I think it should work, but it that possible don't add new code into every layers?

from tensorlayer.

zsdonghao avatar zsdonghao commented on May 13, 2024

@JindongJiang tl.layers.get_layers_with_name is now in the master version

from tensorlayer.

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.