Exemplo n.º 1
0
    def snapshot(self):
        
        output_dir = get_output_path(self.imdb, None)
        if not os.path.exists(output_dir):
            os.makedirs(output_dir)

        infix = ('_' + cfg.TRAIN.SNAPSHOT_INFIX
                 if cfg.TRAIN.SNAPSHOT_INFIX != '' else '')
        filename = self.solver_param.snapshot_prefix + infix + \
                   '_iter_{:d}'.format(self.solver.iter) + '.caffemodel'
        filename = os.path.join(output_dir, filename)

        self.solver.net.save(str(filename))
        print 'Wrote snapshot to: {:s}'.format(filename)
Exemplo n.º 2
0
def test_net(net, imdb):
    num_images = len(imdb.image_index)
    output_dir = get_output_path(imdb, net)
    if not os.path.exists(output_dir):
        os.makedirs(output_dir)

    score_file = os.path.join(output_dir, 'fast_dbox_output_scores')
    roidb = imdb.roidb
    score_list = []
    batch_size = 3000
    # timers
    _t = {'im_detect': Timer(), 'misc': Timer()}
    sum_time = 0
    for i in xrange(num_images):
        im = cv2.imread(imdb.image_path_at(i))
        num_gt = len(np.nonzero(roidb[i]['gt_classes'])[0])
        boxes = roidb[i]['boxes'][num_gt:, :]
        print 'Process image {:d},{:d} boxes'.format(i, boxes.shape[0])
        _t['im_detect'].tic()

        #Pass the boxes through the net in batches
        if boxes.shape[0] % batch_size == 0:
            rid = boxes.shape[0] / batch_size
        else:
            rid = boxes.shape[0] / batch_size + 1

        for j in xrange(rid):
            start_ind = batch_size * j
            end_ind = min(start_ind + batch_size, boxes.shape[0])
            boxes_ = boxes[start_ind:end_ind]
            scores_ = im_obj_detect(net, im, boxes_)
            if (j == 0):
                scores = scores_
            else:
                scores = np.concatenate((scores, scores_), axis=0)

        _t['im_detect'].toc()
        print 'image {:d}/{:d} {:.3f}s'.format(i + 1, num_images,
                                               _t['im_detect'].average_time)
        sum_time = sum_time + _t['im_detect'].average_time
        score_list.append(scores)

    print 'Average time = {:.3f}s'.format(sum_time / num_images)
    #Save Edge boxes score in both .mat and .pkl format
    sio.savemat(score_file + '.mat', {'score_list': score_list})
    f_score = open(score_file + '.pkl', 'wb')
    cPickle.dump(score_list, f_score)
    f_score.close()
Exemplo n.º 3
0
def test_net(net, imdb):
    num_images = len(imdb.image_index)
    output_dir = get_output_path(imdb, net)
    if not os.path.exists(output_dir):
        os.makedirs(output_dir)

    score_file = os.path.join(output_dir, 'fast_dbox_output_scores')
    roidb = imdb.roidb
    score_list = []
    batch_size = 3000 
    # timers
    _t = {'im_detect' : Timer(), 'misc' : Timer()}
    sum_time = 0
    for i in xrange(num_images):
        im = cv2.imread(imdb.image_path_at(i))
        num_gt = len(np.nonzero(roidb[i]['gt_classes'])[0])
        boxes = roidb[i]['boxes'][num_gt:,:]
        print 'Process image {:d},{:d} boxes'.format(i,boxes.shape[0])
        _t['im_detect'].tic()
       
        #Pass the boxes through the net in batches 
        if boxes.shape[0] % batch_size == 0:
            rid = boxes.shape[0]/batch_size
        else:
            rid = boxes.shape[0]/batch_size+1

        for j in xrange(rid):
            start_ind = batch_size*j
            end_ind = min(start_ind+batch_size,boxes.shape[0])
            boxes_ = boxes[start_ind:end_ind]
            scores_ = im_obj_detect(net, im, boxes_)
            if (j==0):
                scores = scores_
            else:
                scores = np.concatenate((scores, scores_), axis=0)
        
        _t['im_detect'].toc()
        print 'image {:d}/{:d} {:.3f}s'.format(i+1,num_images,_t['im_detect'].average_time)
        sum_time = sum_time+_t['im_detect'].average_time
        score_list.append(scores)

    print 'Average time = {:.3f}s'.format(sum_time/num_images)
    #Save Edge boxes score in both .mat and .pkl format
    sio.savemat(score_file+'.mat', {'score_list':score_list})
    f_score = open(score_file+'.pkl','wb')
    cPickle.dump(score_list,f_score)
    f_score.close()