def __init__(self):
        super(self.__class__, self).__init__()

        # set target_names
        self.target_names = ['background'] + \
            [datum['name']
             for datum in jsk_apc2016_common.get_object_data()]
        n_class = len(self.target_names)
        assert n_class == 40

        # load model
        self.gpu = rospy.get_param('~gpu', 0)
        chainermodel = rospy.get_param('~chainermodel')
        self.model = FCN32s(n_class=n_class)
        S.load_hdf5(chainermodel, self.model)
        if self.gpu != -1:
            self.model.to_gpu(self.gpu)
        jsk_logwarn('>> Model is loaded <<')

        while True:
            self.tote_contents = rospy.get_param('~tote_contents', None)
            if self.tote_contents is not None:
                break
            logwarn_throttle(10, 'param ~tote_contents is not set. Waiting..')
            rospy.sleep(0.1)
        self.label_names = rospy.get_param('~label_names')
        jsk_logwarn('>> Param is set <<')

        self.pub = self.advertise('~output', Image, queue_size=1)
        self.pub_debug = self.advertise('~debug', Image, queue_size=1)
Example #2
0
def get_class_id_map():
    cls_names_16 = ['__background__']
    cls_names_16 += [d['name'] for d in jsk_apc2016_common.get_object_data()]

    cls_names_17 = get_object_names()

    cls_name_16_to_17 = {
        '__background__': '__shelf__',
        # 'womens_knit_gloves': 'black_fashion_gloves',
        'crayola_24_ct': 'crayons',
        'scotch_duct_tape': 'duct_tape',
        'expo_dry_erase_board_eraser': 'expo_eraser',
        'hanes_tube_socks': 'hanes_socks',
        'laugh_out_loud_joke_book': 'laugh_out_loud_jokes',
        'rolodex_jumbo_pencil_cup': 'mesh_cup',
        'ticonderoga_12_pencils': 'ticonderoga_pencils',
        'kleenex_tissue_box': 'tissue_box',
    }

    print('{:>28} -> {:<15}'.format('apc2016', 'arc2017'))
    print('-' * 53)
    cls_id_16_to_17 = {}
    for n16, n17 in cls_name_16_to_17.items():
        assert n16 in cls_names_16
        assert n17 in cls_names_17
        print('{:>28} -> {:<15}'.format(n16, n17))
        cls_id_16_to_17[cls_names_16.index(n16)] = cls_names_17.index(n17)

    return cls_id_16_to_17
Example #3
0
    def __init__(self):
        self.json_file = rospy.get_param('~json', None)
        self.is_apc2016 = rospy.get_param('~is_apc2016', True)
        self.gripper = rospy.get_param('~gripper', 'gripper2016')
        self.max_weight = rospy.get_param('~max_weight', -1)
        if self.json_file is None:
            rospy.logerr('must set json file path to ~json')
            return
        data = json.load(open(self.json_file))
        self.work_order = {}
        work_order_list = []
        for order in data['work_order']:
            bin_ = order['bin'].split('_')[1].lower()
            self.work_order[bin_] = order['item']
            work_order_list.append({'bin': bin_, 'item': order['item']})
        rospy.set_param('~work_order', work_order_list)

        self.object_data = None
        if self.is_apc2016:
            self.object_data = jsk_apc2016_common.get_object_data()

        self.bin_contents = jsk_apc2016_common.get_bin_contents(param='~bin_contents')

        self.msg = self.get_work_order_msg()

        self.pub_left = rospy.Publisher(
            '~left_hand', WorkOrderArray, queue_size=1)
        self.pub_right = rospy.Publisher(
            '~right_hand', WorkOrderArray, queue_size=1)
        rospy.Service('~update_target', UpdateTarget, self._update_target_cb)
        self.updated = False
        rospy.Timer(rospy.Duration(rospy.get_param('~duration', 1)), self._timer_cb)
    def __init__(self):
        super(self.__class__, self).__init__()

        # set target_names
        self.target_names = ['background'] + \
            [datum['name']
             for datum in jsk_apc2016_common.get_object_data()]
        n_class = len(self.target_names)
        assert n_class == 40

        # load model
        self.gpu = rospy.get_param('~gpu', 0)
        chainermodel = rospy.get_param('~chainermodel')
        self.model = FCN32s(n_class=n_class)
        S.load_hdf5(chainermodel, self.model)
        if self.gpu != -1:
            self.model.to_gpu(self.gpu)
        jsk_logwarn('>> Model is loaded <<')

        while True:
            self.tote_contents = rospy.get_param('~tote_contents', None)
            if self.tote_contents is not None:
                break
            logwarn_throttle(10, 'param ~tote_contents is not set. Waiting..')
            rospy.sleep(0.1)
        self.label_names = rospy.get_param('~label_names')
        jsk_logwarn('>> Param is set <<')

        self.pub = self.advertise('~output', Image, queue_size=1)
        self.pub_debug = self.advertise('~debug', Image, queue_size=1)
