def load_tf_model():
    # load config file
    sttime = time.time()
    cfg.TEST.checkpoints_path = './ctpn/checkpoints'

    # init session
    gpu_options = tf.GPUOptions(per_process_gpu_memory_fraction=1.0)
    config = tf.ConfigProto(allow_soft_placement=True, gpu_options=gpu_options)
    sess = tf.Session(config=config)

    # load network
    net = get_network("VGGnet_test")

    # load model
    print('Loading network {:s}... '.format("VGGnet_test"))
    saver = tf.train.Saver()
    try:
        ckpt = tf.train.get_checkpoint_state(cfg.TEST.checkpoints_path)
        print('Restoring from {}...'.format(ckpt.model_checkpoint_path))
        saver.restore(sess, ckpt.model_checkpoint_path)
        print('done')
    except:
        raise 'Check your pretrained {:s}'.format(ckpt.model_checkpoint_path)
    logging.info("加载tf模型", time.time() - sttime)
    return sess, net
Example #2
0
def load_tf_model(GPU_MEM_USAGE):
    # load config file
    cfg.TEST.checkpoints_path = './ctpn/checkpoints'

    # init session
    os.environ['CUDA_VISIBLE_DEVICES'] = cfg.TEST.RUN_ON
    gpu_options = tf.GPUOptions(per_process_gpu_memory_fraction=GPU_MEM_USAGE)
    config = tf.ConfigProto(allow_soft_placement=True, gpu_options=gpu_options)
    sess = tf.Session(config=config)

    # load network
    net = get_network("VGGnet_test")

    # load model
    print('Loading network {:s}... '.format("VGGnet_test"))
    saver = tf.train.Saver()
    ckpt = tf.train.get_checkpoint_state(cfg.TEST.checkpoints_path)
    try:
        print('Restoring from {}...'.format(ckpt.model_checkpoint_path))
        saver.restore(sess, ckpt.model_checkpoint_path)
        print('done')
    except:
        raise 'Check your pretrained {:s}'.format(ckpt.model_checkpoint_path)

    return sess, net
Example #3
0
    def __init__(self):
        cfg_from_file(os.getcwd() + '/ctpn/ctpn/text.yml')
        # init session
        self.config = tf.ConfigProto(allow_soft_placement=True)
        self.sess = tf.Session(config=self.config)
        # load network
        self.net = get_network("VGGnet_test")
        # load model
        print(('Loading network {:s}... '.format("VGGnet_test")), end=' ')
        saver = tf.train.Saver()

        try:
            ckpt = tf.train.get_checkpoint_state("ctpn/checkpoints/")
            # ckpt=tf.train.get_checkpoint_state("output/ctpn_end2end/voc_2007_trainval/")
            print('Restoring from {}...'.format(ckpt.model_checkpoint_path), end=' ')
            saver.restore(self.sess, ckpt.model_checkpoint_path)
            print('done', end=' ')
        except:
            raise 'Check your pretrained {:s}'.format(ckpt.model_checkpoint_path)
        print(' done.')
Example #4
0
    def __init__(self, sess):
        super(Detect, self).__init__()
        cfg_from_file('ctpn/ctpn/text.yml')

        # init session
        # config = tf.ConfigProto(allow_soft_placement=True)
        # sess = tf.Session(config=config)

        # sess = tf.Session()
        # load network
        net = get_network("VGGnet_test")
        # load model
        print(('Loading network {:s}... '.format("VGGnet_test")))
        saver = tf.train.Saver()

        ctpn_model_path = 'ctpn/checkpoints/VGGnet_fast_rcnn_iter_50000.ckpt'
        print('Restoring from {}...'.format(ctpn_model_path))
        saver.restore(sess, ctpn_model_path)
        print('Done\n')

        self.sess = sess
        self.net = net
    def __init__(self,first = True):
        if not first:
            tf.get_variable_scope().reuse_variables()
        # cfg_from_file(os.getcwd() + '/ctpn/ctpn/text.yml')
        cfg_from_file(os.path.join(os.path.dirname(os.path.abspath(__file__)),'text.yml'))
        # init session
        self.config = tf.ConfigProto(allow_soft_placement=True)
        self.sess = tf.Session(config=self.config)
        # load network
        self.net = get_network("VGGnet_test")
        # load model
        print(('Loading network {:s}... '.format("VGGnet_test")), end=' ')
        saver = tf.train.Saver()

        try:
            #ckpt = tf.train.get_checkpoint_state("ctpn/checkpoints/")
            ckpt = tf.train.get_checkpoint_state("G:/DeepLearningProjects/Web_SceneRecognition/ScenceRecognition_master/ctpn/checkpoints/")            
            # ckpt=tf.train.get_checkpoint_state("output/ctpn_end2end/voc_2007_trainval/")
            print('Restoring from {}...'.format(ckpt.model_checkpoint_path), end=' ')
            saver.restore(self.sess, ckpt.model_checkpoint_path)
            print('done', end=' ')
        except:
            raise 'Check your pretrained {:s}'.format(ckpt.model_checkpoint_path)
        print(' done.')
Example #6
0
from ctpn.lib.fast_rcnn.train import get_training_roidb, train_net
from ctpn.lib.fast_rcnn.config import cfg_from_file, get_output_dir, get_log_dir
from ctpn.lib.datasets.factory import get_imdb
from ctpn.lib.networks.factory import get_network
from ctpn.lib.fast_rcnn.config import cfg

if __name__ == '__main__':
    cfg_from_file('text.yml')
    print('Using config:')
    pprint.pprint(cfg)
    imdb = get_imdb('voc_2007_trainval')
    print('Loaded dataset `{:s}` for training'.format(imdb.name))
    roidb = get_training_roidb(imdb)

    output_dir = get_output_dir(imdb, None)
    log_dir = get_log_dir(imdb)
    print('Output will be saved to `{:s}`'.format(output_dir))
    print('Logs will be saved to `{:s}`'.format(log_dir))

    device_name = '/gpu:0'
    print(device_name)

    network = get_network('VGGnet_train')

    train_net(network, imdb, roidb,
              output_dir=output_dir,
              log_dir=log_dir,
              pretrained_model=os.path.join('../data/pretrain_model/VGG_imagenet.npy'),
              max_iters=int(cfg.TRAIN.max_steps),
              restore=bool(int(cfg.TRAIN.restore)))
Example #7
0
    print(('Detection took {:.3f}s for '
           '{:d} object proposals').format(timer.total_time, boxes.shape[0]))


if __name__ == '__main__':
    if os.path.exists("data/results/"):
        shutil.rmtree("data/results/")
    os.makedirs("data/results/")

    cfg_from_file('ctpn/text.yml')

    # init session
    config = tf.ConfigProto(allow_soft_placement=True)
    sess = tf.Session(config=config)
    # load network
    net = get_network("VGGnet_test")
    # load model
    print(('Loading network {:s}... '.format("VGGnet_test")), end=' ')
    saver = tf.train.Saver()

    try:
        ckpt = tf.train.get_checkpoint_state(cfg.TEST.checkpoints_path)
        print('Restoring from {}...'.format(ckpt.model_checkpoint_path),
              end=' ')
        saver.restore(sess, ckpt.model_checkpoint_path)
        print('done')
    except:
        raise 'Check your pretrained {:s}'.format(ckpt.model_checkpoint_path)

    im = 128 * np.ones((300, 300, 3), dtype=np.uint8)
    for i in range(2):