nn/unet.py
def load_weights(ckpt_dir, layers2load):
        """
        This is different from network.load(). This function only loads specified layers
        :param ckpt_dir: path to the model to load
        :param layers2load: could be a list, or string where numbers separated by ,
        :return:
        """
        layers_list = []
        if isinstance(layers2load, str):
            layers2load = [int(a) for a in layers2load.split(',')]
        for layer_id in layers2load:
            assert 1 <= layer_id <= 9
            if layer_id <= 5:
                prefix = 'layerconv'
            else:
                prefix = 'layerup'
            layers_list.append('{}{}'.format(prefix, layer_id))

        load_dict = {}
        for layer_name in layers_list:
            feed_layer = layer_name + '/'
            load_dict[feed_layer] = feed_layer
        try:
            latest_check_point = tf.train.latest_checkpoint(ckpt_dir)
            tf.contrib.framework.init_from_checkpoint(ckpt_dir, load_dict)
            print('loaded {}'.format(latest_check_point))
        except tf.errors.NotFoundError:
            with open(os.path.join(ckpt_dir, 'checkpoint'), 'r') as f:
                ckpts = f.readlines()
            ckpt_file_name = ckpts[0].split('/')[-1].strip().strip('\"')
            latest_check_point = os.path.join(ckpt_dir, ckpt_file_name)
            tf.contrib.framework.init_from_checkpoint(latest_check_point, load_dict)
            print('loaded {}'.format(latest_check_point))

        This is different from network.load(). This function only loads specified layers
        :param ckpt_dir: path to the model to load
        :param layers2load: could be a list, or string where numbers separated by ,
        :return:
        
This is different from network.load(). This function only loads specified layers
This is different from network . load () . This function only loads specified layers
def load_weights(ckpt_dir, layers2load):
        layers_list = []
        if isinstance(layers2load, str):
            layers2load = [int(a) for a in layers2load.split(',')]
        for layer_id in layers2load:
            assert 1 <= layer_id <= 9
            if layer_id <= 5:
                prefix = 'layerconv'
            else:
                prefix = 'layerup'
            layers_list.append('{}{}'.format(prefix, layer_id))
        load_dict = {}
        for layer_name in layers_list:
            feed_layer = layer_name + '/'
            load_dict[feed_layer] = feed_layer
        try:
            latest_check_point = tf.train.latest_checkpoint(ckpt_dir)
            tf.contrib.framework.init_from_checkpoint(ckpt_dir, load_dict)
            print('loaded {}'.format(latest_check_point))
        except tf.errors.NotFoundError:
            with open(os.path.join(ckpt_dir, 'checkpoint'), 'r') as f:
                ckpts = f.readlines()
            ckpt_file_name = ckpts[0].split('/')[-1].strip().strip('\"')
            latest_check_point = os.path.join(ckpt_dir, ckpt_file_name)
            tf.contrib.framework.init_from_checkpoint(latest_check_point, load_dict)
            print('loaded {}'.format(latest_check_point))
def load_weights ( ckpt_dir , layers2load ) : layers_list = [ ] if isinstance ( layers2load , str ) : layers2load = [ int ( a ) for a in layers2load . split ( ',' ) ] for layer_id in layers2load : assert 1 <= layer_id <= 9 if layer_id <= 5 : prefix = 'layerconv' else : prefix = 'layerup' layers_list . append ( '{}{}' . format ( prefix , layer_id ) ) load_dict = { } for layer_name in layers_list : feed_layer = layer_name + '/' load_dict [ feed_layer ] = feed_layer try : latest_check_point = tf . train . latest_checkpoint ( ckpt_dir ) tf . contrib . framework . init_from_checkpoint ( ckpt_dir , load_dict ) print ( 'loaded {}' . format ( latest_check_point ) ) except tf . errors . NotFoundError : with open ( os . path . join ( ckpt_dir , 'checkpoint' ) , 'r' ) as f : ckpts = f . readlines ( ) ckpt_file_name = ckpts [ 0 ] . split ( '/' ) [ - 1 ] . strip ( ) . strip ( '\"' ) latest_check_point = os . path . join ( ckpt_dir , ckpt_file_name ) tf . contrib . framework . init_from_checkpoint ( latest_check_point , load_dict ) print ( 'loaded {}' . format ( latest_check_point ) )
This is different from network.load().
This is different from network . load () .
"""
        This is different from network.load(). This function only loads specified layers
        :param ckpt_dir: path to the model to load
        :param layers2load: could be a list, or string where numbers separated by ,
        :return:
        """
None
ckpt_dir
path to the model to load
path to the model to load
layers2load
could be a list, or string where numbers separated by .
could be a list or string where numbers separated by .