def _read(self): channels = {} groundtruth = [] metadata = _SEQUENCES[self.name] channels["color"] = PatternFileListChannel( os.path.join(self._base, "img", "%04d.jpg"), start=metadata.get("start", 1), end=metadata.get("end", None)) self._metadata["channel.default"] = "color" self._metadata["width"], self._metadata["height"] = six.next( six.itervalues(channels)).size groundtruth_file = os.path.join(self._base, "groundtruth_rect.txt") with open(groundtruth_file, 'r') as filehandle: for region in filehandle.readlines(): groundtruth.append(parse(region)) self._metadata["length"] = len(groundtruth) if not channels["color"].length == len(groundtruth): raise DatasetException( "Length mismatch between groundtruth and images") return channels, groundtruth, {}, {}
def _read(self): channels = {} tags = {} values = {} groundtruth = [] channels["color"] = load_channel(os.path.join(self._base, "%08d.jpg")) self._metadata["channel.default"] = "color" self._metadata["width"], self._metadata["height"] = six.next( six.itervalues(channels)).size groundtruth_file = os.path.join( self._base, self.metadata("groundtruth", "groundtruth.txt")) with open(groundtruth_file, 'r') as filehandle: for region in filehandle.readlines(): groundtruth.append(parse(region)) self._metadata["length"] = len(groundtruth) tagfiles = glob.glob(os.path.join(self._base, '*.label')) for tagfile in tagfiles: with open(tagfile, 'r') as filehandle: tagname = os.path.splitext(os.path.basename(tagfile))[0] tag = [line.strip() == "1" for line in filehandle.readlines()] while not len(tag) >= len(groundtruth): tag.append(False) tags[tagname] = tag valuefiles = glob.glob(os.path.join(self._base, '*.value')) for valuefile in valuefiles: with open(valuefile, 'r') as filehandle: valuename = os.path.splitext(os.path.basename(valuefile))[0] value = [ float(line.strip()) for line in filehandle.readlines() ] while not len(value) >= len(groundtruth): value.append(0.0) values[valuename] = value for name, channel in channels.items(): if not channel.length == len(groundtruth): raise DatasetException("Length mismatch for channel %s" % name) for name, tag in tags.items(): if not len(tag) == len(groundtruth): tag_tmp = len(groundtruth) * [False] tag_tmp[:len(tag)] = tag tag = tag_tmp for name, value in values.items(): if not len(value) == len(groundtruth): raise DatasetException("Length mismatch for value %s" % name) return channels, groundtruth, tags, values
def _scan(self, base): metadata_file = os.path.join(base, 'sequence') data = read_properties(metadata_file) for c in ["color", "depth", "ir"]: if "channels.%s" % c in data: self._channels[c] = load_channel( os.path.join(self._base, localize_path(data["channels.%s" % c]))) # Load default channel if no explicit channel data available if len(self._channels) == 0: self._channels["color"] = load_channel( os.path.join(self._base, "color", "%08d.jpg")) else: self._metadata["channel.default"] = next( iter(self._channels.keys())) self._metadata["width"], self._metadata["height"] = six.next( six.itervalues(self._channels)).size groundtruth_file = os.path.join( self._base, data.get("groundtruth", "groundtruth.txt")) with open(groundtruth_file, 'r') as groundtruth: for region in groundtruth.readlines(): self._groundtruth.append(parse(region)) self._metadata["length"] = len(self._groundtruth) tagfiles = glob.glob(os.path.join(self._base, '*.tag')) + glob.glob( os.path.join(self._base, '*.label')) for tagfile in tagfiles: with open(tagfile, 'r') as filehandle: tagname = os.path.splitext(os.path.basename(tagfile))[0] tag = [line.strip() == "1" for line in filehandle.readlines()] while not len(tag) >= len(self._groundtruth): tag.append(False) self._tags[tagname] = tag valuefiles = glob.glob(os.path.join(self._base, '*.value')) for valuefile in valuefiles: with open(valuefile, 'r') as filehandle: valuename = os.path.splitext(os.path.basename(valuefile))[0] value = [ float(line.strip()) for line in filehandle.readlines() ] while not len(value) >= len(self._groundtruth): value.append(0.0) self._values[valuename] = value for name, channel in self._channels.items(): if not channel.length == len(self._groundtruth): raise DatasetException("Length mismatch for channel %s" % name) for name, tags in self._tags.items(): if not len(tags) == len(self._groundtruth): tag_tmp = len(self._groundtruth) * [False] tag_tmp[:len(tags)] = tags tags = tag_tmp for name, values in self._values.items(): if not len(values) == len(self._groundtruth): raise DatasetException("Length mismatch for value %s" % name)