Repository navigation
Conversation
a6f8c64 to
ca7a722
Compare
f365af1 to
adbf7f5
Compare
adbf7f5 to
e42e109
Compare
…eader and row index
e42e109 to
9a9ebe0
Compare
Rename LabeledDataHeader.columns to unrecognised_columns to clarify its purpose. Update classification, documentation, and the corresponding test.
|
@deruyter92 This is now only the DLC basic labeled data concepts. This and #15 could be the first to merge and be used in other repos |
| @dataclass(frozen=True) | ||
| class KeypointIdentifier: | ||
| """Keypoint properties. | ||
|
|
||
| Identifies a keypoint; does not describe the data (see ``KeypointDataFields``). | ||
|
|
||
| Attributes: | ||
| scorer: As stored. | ||
| individual: As stored; ``None`` when the source names no individual. | ||
| bodypart: As stored. | ||
| """ | ||
|
|
||
| scorer: str | ||
| individual: str | None | ||
| bodypart: str | ||
|
|
||
| @property | ||
| def scope(self) -> BodypartScope: | ||
| """``UNIQUE`` exactly when the individual is DeepLabCut's unique-bodyparts bucket.""" | ||
|
|
||
| return BodypartScope.UNIQUE if self.individual == UNIQUE_BODYPARTS_INDIVIDUAL else BodypartScope.INDIVIDUAL | ||
|
|
||
|
|
||
| @dataclass(frozen=True) | ||
| class KeypointIdentifiers(Sequence[KeypointIdentifier]): | ||
| """The identifiers of labeled data's keypoints, in keypoint order. | ||
|
|
||
| Available as ``identifiers`` on: | ||
|
|
||
| - ``LabeledDataFile``: read from the header; equal to the model's when the model can be built. | ||
| For inspecting a file without building the model, or a file with no frames. | ||
| - ``LabeledData``: available after construction (``from_wide_df``, ``from_long_df``, ``without_frames``). | ||
| - ``LabeledDataArrays``: the model's. Column ``k`` of each array is keypoint ``k``, so the arrays can be used | ||
| without the model. |
There was a problem hiding this comment.
I think this maybe mixes two things currently:
the KeypointIdentifier is a faithful and useful representation of what is currently on disk in the wide HDF format. Very useful as a private representation for validating the wide formats.
Passing on the same structure via KeypointIdentifiers on public LabeledData or LabeledDataArrays to me feels a bit awkward, however. E.g.:
- A scorer is really a property of the data collection, not a keypoint
- bodyparts, unique_bodyparts, and individuals have to be recovered via iteration over
KeypointIdentifiers, when these sets are primary facts about the data collection, which now are stored in config.yaml as a plain list.
Why not go for a more plain:
class LabeledDataDescriptor:
scorer: str
bodyparts: tuple[str, ...]
individuals: tuple[str, ...]
unique_bodyparts: tuple[str, ...]
data_fields: KeypointDataFields
You can keep the KeypointIdentifier for the KeypointColumns which is helpful for round-tripping to the wide HDF (private). But for the public model I would go for a plain description of what is in the data collection.
some advantages:
- matches DLC's own model in config.yaml
- offers direct access to the fields e.g.
scorer - avoids impossible states like multiple scorers in one file
- matches the arrays directly and intuitively
(frames, individuals, bodyparts, 2) - small and easily serializable object to pass around
- clear boundary between private, multi-level column-based representation vs public flat representation.
There was a problem hiding this comment.
again, open question, I am maybe overlooking some complexities which you account for. Let me know what you think
There was a problem hiding this comment.
Thanks, a summary for the next iteration:
I agree that the public identity can be a descriptor like you said, e.g.
LabeledDataDescriptor(
scorer="me",
bodyparts=("nose", "tail"),
individuals=("mouse1", "mouse2"), # () for single-animal
unique_bodyparts=("led",),
data_fields=KeypointDataFields(("x", "y")),
)KeypointIdentifier then stays, but private (just for reading and writing the wide header).
It also makes comparing a file layout with the expected descriptor easier, esp. for early validation and reporting of mismatches.
Invalid descriptor -> no model
Broken data should still be readable as stored (to_raw_wide_df()) and usable/reported by validation, but then LabeledData should refuse it. Two example cases (one column per keypoint, frame rows left out):
Several scorers:
| scorer | alice | alice | bob | bob |
|---|---|---|---|---|
| bodyparts | nose | tail | nose | tail |
Ragged, mouse2 has no tail column (not the same as an unlabeled tail, which is valid):
| scorer | me | me | me |
|---|---|---|---|
| individuals | mouse1 | mouse1 | mouse2 |
| bodyparts | nose | tail | nose |
"single" only in the wide format
Unique bodyparts would get their own field, so "single" appears only when reading or writing the legacy wide header.
Array shape
Again, I agree on the value of a consistent shape, in the array format above others.
We could keep xy in memory as (frames, keypoints, 2), and add as views:
per_individual():(frames, individuals, bodyparts, 2), with one individual for single-animal dataunique():(frames, unique_bodyparts, 2), empty if none are present
Both views are free (no copy). The other way would not since unique bodyparts cannot be in the 4D grid, so they would be separate in memory and getting the flat (F, K, 2) array would then copy.
Re: pose outputs
Pose outputs (frame- or time-indexed) have the same header, one scorer per file, so the same descriptor would fit, aside from the frame axis.
It would however point to needing a more generic name, e.g. KeypointsDescriptor.
Keypoints vocabulary, classification of DeepLabCut's wide labeled-data header and row index.
KeypointIdentifier(scorer, individual, bodypart) ;KeypointIdentifiersKeypointDataFieldsfor the keypoint data("x", "y")or("x", "y", "likelihood")levels.