Transforms

Compositions of transforms

Compose(transforms)

Composes several transforms together.

Padding

PadBodies(max_bodies, **kwargs)

Pad each frame with zeros to match number of bodies.

PadFrames(max_frames[, axis])

Pad sequence with zeros to match number of frames.

Selection

SampleFrames(num_frames[, num_clips, axis])

Uniformly sample frames from sequence.

SelectKBodies(k)

Select K bodies from sequeqnce based on motion.

Splitting

SplitFrames()

Split frame into N frames each containing one skeleton.

Normalization

CenterJoint([joint_id, all])

Center skeleton on joint.

ParallelBone(first_id, second_id[, axis])

Transform skeleton so two joints are parallel to a certain axis.

Augmentation

RandomShift(low, high)

Randomly shift skeleton sequences.

RandomRotate(degrees)

Randomly rotate skeleton sequences.

Denoising

SortByMotion()

Sort skeletons in a single frame by motion.

DenoiseByLength()

Denoise bodies by length of non zero frames.

DenoiseBySpread()

Denoise bodies by length of frames under a certain x, y spread.

DenoiseByMotion()

Denoise bodies by filtering frames within a certain range of motion.

MergeBodies()

Merges different bodies who don't overlap into 2 actors.

RemoveZeroFrames()

Remove frames where all bodies are zero from the sequence.

Denoise()

Denoise skeleton sequence used on NTU.

class torch_skeleton.transforms.CenterJoint(joint_id=1, all=False)[source]

Center skeleton on joint.

Parameters
  • joint_id (int) – joint id to center skeleton

  • all (bool) – set to False to center along initial frame

class torch_skeleton.transforms.Compose(transforms)[source]

Composes several transforms together. This transform does not support torchscript. Please, see the note below.

Parameters

transforms (list of Transform objects) – list of transforms to compose.

Example

>>> transforms.Compose([
>>>     transforms.CenterCrop(10),
>>>     transforms.PILToTensor(),
>>>     transforms.ConvertImageDtype(torch.float),
>>> ])

Note

In order to script the transformations, please use torch.nn.Sequential as below.

>>> transforms = torch.nn.Sequential(
>>>     transforms.CenterCrop(10),
>>>     transforms.Normalize((0.485, 0.456, 0.406), (0.229, 0.224, 0.225)),
>>> )
>>> scripted_transforms = torch.jit.script(transforms)

Make sure to use only scriptable transformations, i.e. that work with torch.Tensor, does not require lambda functions or PIL.Image.

class torch_skeleton.transforms.Denoise[source]

Denoise skeleton sequence used on NTU.

class torch_skeleton.transforms.DenoiseByLength[source]

Denoise bodies by length of non zero frames.

Removes bodies whose length is under a minimum length

class torch_skeleton.transforms.DenoiseByMotion[source]

Denoise bodies by filtering frames within a certain range of motion.

Valid frames by spread are selected to compute the motion of a body. Bodies whose motion is outside a certain low, high range is removed.

class torch_skeleton.transforms.DenoiseBySpread[source]

Denoise bodies by length of frames under a certain x, y spread.

Removes bodies where noisy frames exceed a certain ratio. Frames with higher x, y spread than the threshold are considered noisy.

class torch_skeleton.transforms.MergeBodies[source]

Merges different bodies who don’t overlap into 2 actors.

Bodies are expected to be sorted by motion. First body is selected as the main actor as it has the highest motion. subsequent bodies are compared with the main actor. If there aren’t overlapping frames, the body is merged with the main actor. If there are overlapping frames, try to merge with the second actor. If there are overlapping frames with the second actor, the body is removed.

class torch_skeleton.transforms.PadBodies(max_bodies, **kwargs)[source]

Pad each frame with zeros to match number of bodies.

Parameters

max_bodies (int) – number of bodies to pad to

class torch_skeleton.transforms.PadFrames(max_frames, axis=1, **kwargs)[source]

Pad sequence with zeros to match number of frames.

Parameters
  • max_frames (int) – number of frames to pad to

  • axis (int) – time dimension axis, default is 1

class torch_skeleton.transforms.ParallelBone(first_id, second_id, axis=2)[source]

Transform skeleton so two joints are parallel to a certain axis.

Parameters
  • first_id (int) – first joint id

  • second_id (int) – second joint id

  • axis (int) – axis to be parallel to 0, 1, 2, corresponds to x, y, z

class torch_skeleton.transforms.RandomRotate(degrees)[source]

Randomly rotate skeleton sequences.

Parameters

degrees (int) – range of shift in degrees

Example

# randomly select angles from -30 ~ 30 degrees and rotate >>> transforms.RandomRotate(30)

class torch_skeleton.transforms.RandomShift(low, high)[source]

Randomly shift skeleton sequences.

Parameters
  • low (int) – minimum shift

  • high (int) – maximum shift

class torch_skeleton.transforms.RemoveZeroFrames[source]

Remove frames where all bodies are zero from the sequence.

class torch_skeleton.transforms.SampleFrames(num_frames, num_clips=1, axis=0)[source]

Uniformly sample frames from sequence.

Parameters
  • num_frames (int) – number of frames to sample

  • num_clips (int) – number of clips to sample

  • axis (int) – axis to stack sampled clips

class torch_skeleton.transforms.SelectKBodies(k)[source]

Select K bodies from sequeqnce based on motion.

Parameters

k (int) – number of bodies to sort

class torch_skeleton.transforms.SortByMotion[source]

Sort skeletons in a single frame by motion.

class torch_skeleton.transforms.SplitFrames[source]

Split frame into N frames each containing one skeleton.