Esempio n. 1
0
def run_test_metric(num_imgs_list, net, sess, filename=None):
    imdb = get_imdb('voc_2007_test')
    if not filename:
        filename = 'default/res101_faster_rcnn_iter_110000'

    with timer('run_test_metric - mAP calc'):
        f = io.BytesIO()
        with stdout_redirector(f):  #this stops some meaningless info on stdout
            if len(num_imgs_list) == 1:
                num_imgs = num_imgs_list[0]
                if num_imgs == len(imdb.image_index):
                    mAP = test_net(sess,
                                   net,
                                   imdb,
                                   filename,
                                   max_per_image=100)
                    mAP_dict = {num_imgs: mAP}
                else:
                    sampler = VOCImgSampler()
                    sample_images = sampler.get_imgs(num_imgs)
                    sample_names_dict = {num_imgs: sample_images}
                    mAP_dict = test_net_with_sample(
                        sess,
                        net,
                        imdb,
                        filename,
                        sample_images,
                        max_per_image=100,
                        sample_names_dict=sample_names_dict)
            else:
                sampler = VOCImgSampler()
                sample_names_dict = sampler.get_nested_img_lists(num_imgs_list)
                largest_num_imgs = (sorted(num_imgs_list))[-1]
                sample_images = sample_names_dict[largest_num_imgs]
                mAP_dict = test_net_with_sample(
                    sess,
                    net,
                    imdb,
                    filename,
                    sample_images,
                    max_per_image=100,
                    sample_names_dict=sample_names_dict)
            return mAP_dict
Esempio n. 2
0
    def run_test_metric(self, num_imgs):
        imdb = get_imdb('voc_2007_test')
        filename = 'default/res101_faster_rcnn_iter_110000'

        if num_imgs == len(imdb.image_index):
            mAP = test_net(self._sess,
                           self._net_sep,
                           imdb,
                           filename,
                           max_per_image=100)
        else:
            sampler = VOCImgSampler()
            sample_images = sampler.get_imgs(num_imgs)
            mAP = test_net_with_sample(self._sess,
                                       self._net_sep,
                                       imdb,
                                       filename,
                                       sample_images,
                                       max_per_image=100)
        return mAP
Esempio n. 3
0
        net = mobilenetv1()
    elif args.net == 'SGRN':
        net = resnetGCN(num_layers=101)
    else:
        raise NotImplementedError

    # load model
    net.create_architecture(imdb.num_classes,
                            tag='default',
                            anchor_scales=cfg.ANCHOR_SCALES,
                            anchor_ratios=cfg.ANCHOR_RATIOS)

    net.eval()
    if not torch.cuda.is_available():
        net._device = 'cpu'
    net.to(net._device)

    if args.model:
        print(('Loading model check point from {:s}').format(args.model))
        net.load_state_dict(
            torch.load(args.model, map_location=lambda storage, loc: storage))
        print('Loaded.')
    else:
        print(('Loading initial weights from {:s}').format(args.weight))
        print('Loaded.')
    # print(('Loading model check point from {:s}').format(model))
    # net.load_state_dict(
    #     torch.load(model, map_location=lambda storage, loc: storage))
    print('Loaded.')
    test_net(net, imdb, filename, max_per_image=100)  #args.max_per_image)
Esempio n. 4
0
    elif args.net == 'mobile':
        net = mobilenetv1()
    else:
        raise NotImplementedError

    # load model
    net.create_architecture("TEST",
                            imdb.num_classes,
                            tag='default',
                            anchor_scales=cfg.ANCHOR_SCALES,
                            anchor_ratios=cfg.ANCHOR_RATIOS)

    if args.model:
        print(('Loading model check point from {:s}').format(args.model))
        saver = tf.train.Saver()
        saver.restore(sess, args.model)
        print('Loaded.')
    else:
        print(('Loading initial weights from {:s}').format(args.weight))
        sess.run(tf.global_variables_initializer())
        print('Loaded.')

    test_net(sess,
             net,
             imdb,
             filename,
             max_per_image=args.max_per_image,
             eccv14=args.eccv14)

    sess.close()
