feat: add features
Browse files48 unmodified lines49505152535455565733 unmodified lines91929394959697989910010110210310410510610710810911011111211311411511625 unmodified lines1421431441451461471489 unmodified lines1581591601611621631641651661671 unmodified line16917017117217348 unmodified lines"name": datasets.Value("string"),"image": datasets.Image(),"mask": datasets.Image(),"shapes": datasets.Sequence({"track_id": datasets.Value("uint32"),"label": datasets.ClassLabel(num_classes=len(_LABELS),names=_LABELS,33 unmodified lines),]@staticmethoddef extract_shapes_from_tracks(root: ET.Element, file: str, index: int) -> ET.Element:img = ET.Element("image")img.set("name", file)img.set("id", str(index))for track in root.iter("track"):shape = track.find(f".//*[@frame='{index}']")if not (shape is None):shape.set("label", track.get("label"))shape.set("track_id", track.get("id"))img.append(shape)return img@staticmethoddef parse_shape(shape: ET.Element) -> dict:label = shape.get("label")track_id = shape.get("track_id")shape_type = shape.tagrotation = shape.get("rotation", 0.0)occluded = shape.get("occluded", 0)25 unmodified linesshape_data = {"label": label,"track_id": track_id,"type": shape_type,"points": points,"rotation": rotation,9 unmodified linesroot = tree.getroot()for idx, file in enumerate(sorted(os.listdir(os.path.join(data, "images")))):img = self.extract_shapes_from_tracks(root, file, idx)image_id = img.get("id")name = img.get("name")shapes = [self.parse_shape(shape) for shape in img]yield idx, {1 unmodified line"name": name,"image": os.path.join(data, "images", file),"mask": os.path.join(data, "masks", file),"shapes": shapes,}48 unmodified lines4950515253545556575833 unmodified lines929394959697989910025 unmodified lines1261271281291301319 unmodified lines1411421431441451461471481491501511521531 unmodified line15515615715815916016148 unmodified lines"name": datasets.Value("string"),"image": datasets.Image(),"mask": datasets.Image(),"width": datasets.Value("uint16"),"height": datasets.Value("uint16"),"shapes": datasets.Sequence({"label": datasets.ClassLabel(num_classes=len(_LABELS),names=_LABELS,33 unmodified lines),]@staticmethoddef parse_shape(shape: ET.Element) -> dict:label = shape.get("label")shape_type = shape.tagrotation = shape.get("rotation", 0.0)occluded = shape.get("occluded", 0)25 unmodified linesshape_data = {"label": label,"type": shape_type,"points": points,"rotation": rotation,9 unmodified linesroot = tree.getroot()for idx, file in enumerate(sorted(os.listdir(os.path.join(data, "images")))):image_name = file.split("/")[-1]img = root.find(f"./image[@name='images/{image_name}']")image_id = img.get("id")name = img.get("name")width = img.get("width")height = img.get("height")shapes = [self.parse_shape(shape) for shape in img]yield idx, {1 unmodified line"name": name,"image": os.path.join(data, "images", file),"mask": os.path.join(data, "masks", file),"width": width,"height": height,"shapes": shapes,}
fights-segmentation.py+8-20