MCPcopy
hub / github.com/Vchitect/Latte / _load_raw_labels

Method _load_raw_labels

tools/utils/dataset.py:359–396  ·  view source on GitHub ↗

We leave the `dataset.json` file in the same format as in the original SG2-ADA repo: it's `labels` field is a hashmap of filename-label pairs.

(self)

Source from the content-addressed store, hash-verified

357 return dict(super().__getstate__(), _zipfile=None)
358
359 def _load_raw_labels(self):
360 """
361 We leave the `dataset.json` file in the same format as in the original SG2-ADA repo:
362 it's `labels` field is a hashmap of filename-label pairs.
363 """
364 fname = 'dataset.json'
365 labels_files = [f for f in self._all_objects if f.endswith(fname)]
366 if len(labels_files) == 0:
367 return None
368 assert len(labels_files) == 1, f"There can be only a single {fname} file"
369 with self._open_file(labels_files[0]) as f:
370 labels = json.load(f)['labels']
371 if labels is None:
372 return None
373
374 labels = dict(labels)
375 # The `dataset.json` file defines a label for each image and
376 # For the video dataset, this is both inconvenient and redundant.
377 # So let's redefine this
378 video_labels = {}
379 for filename, label in labels.items():
380 dirname = os.path.dirname(filename)
381 if dirname in video_labels:
382 assert video_labels[dirname] == label
383 else:
384 video_labels[dirname] = label
385 labels = video_labels
386 labels = [labels[os.path.normpath(dname).split(os.path.sep)[-1]] for dname in self._video_dir2frames]
387 labels = np.array(labels)
388
389 if labels.dtype in NUMPY_INTEGER_TYPES:
390 labels = labels.astype(np.int64)
391 elif labels.dtype in NUMPY_FLOAT_TYPES:
392 labels = labels.astype(np.float32)
393 else:
394 raise NotImplementedError(f"Unsupported label dtype: {labels.dtype}")
395
396 return labels
397
398 def __getitem__(self, idx: int) -> Dict:
399 if self.load_n_consecutive:

Callers

nothing calls this directly

Calls 2

_open_fileMethod · 0.95
loadMethod · 0.80

Tested by

no test coverage detected