Esempio n. 1
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()
Esempio n. 2
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()
Esempio n. 3
0
def remove_outputs(model):
    while is_output_layer(model.layers[-1], model):
        model.layers.pop()
    model.outputs = [model.layers[-1].output]
    model.layers[-1].outbound_nodes = []
    model.output_names = None
Esempio n. 4
0
def remove_outputs(model):
    while is_output_layer(model.layers[-1], model):
        model.layers.pop()
    model.outputs = [model.layers[-1].output]
    model.layers[-1].outbound_nodes = []
    model.output_names = None