vkashko commited on
Commit
55979c3
·
1 Parent(s): 07cd75d

feat: add features

Browse files
Files changed (1) hide show
  1. fights-segmentation.py +8 -20
fights-segmentation.py CHANGED
@@ -49,9 +49,10 @@ class FightsSegmentation(datasets.GeneratorBasedBuilder):
49
  "name": datasets.Value("string"),
50
  "image": datasets.Image(),
51
  "mask": datasets.Image(),
 
 
52
  "shapes": datasets.Sequence(
53
  {
54
- "track_id": datasets.Value("uint32"),
55
  "label": datasets.ClassLabel(
56
  num_classes=len(_LABELS),
57
  names=_LABELS,
@@ -91,26 +92,9 @@ class FightsSegmentation(datasets.GeneratorBasedBuilder):
91
  ),
92
  ]
93
 
94
- @staticmethod
95
- def extract_shapes_from_tracks(
96
- root: ET.Element, file: str, index: int
97
- ) -> ET.Element:
98
- img = ET.Element("image")
99
- img.set("name", file)
100
- img.set("id", str(index))
101
- for track in root.iter("track"):
102
- shape = track.find(f".//*[@frame='{index}']")
103
- if not (shape is None):
104
- shape.set("label", track.get("label"))
105
- shape.set("track_id", track.get("id"))
106
- img.append(shape)
107
-
108
- return img
109
-
110
  @staticmethod
111
  def parse_shape(shape: ET.Element) -> dict:
112
  label = shape.get("label")
113
- track_id = shape.get("track_id")
114
  shape_type = shape.tag
115
  rotation = shape.get("rotation", 0.0)
116
  occluded = shape.get("occluded", 0)
@@ -142,7 +126,6 @@ class FightsSegmentation(datasets.GeneratorBasedBuilder):
142
 
143
  shape_data = {
144
  "label": label,
145
- "track_id": track_id,
146
  "type": shape_type,
147
  "points": points,
148
  "rotation": rotation,
@@ -158,10 +141,13 @@ class FightsSegmentation(datasets.GeneratorBasedBuilder):
158
  root = tree.getroot()
159
 
160
  for idx, file in enumerate(sorted(os.listdir(os.path.join(data, "images")))):
161
- img = self.extract_shapes_from_tracks(root, file, idx)
 
162
 
163
  image_id = img.get("id")
164
  name = img.get("name")
 
 
165
  shapes = [self.parse_shape(shape) for shape in img]
166
 
167
  yield idx, {
@@ -169,5 +155,7 @@ class FightsSegmentation(datasets.GeneratorBasedBuilder):
169
  "name": name,
170
  "image": os.path.join(data, "images", file),
171
  "mask": os.path.join(data, "masks", file),
 
 
172
  "shapes": shapes,
173
  }
 
49
  "name": datasets.Value("string"),
50
  "image": datasets.Image(),
51
  "mask": datasets.Image(),
52
+ "width": datasets.Value("uint16"),
53
+ "height": datasets.Value("uint16"),
54
  "shapes": datasets.Sequence(
55
  {
 
56
  "label": datasets.ClassLabel(
57
  num_classes=len(_LABELS),
58
  names=_LABELS,
 
92
  ),
93
  ]
94
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
95
  @staticmethod
96
  def parse_shape(shape: ET.Element) -> dict:
97
  label = shape.get("label")
 
98
  shape_type = shape.tag
99
  rotation = shape.get("rotation", 0.0)
100
  occluded = shape.get("occluded", 0)
 
126
 
127
  shape_data = {
128
  "label": label,
 
129
  "type": shape_type,
130
  "points": points,
131
  "rotation": rotation,
 
141
  root = tree.getroot()
142
 
143
  for idx, file in enumerate(sorted(os.listdir(os.path.join(data, "images")))):
144
+ image_name = file.split("/")[-1]
145
+ img = root.find(f"./image[@name='images/{image_name}']")
146
 
147
  image_id = img.get("id")
148
  name = img.get("name")
149
+ width = img.get("width")
150
+ height = img.get("height")
151
  shapes = [self.parse_shape(shape) for shape in img]
152
 
153
  yield idx, {
 
155
  "name": name,
156
  "image": os.path.join(data, "images", file),
157
  "mask": os.path.join(data, "masks", file),
158
+ "width": width,
159
+ "height": height,
160
  "shapes": shapes,
161
  }