Exemple #1
0
def rename_layers(model, scope=None):
    if not scope:
        scope = model.scope
    for layer in model.layers:
        if is_input_layer(layer) or layer.name.startswith(scope):
            continue
        layer.name = '%s/%s' % (scope, layer.name)
Exemple #2
0
def rename_layers(model, scope=None):
    if not scope:
        scope = model.scope
    for layer in model.layers:
        if is_input_layer(layer) or layer.name.startswith(scope):
            continue
        layer.name = '%s/%s' % (scope, layer.name)
Exemple #3
0
    def set_trainability(self, model):
        opts = self.opts
        trainable = []
        not_trainable = []
        if opts.fine_tune:
            not_trainable.append('.*')
        elif opts.train_models:
            not_trainable.append('.*')
            for name in opts.train_models:
                trainable.append('%s/' % name)
        if opts.freeze_filter:
            not_trainable.append(mod.get_first_conv_layer(model.layers).name)
        if not trainable and opts.trainable:
            trainable = opts.trainable
        if not not_trainable and opts.not_trainable:
            not_trainable = opts.not_trainable

        if not trainable and not not_trainable:
            return

        table = OrderedDict()
        table['layer'] = []
        table['trainable'] = []
        for layer in model.layers:
            if is_input_layer(layer) or is_output_layer(layer, model):
                continue
            if not hasattr(layer, 'trainable'):
                continue
            for regex in not_trainable:
                if re.match(regex, layer.name):
                    layer.trainable = False
            for regex in trainable:
                if re.match(regex, layer.name):
                    layer.trainable = True
            table['layer'].append(layer.name)
            table['trainable'].append(layer.trainable)
        print('Layer trainability:')
        print(format_table(table))
        print()
Exemple #4
0
    def set_trainability(self, model):
        opts = self.opts
        trainable = []
        not_trainable = []
        if opts.fine_tune:
            not_trainable.append('.*')
        elif opts.train_models:
            not_trainable.append('.*')
            for name in opts.train_models:
                trainable.append('%s/' % name)
        if opts.freeze_filter:
            not_trainable.append(mod.get_first_conv_layer(model.layers).name)
        if not trainable and opts.trainable:
            trainable = opts.trainable
        if not not_trainable and opts.not_trainable:
            not_trainable = opts.not_trainable

        if not trainable and not not_trainable:
            return

        table = OrderedDict()
        table['layer'] = []
        table['trainable'] = []
        for layer in model.layers:
            if is_input_layer(layer) or is_output_layer(layer, model):
                continue
            if not hasattr(layer, 'trainable'):
                continue
            for regex in not_trainable:
                if re.match(regex, layer.name):
                    layer.trainable = False
            for regex in trainable:
                if re.match(regex, layer.name):
                    layer.trainable = True
            table['layer'].append(layer.name)
            table['trainable'].append(layer.trainable)
        print('Layer trainability:')
        print(format_table(table))
        print()