Esempio n. 5
0
    net = resnet_C3C4(batch_size=cfg.TRAIN.IMS_PER_BATCH, num_layers=101)
  elif args.net == 'res101_C3-R-cbam':
    net = resnet_C3Rcbam(batch_size=cfg.TRAIN.IMS_PER_BATCH, num_layers=101)
  elif args.net == 'res101_R-cbam':
    net = resnet_Rcbam(batch_size=cfg.TRAIN.IMS_PER_BATCH, num_layers=101)
  else:
    raise NotImplementedError

  # load model
  net.create_architecture(sess, "TEST", imdb.num_classes, tag='default',
                          anchor_scales=cfg.ANCHOR_SCALES,
                          anchor_ratios=cfg.ANCHOR_RATIOS)

  if args.model:
    print(('Loading model check point from {:s}').format(args.model))
    saver = tf.train.Saver()
    saver.restore(sess, args.model)
    #variables=tf.get_collection(tf.GraphKeys.GLOBAL_VARIABLES)
    #pdb.set_trace()
    #for v in variables:
      #print('Varibles: %s' % v.name)
    print('Loaded.')
  else:
    print(('Loading initial weights from {:s}').format(args.weight))
    sess.run(tf.global_variables_initializer())
    print('Loaded.')

  test_net(sess, net, imdb, filename, max_per_image=args.max_per_image,thresh=0)

  sess.close()
Esempio n. 6
0
        #if im_name[0]=='T':
        print('~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~')
        print('Demo for data/demo/' + testset + '/' + im_name)
        im_rgb = im_name
        demo(sess, net, im_name, im_rgb, testset)
    ########## calculate MAP
    if map_or_not == 'true':
        conf_threshs = [0.5]
        test_file = open('test_result_conv4.txt', 'w')
        for conf_thresh in conf_threshs:
            pdb.set_trace()
            test_net(sess,
                     net,
                     imdb,
                     filename,
                     test_file,
                     testset,
                     method,
                     max_per_image=100,
                     thresh=conf_thresh)
            test_file.write('\n')
        test_file.close()

        if os.path.exists(
                '/home/yangfan/low_visibility_object_recognition_system_V2.0/dual_modal_faster_rcnn/data/EELABdevkit/annotations_cache/imagesetfile_annots.pkl'
        ):
            os.remove(
                '/home/yangfan/low_visibility_object_recognition_system_V2.0/dual_modal_faster_rcnn/data/EELABdevkit/annotations_cache/imagesetfile_annots.pkl'
            )

    plt.show()
Esempio n. 7
0
        net = memory.mobilenetv1_memory()
    else:
        raise NotImplementedError

    # load model
    net.create_architecture("TEST",
                            imdb.num_classes,
                            imdb.num_predicates,
                            tag='default')

    if args.model:
        print(('Loading model check point from {:s}').format(args.model))
        saver = tf.train.Saver()
        saver.restore(sess, args.model)
        print('Loaded.')
    else:
        print(('Loading initial weights from {:s}').format(args.weight))
        sess.run(tf.global_variables_initializer())
        print('Loaded.')

    test_net(sess,
             net,
             imdb,
             roidb,
             filename,
             args.visualize,
             iter_test=iter_test,
             mode='all')

    sess.close()
Esempio n. 8
0
        return features, (question_vectors, answer_vectors, candidate_vectors)
    else:
        return features, (question_vectors, answer_vectors)


if __name__ == '__main__':
    args = parse_args()

    print('Called with args: ')
    print(args)

    if args.cfg_file is not None:
        cfg_from_file(args.cfg_file)
    #if args.set_cfgs is not None:
    #    cfg_from_list(args.set_cfgs)

    print("Using config:")
    print(cfg)

    output_dir = get_output_dir(args.dataset_name, args.tag)
    print('Output will be saved to `{:s}`'.format(output_dir))
    tb_dir = get_output_tb_dir(args.dataset_name, args.tag)
    print('TensorFlow summaries will be saved to `{:s}`'.format(tb_dir))

    test_reader = tf_reader('/data/mm/dataset/activityNet/test.tfrecords',
                            cfg['TEST'])

    net = Network(test_reader.dataset.output_types,
                  test_reader.dataset.output_shapes)
    test_net(net, test_reader, output_dir, tb_dir)
