コード例 #1
0
    def __init__(self, project, image_set):
        imdb.__init__(self, project + '_' + image_set)
        # specific config options
        self.config = {}
        self._project = project
        self._image_set = image_set
        self._data_path = osp.join(cfg.DATA_DIR, '')
        cats = load_json(os.path.join(self._data_path, 'cats.json'))
        cats = dict({k: v['name'] for k, v in cats.items()})
        self._classes = tuple(['__background__'] + list(cats.values()))
        self._class_to_ind = dict(
            list(zip(self.classes, list(range(self.num_classes)))))
        self._class_to_cat_id = dict([(v, k) for k, v in cats.items()])
        self._image_index = self._load_image_set_index()
        # Default to roidb handler
        self.set_proposal_method('gt')
        self.competition_mode(False)

        self._images = load_json(os.path.join(self._data_path, 'images.json'))

        self._annos = load_json(
            os.path.join(self._data_path, 'annotations.json'))
        print('images: %d, annotations: %d, dataset: %d' %
              (len(self._images), len(self._annos), len(self._image_index)))
        annoted = list(self._annos.keys())

        self._image_index = list(set(self._image_index).intersection(annoted))
コード例 #2
0
ファイル: play.py プロジェクト: splendor-kill/mira
def verify_annotation(data_dir):
    cats = load_json(os.path.join(data_dir, 'cats.json'))
    img_j = load_json(os.path.join(data_dir, 'images.json'))
    anno_j = load_json(os.path.join(data_dir, 'annotations.json'))

    font = cv2.FONT_HERSHEY_SIMPLEX
    for k, v in img_j.items():
        full_name = os.path.join(data_dir, v['folder'], v['file_name'])
        img = cv2.imread(full_name)
        for cat_id in cats.keys():
            anno = anno_j[k]
            assert anno is not None
            if not cat_id in anno:
                continue
            bbs = anno[cat_id]['bbox']
            for b in bbs:
                x, y, w, h = b['x'], b['y'], b['w'], b['h']
                cv2.rectangle(img, (x, y), (x + w, y + h), (255, 0, 0), 2)
                cv2.putText(img, cats[cat_id]['name'], (x, y), font, 1, (255, 255, 0), 2)

        cv2.imshow('check annotations', img)
        k = cv2.waitKey(0)
        if k == ord('q'):
            return
コード例 #3
0
ファイル: annotate_pascal.py プロジェクト: splendor-kill/mira
def convert_to_pascal_from_coco(big_dir, annos_json, images_json, cats_json,
                                prefix, annos_dir):
    cats = load_json(cats_json)
    images = load_json(images_json)
    annos = load_json(annos_json)

    if not os.path.exists(annos_dir):
        os.makedirs(annos_dir)

    i = 0
    for k, v in annos.items():
        info = images[k]
        file_name = info['file_name']

        new_file_name_stem = '%s_%05d' % (prefix, int(k))
        new_file_name = new_file_name_stem + os.path.splitext(file_name)[-1]
        save_to_xml2(info, v, cats, new_file_name,
                     os.path.join(annos_dir, new_file_name_stem + '.xml'))

        old_file = os.path.join(big_dir, file_name)
        new_file = os.path.join(big_dir, new_file_name)
        os.rename(old_file, new_file)
        i += 1
    print('total %d files converted' % (i, ))
コード例 #4
0
    def __init__(self, project, image_set):
        imdb.__init__(self, project + '_' + image_set)
        self._project = project
        self._image_set = image_set
        self._data_path = os.path.join(cfg.DATA_DIR, 'ds_mj')
        cats = load_json(os.path.join(cfg.DATA_DIR, 'cats.json'))
        cats = dict({k: v['name'] for k, v in cats.items()})
        self._classes = tuple(['__background__'] + list(cats.values()))
        self._class_to_ind = dict(
            list(zip(self.classes, list(range(self.num_classes)))))
        self._image_ext = '.png'
        self._image_index = self._load_image_set_index()
        self.set_proposal_method('gt')
        self.config = {}

        assert os.path.exists(self._data_path), \
          'Path does not exist: {}'.format(self._data_path)
コード例 #5
0
                print()

            cv2.imshow('pic browser', image)
            k = cv2.waitKey(0)
            if k == ord('q'):                
                return True
    return False


def browse_all(file_dir, cats):
    smalls = {}
    for k, v in cats.items():
        full_name = os.path.join(cfg.data_dir, v['folder'], v['file_name'])        
        img = cv2.imread(full_name, 0)
        if img is not None:
            smalls[k] = img

    for k, v in smalls.items():
        print('broswering', cats[k]['name'])
        done = browse(file_dir, v)
        if done:
            break

    
if __name__ == '__main__':
    cfg.data_dir = '../dataset'
#     template = cv2.imread(os.path.join(cfg.data_dir, 'atomitems/b8.png'), 0)
#     browse(os.path.join(cfg.data_dir, 'bigpics'), template)
    cats = load_json(os.path.join(cfg.data_dir, 'cats.json'))
    browse_all(os.path.join(cfg.data_dir, 'bigpics'), cats)
コード例 #6
0
ファイル: gen_samples.py プロジェクト: splendor-kill/mira
def load_cats(cats_json):
    cats = load_json(cats_json)
    cats = {k: v['name'] for k, v in cats.items()}
    class_to_catid = dict([(v, k) for k, v in cats.items()])
    return cats, class_to_catid
コード例 #7
0
import os
import numpy as np
import cv2
from annotate import load_json

data_dir = '../dataset'

cats = load_json(os.path.join(data_dir, 'cats.json'))
cats = dict({k: v['name'] for k, v in cats.items()})
print('cat num:', len(cats))

annos = load_json(os.path.join(data_dir, 'annotations.json'))
print('annotation num:', len(annos))

images = load_json(os.path.join(data_dir, 'images.json'))
print('image num:', len(images))

ids = list(annos.keys())
test_ids = ids[:5]
print('following images will be tested')
print(test_ids)

print(annos[1])

for i in test_ids:
    img_info = images[i]
    full_file_name = os.path.join(data_dir, img_info['folder'],
                                  img_info['file_name'])
    image = cv2.imread(full_file_name)
    print(full_file_name)
    if image is None:
コード例 #8
0
ファイル: gui_windows.py プロジェクト: splendor-kill/mira
                              linewidth=3.,
                              alpha=0.5)))
        patches.append(
            ax.text(bbox[0] + 3, (bbox[3] + bbox[1]) / 2,
                    '{:s}'.format(class_name),
                    bbox=dict(facecolor='blue', alpha=0.4),
                    fontsize=14,
                    color='white'))
    return patches


cfg.DATA_DIR = './dataset'
cfg.ANCHOR_SCALES = [2.2, 4.2, 7.0, 7.6]
cfg.ANCHOR_RATIOS = [0.75, 0.83, 1.18, 1.33]

cats = load_json(os.path.join(cfg.DATA_DIR, 'cats.json'))
cat_ids = list(cats.keys())
CLASSES = [cats[i]['name'] for i in sorted(cat_ids)]
CLASSES = tuple(['__background__'] + CLASSES)
print('number of classes:', len(CLASSES))

NETS = {
    'vgg16': ('vgg16_faster_rcnn_iter_20000.ckpt', ),
    'res101': ('res101_faster_rcnn_iter_110000.ckpt', )
}
DATASETS = {'mahjong': ('mj_train', )}


def recognize(sess, net, im):
    """Detect object classes in an image using pre-computed object proposals."""