def get_class_id_map():
    cls_names_16 = ['__background__']
    cls_names_16 += [d['name'] for d in jsk_apc2016_common.get_object_data()]

    cls_names_17 = get_object_names()

    cls_name_16_to_17 = {
        '__background__': '__shelf__',
        # 'womens_knit_gloves': 'black_fashion_gloves',
        'crayola_24_ct': 'crayons',
        'scotch_duct_tape': 'duct_tape',
        'expo_dry_erase_board_eraser': 'expo_eraser',
        'hanes_tube_socks': 'hanes_socks',
        'laugh_out_loud_joke_book': 'laugh_out_loud_jokes',
        'rolodex_jumbo_pencil_cup': 'mesh_cup',
        'ticonderoga_12_pencils': 'ticonderoga_pencils',
        'kleenex_tissue_box': 'tissue_box',
    }

    print('{:>28} -> {:<15}'.format('apc2016', 'arc2017'))
    print('-' * 53)
    cls_id_16_to_17 = {}
    for n16, n17 in cls_name_16_to_17.items():
        assert n16 in cls_names_16
        assert n17 in cls_names_17
        print('{:>28} -> {:<15}'.format(n16, n17))
        cls_id_16_to_17[cls_names_16.index(n16)] = cls_names_17.index(n17)

    return cls_id_16_to_17
 def __init__(self):
     super(self.__class__, self).__init__()
     json_file = rospy.get_param('~json')
     self.tote_contents = jsk_apc2016_common.get_tote_contents(json_file)
     self.pub = self.advertise('~output', ObjectRecognition, queue_size=1)
     object_data = jsk_apc2016_common.get_object_data()
     self.blacklist = [
         d['name'] for d in object_data
         if d['graspability']['gripper2016'] >= 4
     ]
Example #7
0
def test_get_object_data():
    obj_data = jsk_apc2016_common.get_object_data()
    obj_names = map(lambda d: d['name'], obj_data)
    assert_true(isinstance(obj_data, list))
    assert_equal(39, len(obj_data))
    assert_equal(sorted(obj_names), obj_names)
    for d in obj_data:
        assert_true(isinstance(d, dict))
        assert_true('name' in d)
        assert_true('weight' in d)
        assert_true('graspability' in d)
        graspability = d['graspability']
        assert_true('gripper2015' in graspability)
        assert_true('gripper2016' in graspability)
        assert_true(graspability['gripper2015'] in range(1, 5))
        assert_true(graspability['gripper2016'] in range(1, 5))
        assert_true('stock' in d)
Example #8
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('rawdata_dir')
    parser.add_argument('dataset_dir')
    args = parser.parse_args()

    rawdata_dir = args.rawdata_dir
    dataset_dir = args.dataset_dir

    target_names = ['background'] + \
        [obj['name'] for obj in jsk_apc2016_common.get_object_data()]
    for label_id, label_name in enumerate(target_names):
        print('{0}: {1}'.format(label_id, label_name))

    tmp_dir = tempfile.mkdtemp()
    if not osp.exists(tmp_dir):
        os.makedirs(tmp_dir)

    raw_archive_dir = rawdata_dir + '_archive'
    if not osp.exists(raw_archive_dir):
        os.makedirs(raw_archive_dir)

    cmap = labelcolormap(len(target_names))

    for dir_ in os.listdir(rawdata_dir):
        img_file = osp.join(rawdata_dir, dir_, 'image.png')
        bin_mask_file = osp.join(rawdata_dir, dir_, 'bin_mask.png')
        json_file = osp.join(tmp_dir, 'labelme.json')
        cmd = 'labelme {0} -O {1}'.format(img_file, json_file)
        subprocess.call(cmd, shell=True)

        save_dir = osp.join(dataset_dir, dir_)
        if not osp.exists(save_dir):
            os.makedirs(save_dir)
        shutil.copy(img_file, osp.join(save_dir, 'image.png'))

        label = json_to_label(json_file)
        bin_mask = imread(bin_mask_file, mode='L')
        label[bin_mask == 0] = 255
        imsave(osp.join(save_dir, 'label.png'), label)

        label_viz = label2rgb(label, colors=cmap)
        imsave(osp.join(save_dir, 'label_viz.png'), label_viz)

        shutil.move(osp.join(rawdata_dir, dir_), raw_archive_dir)