Esempio n. 9
0
#model = None
model = '/home/vador/Documents/project/AI/drl-rpn-tf-video/output-weights/voc_2007_train/output/default/voc_2007_train/vgg16_drl_rpn_iter_1.ckpt'
#model = '/home/vador/Documents/project/AI/drl-rpn-tf-video/drl-rpn-voc2007-2012-trainval/vgg16_drl_rpn_iter_110000.ckpt'
weight = 'weights3d'

if model:
    filename = os.path.splitext(os.path.basename(model))[0]
else:
    filename = weight

with tf.Session(config=tfconfig) as sess:
    # load model
    if model:
        print(('Loading model check point from {:s}').format(model))
        # Why the following line is needed ?? if i remove it, some var are not initialized ! WHY ?
        #sess.run(tf.global_variables_initializer())
        saver = tf.train.Saver()  #import_meta_graph(model + '.meta')
        saver.restore(sess, model)
        for var in tf.global_variables():
            if var.name == 'h_relu_weights_video:0':
                print(var.name)
                print(var.shape)

    else:
        print(('Loading initial weights from {:s}').format(weight))
        sess.run(tf.global_variables_initializer())
        print('Loaded.')

    test_net(sess, net, imdb, filename)
    def launch_test(self, conf, hash_model):
        '''
        '''
        args = {}
        args['cfg_file'] = conf.frcnn_cfg
        args['weight'] = conf.starting_weights
        args['model'] = hash_model
        args['imdb_name'] = conf.valid_set
        args['comp_mode'] = False
        args['tag'] = conf.frcnn_tag
        args['net'] = conf.frcnn_net
        args['set_cfgs'] = None
        args['max_per_image'] = 5

        print('Called with args:')
        print(args)

        if args['cfg_file'] is not None:
            cfg_from_file(argsargs['cfg_file'])
        if args['set_cfgs'] is not None:
            cfg_from_list(args['set_cfgs'])

        print('Using config:')
        pprint.pprint(cfg)

        # if has model, get the name from it
        # if does not, then just use the inialization weights
        if args['model']:
            filename = os.path.splitext(os.path.basename(args['model']))[0]
        else:
            filename = os.path.splitext(os.path.basename(args['weight']))[0]

        tag = args['tag']
        tag = tag if tag else 'default'
        filename = tag + '/' + filename

        # TODO This is really bad but it works, I'm sincerely sorry
        conf_copy = copy.deepcopy(conf)
        conf_copy.train_set = conf_copy.valid_set
        imdb = get_imdb(args['imdb_name'], conf_copy)
        print(args['imdb_name'])
        imdb.competition_mode(args['comp_mode'])

        tfconfig = tf.ConfigProto(allow_soft_placement=True)
        tfconfig.gpu_options.allow_growth = True

        # init session
        sess = tf.Session(config=tfconfig)
        # load network
        if args['net'] == 'vgg16':
            net = vgg16(batch_size=1)
        elif args['net'] == 'res50':
            net = resnetv1(batch_size=1, num_layers=50)
        elif args['net'] == 'res101':
            net = resnetv1(batch_size=1, num_layers=101)
        elif args['net'] == 'res152':
            net = resnetv1(batch_size=1, num_layers=152)
        elif args['net'] == 'mobile':
            net = mobilenetv1(batch_size=1)
        else:
            raise NotImplementedError

        # load model
        net.create_architecture(sess,
                                "TEST",
                                imdb.num_classes,
                                tag='default',
                                anchor_scales=cfg.ANCHOR_SCALES,
                                anchor_ratios=cfg.ANCHOR_RATIOS)

        if args['model']:
            print(
                ('Loading model check point from {:s}').format(args['model']))
            saver = tf.train.Saver()
            saver.restore(sess, args['model'])
            print('Loaded.')
        else:
            print(('Loading initial weights from {:s}').format(args['weight']))
            sess.run(tf.global_variables_initializer())
            print('Loaded.')

        test_net(sess,
                 net,
                 imdb,
                 filename,
                 max_per_image=args['max_per_image'])

        sess.close()
            raise NotImplementedError
    elif(cfg.NET_TYPE == 'lidar'):
        net = lidarnet(num_layers=101)
    # load model
    if(cfg.NET_TYPE == 'lidar'):
        #TODO: Magic numbers, need to sort this out to flow through 3d anchor gen properly
        net.create_architecture(
            db.num_classes,
            tag='default',
            anchor_scales=cfg.LIDAR.ANCHOR_SCALES,
            anchor_ratios=cfg.LIDAR.ANCHOR_ANGLES)
    elif(cfg.NET_TYPE == 'image'):
        net.create_architecture(
            db.num_classes,
            tag='default',
            anchor_scales=cfg.ANCHOR_SCALES,
            anchor_ratios=cfg.ANCHOR_RATIOS)

    net.eval()

    print(('Loading initial weights from {:s}').format(args.weights_file))
    #file_dir = os.path.join(cfg.DATA_DIR,args.db_name,'weights',args.weights_file)
    params = torch.load(args.weights_file, map_location=lambda storage, loc: storage)
    net.load_state_dict(params)
    print('Loaded.')
    if not torch.cuda.is_available():
        net._device = 'cpu'
    net.to(net._device)
    #TODO: Fix stupid output directory bullshit
    test_net(net, db, args.out_dir, max_dets=args.max_num_dets, mode='val',thresh=0.5,draw_det=True,eval_det=True)
