diff --git a/sleap/io/format/hdf5.py b/sleap/io/format/hdf5.py index 353f88e3a..55a30d74f 100644 --- a/sleap/io/format/hdf5.py +++ b/sleap/io/format/hdf5.py @@ -81,7 +81,10 @@ def read_headers( # Extract the Labels JSON metadata and create Labels object with just this # metadata. - dicts = json_loads(f.require_group("metadata").attrs["json"].tobytes().decode()) + json = f.require_group("metadata").attrs["json"] + if not isinstance(json, str): + json = json.tobytes().decode() + dicts = json_loads(json) # These items are stored in separate lists because the metadata group got to be # too big. @@ -151,6 +154,45 @@ def read( points_dset[:]["x"] -= 0.5 points_dset[:]["y"] -= 0.5 + def cast_as_compound(arr, dtype): + out = np.empty(shape=(len(arr),), dtype=dtype) + if out.size == 0: + return out + for i, (name, _) in enumerate(dtype): + out[name] = arr[:, i] + return out + + # cast points, instances, and frames into complex dtype if not already + dtype_points = [("x", "