Coder Social home page Coder Social logo

efficient_densenet_tensorflow's People

Contributors

joeyearsley avatar matthiasgoergens avatar sirius083 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

efficient_densenet_tensorflow's Issues

efficient densenet in tensorflow2.0

I have learn so much from your project, It's a good working. Thank you~
I am writing project in tf2.0 now. I haven't been able to implement it. So sad.....
Do you know how to implement in tf2.0. Thank you!

Doesn't work?

class Back_Recompute(Layer):
    def __init__(self, nb_filter, bottleneck=False, dropout_rate=None, weight_decay=1e-4, **kwargs):
        self.nb_filter = nb_filter
        self.weight_decay = weight_decay
        self.bottleneck = bottleneck
        self.dropout_rate = dropout_rate
        super(Back_Recompute, self).__init__(**kwargs)

    def call(self, ip):
        global brcount
        concat_axis = 1 if K.image_data_format() == 'channels_first' else -1
        with tf.variable_scope('denseblock_{}'.format(brcount), use_resource=True):
            def _x(inner_ip):
                x = BatchNormalization(axis=concat_axis, epsilon=1.1e-5)(inner_ip)
                x = Activation('relu')(x)
                if self.bottleneck:
                    inter_channel = self.nb_filter * 4  # Obtained from https://github.com/liuzhuang13/DenseNet/blob/master/densenet.lua

                    x = Conv2D(inter_channel, (1, 1), kernel_initializer='he_normal', padding='same', use_bias=False,
                               kernel_regularizer=l2(self.weight_decay))(x)
                    x = BatchNormalization(axis=concat_axis, epsilon=1.1e-5)(x)
                    x = Activation('relu')(x)
                x = Conv2D(self.nb_filter, (3, 3), kernel_initializer='he_normal', padding='same', use_bias=False)(x)
                if self.dropout_rate:
                    x = Dropout(self.dropout_rate)(x)
                return x

            brcount = brcount + 1
            _x = tf.contrib.layers.recompute_grad(_x)

            return _x(ip)

    def compute_output_shape(self, input_shape):
        return (input_shape[0], input_shape[1], input_shape[2], self.nb_filter)

Then WARNING:tensorflow:@custom_gradient grad_fn has 'variables' in signature, but no ResourceVariables were used on the forward pass.
I found in model.summary, the paras of Back_Recompute is 0,Why?

`recompute_grad` Does Not Work

The method you propose for using recompute_grad is not working, except for the simplest case where all layers in the model are recomputed except the input and output layers. All other cases (e.g. when every-other layer is recomputed) cause the following error:

ValueError: The variables used on recompute were different than the variables originally
used. The function wrapped with @recompute_grad likley creates its own variable
scope with a default name and has been called twice in the same enclosing scope.
To fix, ensure each call to the function happens in its own unique variable
scope.

Can you please advise how to fix this error?

My current method is to (1) create a memory efficient layer, e.g.:

def Conv2D_mem_eff( input_tensor,
                    filters,
                    kernel_size,
                    kernel_regularizer,
                    bias_regularizer,
                    padding,
                    name ):

    with tf.variable_scope( name,
                            use_resource = True ):

        def _x( inner_input_tensor ):

            x = Conv2D( filters = filters,
                        kernel_size = kernel_size,
                        padding = padding,
                        kernel_regularizer = kernel_regularizer,
                        bias_regularizer = bias_regularizer,
                        name = name )(inner_input_tensor)

            return x

        _x = tf.contrib.layers.recompute_grad( _x )

        return _x( input_tensor )

then (2) use this within a Lambda layer when defining my model:

x = Lambda( Conv2D_mem_eff,
                     arguments = {'filters' : 24,
                                            'kernel_size' : (5,5),
                                            'kernel_regularizer' : l2,
                                            'bias_regularizer' : l2,
                                            'padding' : 'same',
                                            'name' : 'conv02'},
                     name= 'conv02' )(x)

I give unique names for each layer I use.

boolean parameter error

the argument parse of boolean varibles is supposed to passed in the version1 format,
otherwise it will not accept the False argument, it is been discussed here
https://stackoverflow.com/questions/15008758/parsing-boolean-values-with-argparse

import argparse
parser = argparse.ArgumentParser()

# version 1
parser.add_argument('--efficient', type = lambda x: (str(x).lower() == 'true'), default=False,
                    help='Whether to run with gradient checkpointing or not.')

# version2
parser.add_argument('--fp16', type=bool, default=False,
                    help='Whether to run with FP16 or not.')

args = parser.parse_args()
print('args.efficient', args.efficient)
print('args.fp16', args.fp16)
python param_tmp.py --efficient=False --fp16=False

Can this be applied to keras

Great work! I am using Keras to bulid my model and I want to reduce the memory of densenet. Can this project be directly used on Keras? Could you show some Keras examples or user guide in Keras?

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.