Example #9
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('--year', type=int, default=2016)
    args = parser.parse_args()

    if args.year == 2015:
        import jsk_apc2015_common
        cls_names = ['background'] + jsk_apc2015_common.get_object_list()
    elif args.year == 2016:
        import jsk_apc2016_common
        data = jsk_apc2016_common.get_object_data()
        cls_names = ['background'] + [d['name'] for d in data]
    else:
        raise ValueError

    text = []
    for cls_id, cls_name in enumerate(cls_names):
        text.append('{:2}: {}'.format(cls_id, cls_name))
    print('\n'.join(text))
Example #10
0
 def __init__(self):
     rp = rospkg.RosPack()
     self.json_file = rospy.get_param('~json', None)
     self.create_output_json = rospy.get_param('~create_output_json', True)
     if self.create_output_json:
         self.output_json_file = osp.join(
                 rp.get_path('jsk_2016_01_baxter_apc'),
                 'output',
                 'output_' + osp.basename(self.json_file)
                 )
     else:
         self.output_json_file = self.json_file
     self.black_list = rospy.get_param('~black_list', [])
     self.volume_first = rospy.get_param('~volume_first', [])
     self.limit_volume = rospy.get_param('~limit_volume', 3000)
     if self.json_file is None:
         rospy.logerr('must set json file path to ~json')
         return
     if self.output_json_file is None:
         rospy.logerr('must set output json file path to ~output_json')
         return
     self.pub = {}
     self.pub['left'] = rospy.Publisher(
             '~left_hand',
             WorkOrderArray,
             queue_size=1
             )
     self.pub['right'] = rospy.Publisher(
             '~right_hand',
             WorkOrderArray,
             queue_size=1
             )
     self.object_data = jsk_apc2016_common.get_object_data()
     initial_bin_contents = jsk_apc2016_common.get_bin_contents(
             self.json_file
             )
     self.bin_point_dict = {
             k: self._get_point(v) for k, v in initial_bin_contents.items()
             }
    def __init__(self):
        self.mask_img = None
        self.dist_img = None
        self.target_bin = None
        self.bin_info_dict = {}
        self.bridge = CvBridge()
        ConnectionBasedTransport.__init__(self)

        self.gpu = rospy.get_param('~gpu', 0)
        self.load_model()

        self.objects = ['background'] +\
            [object_data['name'] for
             object_data in jsk_apc2016_common.get_object_data()]

        self.target_mask_pub = self.advertise(
            '~target_mask', Image, queue_size=3)
        self.masked_input_img_pub = self.advertise(
            '~masked_input', Image, queue_size=3)
        self.label_pub = self.advertise(
            '~label', Image, queue_size=3)
        self.debug_mask_pub = self.advertise(
            '~debug', Image, queue_size=3)
Example #12
0
    def __init__(self):
        self.mask_img = None
        self.dist_img = None
        self.target_bin = None
        self.bin_info_dict = {}
        self.bridge = CvBridge()
        ConnectionBasedTransport.__init__(self)

        self.gpu = rospy.get_param('~gpu', 0)
        self.load_model()

        self.objects = ['background'] +\
            [object_data['name'] for
             object_data in jsk_apc2016_common.get_object_data()]

        self.target_mask_pub = self.advertise('~target_mask',
                                              Image,
                                              queue_size=3)
        self.masked_input_img_pub = self.advertise('~masked_input',
                                                   Image,
                                                   queue_size=3)
        self.label_pub = self.advertise('~label', Image, queue_size=3)
        self.debug_mask_pub = self.advertise('~debug', Image, queue_size=3)
