コード例 #1
0
ファイル: dtdseg.py プロジェクト: bonyuta0204/NetDissec
 def resolve_segmentation(cls, m, categories=None):
     filename, tnumbers = m
     result = {}
     if wants('texture', categories):
         result['texture'] = tnumbers
     if wants('color', categories):
         result['color'] = colorname.label_major_colors(
             imread(filename)) + 1
     arrs = [a for a in result.values() if numpy.shape(a) >= 2]
     shape = arrs[0].shape[-2:] if arrs else (1, 1)
     return result, shape
コード例 #2
0
 def resolve_segmentation(cls, m, categories=None):
     result = {}
     if wants('scene', categories):
         result['scene'] = m['scene']
     if wants('part', categories):
         result['part'] = load_parts(m)
     if wants('object', categories):
         result['object'] = load_segmentation(m)
     if wants('color', categories):
         result['color'] = colorname.label_major_colors(load_image(m)) + 1
     arrs = [a for a in result.values() if numpy.shape(a) >= 2]
     shape = arrs[0].shape[-2:] if arrs else (1, 1)
     return result, shape
コード例 #3
0
ファイル: pascalseg.py プロジェクト: firstmover/NetDissect
 def resolve_segmentation(cls, m, categories=None):
     directory, version, partdir, contextdir, part_key, seg_fn = m
     result = {}
     if wants('color', categories):
         jpeg_fn = os.path.join(directory, version, 'JPEGImages',
                                seg_fn.replace('.mat', '.jpg'))
         result['color'] = colorname.label_major_colors(imread(jpeg_fn)) + 1
     if wants('part', categories):
         objs, parts = load_parts_segmentation(
             os.path.join(directory, partdir, 'Annotations_Part', seg_fn),
             part_key)  # (ignore object layer the from parts segmentation)
         result['part'] = parts
     if wants('object', categories):
         result['object'] = loadmat(
             os.path.join(directory, contextdir, 'trainval',
                          seg_fn))['LabelMap']
     arrs = [a for a in result.values() if numpy.shape(a) >= 2]
     shape = arrs[0].shape[-2:] if arrs else (1, 1)
     return result, shape
コード例 #4
0
 def resolve_segmentation(cls, m, categories=None):
     directory, row, supply = m
     fnjpg = os.path.join(directory, row['photo'])
     result = {}
     if wants('material', categories) and wants('material', supply):
         mats = {}
         for material, fn in row['segments']:
             mask = imread(os.path.join(directory, fn)) != 0
             if material not in mats:
                 mats[material] = mask
             else:
                 mats[material] |= mask
         allmats = numpy.concatenate([
             material * fn[None,:,:]
             for material, fn in sorted(mats.items(), key=lambda x: x[0])])
         result['material'] = allmats
     if wants('color', categories) and wants('color', supply):
         result['color'] = colorname.label_major_colors(imread(fnjpg)) + 1
     arrs = [a for a in result.values() if numpy.shape(a) >= 2]
     shape = arrs[0].shape[-2:] if arrs else (1, 1)
     return result, shape
コード例 #5
0
    def resolve_segmentation(cls, m, categories=None):
        directory, row, scene, supply = m
        photo_id = int(row['photo_id'])
        fnpng = os.path.join(directory, 'photos-labels', '%d.png' % photo_id)
        fnjpg = os.path.join(directory, 'photos', '%d.jpg' % photo_id)

        if wants('material', categories) or wants('object', categories):
            labels = imread(fnpng)
            # Opensurfaces has some completely unlabled images; omit them.
            # TODO: figure out how to do this nicely in the joiner instead.
            # if labels.max() == 0:
            #     return {}
        result = {}
        if wants('scene', categories) and wants('scene', supply):
            result['scene'] = scene
        if wants('material', categories) and wants('material', supply):
            result['material'] = labels[:, :, 0]
        if wants('object', categories) and wants('object', supply):
            result['object'] = labels[:, :, 1]
        if wants('color', categories) and wants('color', supply):
            result['color'] = colorname.label_major_colors(imread(fnjpg)) + 1
        arrs = [a for a in result.values() if numpy.shape(a) >= 2]
        shape = arrs[0].shape[-2:] if arrs else (1, 1)
        return result, shape