Esempio n. 12
0
def testing(imdbval_name, classes, cfg_file, model, weights, tag, net,
            max_per_image):

    __sets = {}

    for split in ['train', 'val', 'trainval', 'test']:
        name = imdbval_name.split('_')[0] + '_{}'.format(split)
        __sets[name] = (lambda split=split: dataset(split, classes,
                                                    name.split('_')[0]))

    if cfg_file is not None:
        cfg_from_file(cfg_file)

    print('Using config:')
    pprint.pprint(cfg)

    # if has model, get the name from it
    # if does not, then just use the inialization weights
    if model:
        filename = os.path.splitext(os.path.basename(model))[0]
    else:
        filename = os.path.splitext(os.path.basename(weights))[0]

    tag = tag if tag else 'default'
    filename = tag + '/' + filename
    imdb = get_imdb(imdbval_name, __sets)

    tfconfig = tf.ConfigProto(allow_soft_placement=True)
    tfconfig.gpu_options.allow_growth = True

    # init session
    sess = tf.Session(config=tfconfig)
    # load network
    if net == 'vgg16':
        net = vgg16(batch_size=1)
    elif net == 'res50':
        net = resnetv1(batch_size=1, num_layers=50)
    elif net == 'res101':
        net = resnetv1(batch_size=1, num_layers=101)
    elif net == 'res152':
        net = resnetv1(batch_size=1, num_layers=152)
    else:
        raise NotImplementedError

    # load model
    net.create_architecture(sess,
                            "TEST",
                            imdb.num_classes,
                            tag='default',
                            anchor_scales=cfg.ANCHOR_SCALES,
                            anchor_ratios=cfg.ANCHOR_RATIOS)

    if model:
        print(('Loading model check point from {:s}').format(model))
        saver = tf.train.Saver()
        saver.restore(sess, model)
        print('Loaded.')
    else:
        print(('Loading initial weights from {:s}').format(weights))
        sess.run(tf.global_variables_initializer())
        print('Loaded.')

    test_net(sess, net, imdb, filename, max_per_image=max_per_image)

    sess.close()
Esempio n. 13
0
        raise NotImplementedError

    # load model
    net.create_architecture("TEST",
                            imdb.num_classes,
                            tag='default',
                            anchor_scales=cfg.ANCHOR_SCALES,
                            anchor_ratios=cfg.ANCHOR_RATIOS)

    if args.model:
        print(('Loading model check point from {:s}').format(args.model))
        saver = tf.train.Saver()
        saver.restore(sess, args.model)
        print('Loaded.')
    else:
        print(('Loading initial weights from {:s}').format(args.weight))
        sess.run(tf.global_variables_initializer())
        print('Loaded.')

    test_net(sess,
             net,
             imdb,
             filename,
             max_per_image=args.max_per_image,
             roidb=roidb)
    # ids = [262145, 131074, 131075, 393221, 393223, 393224, 524297, 393227]
    #for imgs in ids:
    #  demo.demo(sess, net, imgs)
    #plt.show()
    sess.close()
