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

Method _load_raw_labels

tools/utils/dataset.py:235–256  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

233 return image
234
235 def _load_raw_labels(self):
236 fname = 'dataset.json'
237 labels_files = [f for f in self._all_fnames if f.endswith(fname)]
238 if len(labels_files) == 0:
239 return None
240 assert len(labels_files) == 1, f"There can be only a single {fname} file"
241 with self._open_file(labels_files[0]) as f:
242 labels = json.load(f)['labels']
243 if labels is None:
244 return None
245 labels = dict(labels)
246 labels = [labels[remove_root(fname, self._name).replace('\\', '/')] for fname in self._image_fnames]
247 labels = np.array(labels)
248
249 if labels.dtype in NUMPY_INTEGER_TYPES:
250 labels = labels.astype(np.int64)
251 elif labels.dtype in NUMPY_FLOAT_TYPES:
252 labels = labels.astype(np.float32)
253 else:
254 raise NotImplementedError(f"Unsupported label dtype: {labels.dtype}")
255
256 return labels
257
258#----------------------------------------------------------------------------
259

Callers

nothing calls this directly

Calls 3

_open_fileMethod · 0.95
remove_rootFunction · 0.85
loadMethod · 0.80

Tested by

no test coverage detected