Example #1
0
 def object_rec_parse_url(self, objects=None, unique=True):
     """
     Args:
         objects: List of objects to return (if None then return all)
     
     Returns:
         Iterator of (image_url, objects), where
         objects is a list of {'class': class_name, 'xy': np_array}
     """
     objects = set(objects)
     prev_urls = set()
     for fn in glob.glob(self.dataset_path + 'Annotations/*.xml'):
         try:
             image_fn, folder, cur_objects = vision_data.parse_voc_xml(fn)
             cur_objects = [x for x in cur_objects if x['class'] in objects]
         except:
             logging.warning('Cannot parse [%s]' % fn)
         else:
             if cur_objects:
                 if (folder, image_fn) in prev_urls:
                     print('Duplicate Annotation: http://labelme.csail.mit.edu/Images/%s/%s' % (folder, image_fn))
                     continue
                 prev_urls.add((folder, image_fn))
                 print('http://labelme.csail.mit.edu/Images/%s/%s' % (folder, image_fn))
                 yield 'http://labelme.csail.mit.edu/Images/%s/%s' % (folder, image_fn), cur_objects
Example #2
0
    def _parse_xml_all(self):
        data = {}

        for folder_path in glob.glob(self.dataset_path + 'Annotations/*'):
            if os.path.basename(folder_path) not in ('out_of_context',
                                                     'static_sun09_database'):
                continue
            image_path = self.dataset_path + 'Images/%s/' % os.path.basename(
                folder_path)
            for filename_path in glob.glob(folder_path + '/*'):
                try:
                    filename, folder, objs = vision_data.parse_voc_xml(
                        filename_path)
                except Exception as e:
                    print(e)
                    print('Parse Error: %s' % filename_path)
                    continue
                assert os.path.basename(folder_path) == folder
                data.setdefault(folder, {})[image_path + filename] = objs
        static_data = {}
        for object_path in glob.glob('%s/Annotations/static_sun_objects/*' %
                                     (self.dataset_path)):
            image_path = self.dataset_path + 'Images/static_sun_objects/'
            try:
                filename, folder, objs = self._parse_xml(filename_path)
            except Exception as e:
                print(e)
                print('Parse Error: %s' % filename_path)
                continue
            object_name = os.path.basename(object_path)
            static_data.setdefault(object_name, []).append(objs)
        return static_data, data['out_of_context'], data[
            'static_sun09_database']
Example #3
0
 def object_rec_parse_url(self, objects=None, unique=True):
     """
     Args:
         objects: List of objects to return (if None then return all)
     
     Returns:
         Iterator of (image_url, objects), where
         objects is a list of {'class': class_name, 'xy': np_array}
     """
     objects = set(objects)
     prev_urls = set()
     for fn in glob.glob(self.dataset_path + 'Annotations/*.xml'):
         try:
             image_fn, folder, cur_objects = vision_data.parse_voc_xml(fn)
             cur_objects = [x for x in cur_objects if x['class'] in objects]
         except:
             logging.warning('Cannot parse [%s]' % fn)
         else:
             if cur_objects:
                 if (folder, image_fn) in prev_urls:
                     print(
                         'Duplicate Annotation: http://labelme.csail.mit.edu/Images/%s/%s'
                         % (folder, image_fn))
                     continue
                 prev_urls.add((folder, image_fn))
                 print('http://labelme.csail.mit.edu/Images/%s/%s' %
                       (folder, image_fn))
                 yield 'http://labelme.csail.mit.edu/Images/%s/%s' % (
                     folder, image_fn), cur_objects
Example #4
0
    def _parse_xml_all(self):
        data = {}

        for folder_path in glob.glob(self.dataset_path + 'Annotations/*'):
            if os.path.basename(folder_path) not in ('out_of_context',
                                                     'static_sun09_database'):
                continue
            image_path = self.dataset_path + 'Images/%s/' % os.path.basename(folder_path)
            for filename_path in glob.glob(folder_path + '/*'):
                try:
                    filename, folder, objs = vision_data.parse_voc_xml(filename_path)
                except Exception, e:
                    print(e)
                    print('Parse Error: %s' % filename_path)
                    continue
                assert os.path.basename(folder_path) == folder
                data.setdefault(folder, {})[image_path + filename] = objs