Esempio n. 14
0
    elif args.net == 'res101':
        net = resnetv1(num_layers=101)
    elif args.net == 'res152':
        net = resnetv1(num_layers=152)
    elif args.net == 'mobile':
        net = mobilenetv1()
    else:
        raise NotImplementedError

    # load model
    net.create_architecture(imdb.num_classes,
                            tag='default',
                            anchor_scales=cfg.ANCHOR_SCALES,
                            anchor_ratios=cfg.ANCHOR_RATIOS)

    net.eval()
    if not torch.cuda.is_available():
        net._device = 'cpu'
    net.to(net._device)

    if args.model:
        print(('Loading model check point from {:s}').format(args.model))
        net.load_state_dict(
            torch.load(args.model, map_location=lambda storage, loc: storage))
        print('Loaded.')
    else:
        print(('Loading initial weights from {:s}').format(args.weight))
        print('Loaded.')

    test_net(net, imdb, roidb, filename, max_per_image=args.max_per_image)
Esempio n. 15
0
        net = memory.resnetv1_memory(num_layers=101)
    elif net_base == 'res152':
        net = memory.resnetv1_memory(num_layers=152)
    elif net_base == 'mobile':
        net = memory.mobilenetv1_memory()
    else:
        raise NotImplementedError

    # load model
    net.create_architecture("TEST", imdb.num_classes, tag='default')

    if args.model:
        print(('Loading model check point from {:s}').format(args.model))
        saver = tf.train.Saver()
        saver.restore(sess, args.model)
        print('Loaded.')
    else:
        print(('Loading initial weights from {:s}').format(args.weight))
        sess.run(tf.global_variables_initializer())
        print('Loaded.')

    test_net(sess,
             net,
             imdb,
             imdb.roidb,
             filename,
             args.visualize,
             iter_test=iter_test)

    sess.close()
Esempio n. 16
0
        net = resnetv1(num_layers=152)
    elif args.net == 'mobile':
        net = mobilenetv1()
    else:
        raise NotImplementedError

    # load model
    net.create_architecture(imdb.num_classes,
                            tag='default',
                            anchor_scales=cfg.ANCHOR_SCALES,
                            anchor_ratios=cfg.ANCHOR_RATIOS)

    net.eval()
    if not torch.cuda.is_available():
        net._device = 'cpu'
    net.to(net._device)

    if args.model:
        print(('Loading model check point from {:s}').format(args.model))
        net.load_state_dict(
            torch.load(args.model, map_location=lambda storage, loc: storage))
        # net.load_state_dict(
        #     torch.load('output/vgg16/coco_2017_val/default/vgg16_faster_rcnn_iter_20000.pth',
        #     map_location=lambda storage, loc: storage))
        print('Loaded.')
    else:
        print(('Loading initial weights from {:s}').format(args.weight))
        print('Loaded.')

    test_net(net, imdb, filename, max_per_image=args.max_per_image, thresh=.20)
Esempio n. 17
0
    elif args.net == 'mobile':
        net = mobilenetv1()
    else:
        raise NotImplementedError

    # load model
    net.create_architecture(imdb.num_classes,
                            tag='default',
                            anchor_scales=cfg.ANCHOR_SCALES,
                            anchor_ratios=cfg.ANCHOR_RATIOS)

    net.eval()
    net.cuda()
    if cfg.TEST.CLEAN_PRE_RESULT:
        if args.model:
            print(('Loading model check point from {:s}').format(args.model))
            model_dict = torch.load(args.model)
            print(model_dict.keys())
            print(model_dict['vgg.classifier.0.weight'].shape)
            net.load_state_dict(model_dict)
            print('Loaded.')
        else:
            print(('Loading initial weights from {:s}').format(args.weight))
            print('Loaded.')

    test_net(net,
             imdb,
             filename,
             max_per_image=args.max_per_image,
             clean_pre_result=cfg.TEST.CLEAN_PRE_RESULT)