Example #13
0
    def __init__(self):
        self.json_file = rospy.get_param('~json', None)
        self.is_apc2016 = rospy.get_param('~is_apc2016', True)
        self.gripper = rospy.get_param('~gripper', 'gripper2016')
        self.max_weight = rospy.get_param('~max_weight', -1)
        if self.json_file is None:
            rospy.logerr('must set json file path to ~json')
            return
        data = json.load(open(self.json_file))
        self.work_order = {}
        work_order_list = []
        for order in data['work_order']:
            bin_ = order['bin'].split('_')[1].lower()
            self.work_order[bin_] = order['item']
            work_order_list.append({'bin': bin_, 'item': order['item']})
        rospy.set_param('~work_order', work_order_list)

        self.object_data = None
        if self.is_apc2016:
            self.object_data = jsk_apc2016_common.get_object_data()

        self.bin_contents = jsk_apc2016_common.get_bin_contents(
            param='~bin_contents')

        self.msg = self.get_work_order_msg()

        self.pub_left = rospy.Publisher('~left_hand',
                                        WorkOrderArray,
                                        queue_size=1)
        self.pub_right = rospy.Publisher('~right_hand',
                                         WorkOrderArray,
                                         queue_size=1)
        rospy.Service('~update_target', UpdateTarget, self._update_target_cb)
        self.updated = False
        rospy.Timer(rospy.Duration(rospy.get_param('~duration', 1)),
                    self._timer_cb)
Example #14
0
#-------------------------------------------------------------------------------

# define our bin and item names to use

CONST_BIN_NAMES = [
    'bin_A', 'bin_B', 'bin_C', 'bin_D', 'bin_E', 'bin_F', 'bin_G', 'bin_H',
    'bin_I', 'bin_J', 'bin_K', 'bin_L'
]

NBINS = len(CONST_BIN_NAMES)
N1_2_BINS = 3 + random.randint(0, 1)
N3_4_BINS = 5 + random.randint(0, 1)
N5__BINS = NBINS - (N1_2_BINS + N3_4_BINS)  #assumed to be more than 5 items
N_TOTAL_ITEMS = 47  ###CHANGE THIS TO 50 AFTER FULL ITEMS BE DELIEVERED FROM AMAZON

ITEMS_DATA = jsk_apc2016_common.get_object_data()
CONST_ITEM_NAMES = []
CONST_N_ITEMS = []
for item_data in ITEMS_DATA:
    CONST_ITEM_NAMES.append(item_data['name'])
    CONST_N_ITEMS.append(item_data['stock'])


class InterfaceGeneratorPick():
    def __init__(self):
        self.count_items = N_TOTAL_ITEMS
        self.bin_contents = {bin_name: [] for bin_name in CONST_BIN_NAMES}
        self.bin_list = [1] * NBINS
        self.bin_check = [False] * NBINS
        self.items_bins = copy.deepcopy(
            CONST_ITEM_NAMES)  # create a destroyable copy of the items
Example #15
0
import collections
import os
import os.path as osp
import pprint
import shutil
import textwrap

import numpy as np
from scipy.ndimage import imread
from skimage.transform import resize
import matplotlib.pyplot as plt

from jsk_apc2016_common import get_object_data


target_names = ['no_object'] + [d['name'] for d in get_object_data()]

this_dir = osp.dirname(osp.abspath(__file__))
dataset_dir = osp.realpath(osp.join(this_dir, 'all'))
stats = collections.defaultdict(int)
for dir_ in os.listdir(dataset_dir):
    img = imread(osp.join(dataset_dir, dir_, 'image.png'), mode='RGB')
    mask = imread(osp.join(dataset_dir, dir_, 'mask.png'), mode='L')
    mask = resize(mask, img.shape[:2], preserve_range=True).astype(np.uint8)
    label_name = open(osp.join(dataset_dir, dir_, 'label.txt')).read().strip()
    if label_name not in target_names:
        print(osp.join(dataset_dir, dir_), label_name, img.shape[:2])
        raise ValueError
    applied = img.copy()
    applied[mask == 0] = 0
    h, w = img.shape[:2]