Esempio n. 18
0
    sess = tf.Session(config=tfconfig)



    net = resnetv1(num_layers=101)

    # load model
    net.create_architecture(sess, "TEST", imdb.num_classes, tag='default',
                            anchor_scales=cfg.ANCHOR_SCALES,
                            anchor_ratios=cfg.ANCHOR_RATIOS)

    print(('Loading model check point from {:s}').format(args.model))
    saver = tf.train.Saver()
    saver.restore(sess, args.model)

    test_net(sess, net, imdb, filename, max_per_image=args.max_per_image)
    # for var in tf.all_variables():
    #     print(var.op.name)
    #     print(sess.run(var))
    # np.random.seed(cfg.RNG_SEED)
    # """Test a Fast R-CNN network on an image database."""
    # num_images = len(imdb.image_index)
    # # all detections are collected into:
    # #  all_boxes[cls][image] = N x 5 array of detections in
    # #  (x1, y1, x2, y2, score)
    # all_boxes = [[[] for _ in range(num_images)]
    #              for _ in range(imdb.num_classes)]
    #
    # output_dir = get_output_dir(imdb, filename)
    # # im = cv2.imread('/home/aurora/workspaces/data/voc/voc2007/VOC2007/JPEGImages/006258.jpg')
    # # im = cv2.imread('/home/aurora/workspaces/PycharmProjects/tensorflow/tf_rfcn/data/VOCdevkit2007/VOC2007/JPEGImages/000001.jpg')
Esempio n. 19
0
        net = mobilenetv1()
    else:
        raise NotImplementedError

    # load model
    net.create_architecture("TEST",
                            imdbs[0].num_classes,
                            tag='default',
                            anchor_scales=cfg.ANCHOR_SCALES,
                            anchor_ratios=cfg.ANCHOR_RATIOS)

    if args.model:
        print(('Loading model check point from {:s}').format(args.model))
        saver = tf.train.Saver()
        saver.restore(sess, args.model)
        print('Loaded.')
    else:
        print(('Loading initial weights from {:s}').format(args.weight))
        sess.run(tf.global_variables_initializer())
        print('Loaded.')

    test_net(sess,
             net,
             imdbs,
             filename,
             max_per_image=args.max_per_image,
             thresh_nms=args.threshold_nms,
             thresh_map=args.threshold_map)

    sess.close()
    tag = 'default/rgh'
    model = '/media/rgh/rgh-data/PycharmProjects/cvpr2018/output/vgg16/Lip_320_train/default/' \
                       + 'vgg16_faster_rcnn_iter_70000.pth'
    cfg.ANCHOR_SCALES = [4, 8, 16, 32]
    cfg.ANCHOR_RATIOS = [0.5, 1, 2]
    #cfg.HAS_PARSING_LABEL = False
    cfg.POOLING_MODE = 'crop'
    cfg.FC6_IN_CHANNEL = 512
    cfg.TEST.CLEAN_PRE_RESULT = True
    print('Using config:')
    pprint.pprint(cfg)
    imdb = get_imdb(imdb_name)
    net = vgg16()
    net.create_architecture(imdb.num_classes,
                            tag='default',
                            anchor_scales=cfg.ANCHOR_SCALES,
                            anchor_ratios=cfg.ANCHOR_RATIOS)
    net.eval()
    net.cuda()

    model_dict = torch.load(model)
    print(model_dict.keys())
    print(model_dict['vgg.classifier.0.weight'].shape)
    net.load_state_dict(model_dict)

    test_net(net,
             imdb,
             tag,
             max_per_image=100,
             clean_pre_result=cfg.TEST.CLEAN_PRE_RESULT)
Esempio n. 21
0
    if False:
        # tensor flow conf
        tfconfig = tf.ConfigProto(allow_soft_placement=True)
        tfconfig.gpu_options.allow_growth = True

        # init session
        session = tf.Session(config=tfconfig)
        # load model
        net.create_architecture("TEST", imdb.num_classes, tag='default',
                                anchor_scales=cfg.ANCHOR_SCALES,
                                anchor_ratios=cfg.ANCHOR_RATIOS)

        if args.model:
            print('Loading model check point from {:s}'.format(args.model))
            saver = tf.train.Saver()
            saver.restore(session, args.model)
            print('Loaded.')
        else:
            print('Loading initial weights from {:s}'.format(args.weight))
            session.run(tf.global_variables_initializer())
            print('Loaded.')

        model = FasterRCNN(session, net, imdb, max_per_image=args.max_per_image)
    else:
        model = Yolo(imdb)

    test_net(model, imdb, filename)


    session.close()
Esempio n. 22
0
    else:
        raise NotImplementedError

    # load model
    net.create_architecture(sess,
                            "TEST",
                            imdb.num_classes,
                            tag='default',
                            anchor_scales=cfg.ANCHOR_SCALES,
                            anchor_ratios=cfg.ANCHOR_RATIOS)

    if args.model:
        print(('Loading model check point from {:s}').format(args.model))
        saver = tf.train.Saver()
        saver.restore(sess, args.model)
        print('Loaded.')
    else:
        print(('Loading initial weights from {:s}').format(args.weight))
        sess.run(tf.global_variables_initializer())
        print('Loaded.')

    test_net(sess,
             net,
             imdb,
             filename,
             max_per_image=args.max_per_image,
             conf_thresh=conf_thresh,
             iou_thresh=iou_thresh)

    sess.close()
Esempio n. 23
0
    weights_path = os.path.join(folder_path,weights_name)
    np.save(weights_path, dic)
    print 'The weights are saved in {}'.format(weights_path)

    '''
    load the new weigts to a new graph,
    test the pruned network
    '''
    with tf.Graph().as_default() as g2:
        with tf.Session(config=tfconfig,graph=g2).as_default() as sess:
            #load the new graph
            net = vgg16(batch_size=1)
            net.create_architecture(sess,'TEST',num_classes,tag='default',
                                    anchor_scales = [8,16,32],
                                    filter_num = new_filter_num)

            # load the new weights from npy file
            weights_dic = np.load(weights_path).item()

            for name_scope in weights_dic:
                with tf.variable_scope(name_scope,reuse = True):
                    for name in weights_dic[name_scope]:
                        var = tf.get_variable(name)
                        sess.run(var.assign(weights_dic[name_scope][name]['value']))
                        print 'assign pretrain model to {}/{}'.format(name_scope,name)

            # test the new model
            imdb = get_imdb('voc_2007_test')
            filename = 'demo_pruning'
            test_net(sess, net, imdb, filename, max_per_image=100)
Esempio n. 24
0
        net = resnetv1_ssh(num_layers=50)
    elif args.backbone == 'res101':
        net = resnetv1_ssh(num_layers=101)
    elif args.backbone == 'res152':
        net = resnetv1_ssh(num_layers=152)
    elif args.backbone == 'mobile':
        net = mobilenetv1_ssh()
    elif args.backbone == 'mobile_v2':
        net = mobilenetv2_ssh()
    else:
        raise NotImplementedError

    # load model
    net.create_architecture("TEST", imdb.num_classes, tag=tag,
                            anchor_scales=cfg.ANCHOR_SCALES,
                            anchor_ratios=cfg.ANCHOR_RATIOS)

    if args.model:
        print(('Loading model check point from {:s}').format(args.model))
        saver = tf.train.Saver()
        saver.restore(sess, args.model)
        print('Loaded.')
    else:
        print(('Loading initial weights from {:s}').format(args.weight))
        sess.run(tf.global_variables_initializer())
        print('Loaded.')

    test_net(sess, net, imdb, filename, max_per_image=args.max_per_image)

    sess.close()
Esempio n. 25
0
        net = vgg16()
    elif args.net == 'res50':
        net = resnetv1(num_layers=50)
    elif args.net == 'res101':
        net = resnetv1(num_layers=101)
    elif args.net == 'res152':
        net = resnetv1(num_layers=152)
    elif args.net == 'mobile':
        net = mobilenetv1()
    else:
        raise NotImplementedError

    # load model
    net.create_architecture("TEST", imdb.num_classes, tag='default',
                            anchor_scales=cfg.ANCHOR_SCALES,
                            anchor_ratios=cfg.ANCHOR_RATIOS)
    net.create_training_testing_vars()

    if args.model:
        print(('Loading model check point from {:s}').format(args.model))
        saver = tf.train.Saver()
        saver.restore(sess, args.model)
        print('Loaded.')
    else:
        print(('Loading initial weights from {:s}').format(args.weight))
        sess.run(tf.global_variables_initializer())
        print('Loaded.')
    test_net(sess, net, imdb, filename, max_per_image=args.max_per_image, annot_file_tag=wait_name)

    sess.close()