Example #16
0
def test_get_object_data():
    obj_data = jsk_apc2016_common.get_object_data()
    assert_true(isinstance(obj_data, list))
    for d in obj_data:
        assert_true(isinstance(d, dict))
        assert_true('name' in d)
                   'bin_E',
                   'bin_F',
                   'bin_G',
                   'bin_H',
                   'bin_I',
                   'bin_J',
                   'bin_K',
                   'bin_L']


NBINS = len(CONST_BIN_NAMES)
N1_2_BINS = 3 + random.randint(0,1)
N3_4_BINS = 5 + random.randint(0,1)
N5__BINS = NBINS - (N1_2_BINS + N3_4_BINS) #assumed to be more than 5 items

ITEMS_DATA = jsk_apc2016_common.get_object_data()
CONST_ITEM_NAMES = []
CONST_N_ITEMS=[]
for item_data in ITEMS_DATA :
    CONST_ITEM_NAMES.append(item_data['name'])
    CONST_N_ITEMS.append(item_data['stock'])

NTOTE_TOTAL = 12 # total number of items
N_TOTAL_ITEMS = 35 ###CHANGE THIS TO 40 AFTER FULL ITEMS BE DELIEVERED FROM AMAZON

count_items = N_TOTAL_ITEMS
parser = argparse.ArgumentParser()
parser.add_argument("version")
args = parser.parse_args()
version = args.version
Example #18
0
from __future__ import print_function

import os
import os.path as osp

import matplotlib.pyplot as plt
import numpy as np
from scipy.ndimage import imread
from skimage.color import label2rgb

import jsk_apc2016_common


target_names = [None] * 256
target_names[0] = 'background'
for i, datum in enumerate(jsk_apc2016_common.get_object_data()):
    label_value = i + 1  # background is 0
    target_names[label_value] = datum['name']
target_names[255] = 'unlabeled'
target_names = np.array(target_names)

for dir_ in os.listdir('annotated'):
    img_file = osp.join('annotated', dir_, 'image.png')
    label_file = osp.join('annotated', dir_, 'label.png')
    img = imread(img_file, mode='RGB')
    label = imread(label_file, mode='L')
    print('{0}: candidates: {1}'.format(dir_, target_names[np.unique(label)]))
    label_viz = label2rgb(label, img, bg_label=0)
    label_viz[label == 255] = 0
    plt.imshow(label_viz)
    plt.show()
Example #19
0

"""Script to label multiple image sets using LabelMe

Usage:
    Create polygons --> Save --> (Next image set) --> Create polygons

    If you want to delete the displayed dataset, put label '-1'.

    You may want to skip labelling some images. In that case, you can just
    close Labelme.
"""


object_names = [object_data['name'] for
                object_data in jsk_apc2016_common.get_object_data()]
object_names_dict = {}
for i, name in enumerate(object_names):
    object_names_dict[name] = i


class LabelMeMultiple(object):
    def __init__(self, prefix, labeled_dir):
        self.prefix = prefix
        self.labeled_dir = labeled_dir

        self.json_path = prefix + '.json'
        self.img_path = prefix + '.jpg'
        self.mask_path = prefix + '.pbm'
        self.pkl_path = prefix + '.pkl'
        self.input_paths = [
Example #20
0
def test_get_object_data():
    obj_data = jsk_apc2016_common.get_object_data()
    assert_true(isinstance(obj_data, list))
    for d in obj_data:
        assert_true(isinstance(d, dict))
        assert_true('name' in d)
Example #21
0
import jsk_apc2016_common
"""Script to label multiple image sets using LabelMe

Usage:
    Create polygons --> Save --> (Next image set) --> Create polygons

    If you want to delete the displayed dataset, put label '-1'.

    You may want to skip labelling some images. In that case, you can just
    close Labelme.
"""

object_names = [
    object_data['name']
    for object_data in jsk_apc2016_common.get_object_data()
]
object_names_dict = {}
for i, name in enumerate(object_names):
    object_names_dict[name] = i


class LabelMeMultiple(object):
    def __init__(self, prefix, labeled_dir):
        self.prefix = prefix
        self.labeled_dir = labeled_dir

        self.json_path = prefix + '.json'
        self.img_path = prefix + '.jpg'
        self.mask_path = prefix + '.pbm'
        self.pkl_path = prefix + '.pkl'