gaitsetpy.features.urfall_features API documentation

# gaitsetpy.features.urfall_features

UrFall Image/Video Feature Extractor. Maintainer: @aharshit123456

This module provides a lightweight feature extractor for UrFall depth (PNG16), RGB (PNG), and video (MP4) modalities. It extracts simple, fast-to-compute features suitable for sanity checks and baseline models.

View Source

     1'''
     2UrFall Image/Video Feature Extractor.
     3Maintainer: @aharshit123456
     4
     5This module provides a lightweight feature extractor for UrFall depth (PNG16), RGB (PNG), and video (MP4) modalities.
     6It extracts simple, fast-to-compute features suitable for sanity checks and baseline models.
     7'''
     8
     9from typing import List, Dict, Any
    10import numpy as np
    11from ..core.base_classes import BaseFeatureExtractor
    12
    13
    14class UrFallMediaFeatureExtractor(BaseFeatureExtractor):
    15    """
    16    UrFall image/video feature extractor.
    17
    18    Extracts per-window features from sequences of images or decoded video frames:
    19    - mean_intensity
    20    - std_intensity
    21    - motion_mean (if pairwise differences are available)
    22    - motion_std
    23    """
    24
    25    def __init__(self, verbose: bool = False):
    26        super().__init__(
    27            name="urfall_media",
    28            description="Lightweight feature extractor for UrFall depth/RGB/video modalities"
    29        )
    30        self.config = {
    31            'verbose': verbose,
    32            'use_motion': True,
    33            'grayscale': True,  # for RGB convert to gray before stats
    34        }
    35
    36    def extract_features(self, windows: List[Dict], fs: int, **kwargs) -> List[Dict]:
    37        self.config.update(kwargs)
    38        features: List[Dict[str, Any]] = []
    39        for window in windows:
    40            name = window.get('name', 'unknown')
    41            frames = window.get('data', [])
    42            if not isinstance(frames, list) or len(frames) == 0:
    43                continue
    44            # frames is a list of numpy arrays (HxW) or (HxWxC)
    45            intensities = []
    46            motions = []
    47            prev_gray = None
    48            for f in frames:
    49                arr = np.array(f)
    50                if arr.ndim == 3 and self.config['grayscale']:
    51                    arr = arr.mean(axis=2)
    52                intensities.append(float(np.mean(arr)))
    53                if self.config['use_motion']:
    54                    if prev_gray is not None:
    55                        diff = np.abs(arr.astype(np.float32) - prev_gray.astype(np.float32))
    56                        motions.append(float(np.mean(diff)))
    57                    prev_gray = arr
    58            fdict: Dict[str, Any] = {'name': name, 'features': {}}
    59            if intensities:
    60                fdict['features']['mean_intensity'] = float(np.mean(intensities))
    61                fdict['features']['std_intensity'] = float(np.std(intensities))
    62            if motions:
    63                fdict['features']['motion_mean'] = float(np.mean(motions))
    64                fdict['features']['motion_std'] = float(np.std(motions))
    65            features.append(fdict)
    66        return features
    67
    68    def get_feature_names(self) -> List[str]:
    69        return ['mean_intensity', 'std_intensity', 'motion_mean', 'motion_std']

class UrFallMediaFeatureExtractor(gaitsetpy.core.base_classes.BaseFeatureExtractor): View Source

    15class UrFallMediaFeatureExtractor(BaseFeatureExtractor):
    16    """
    17    UrFall image/video feature extractor.
    18
    19    Extracts per-window features from sequences of images or decoded video frames:
    20    - mean_intensity
    21    - std_intensity
    22    - motion_mean (if pairwise differences are available)
    23    - motion_std
    24    """
    25
    26    def __init__(self, verbose: bool = False):
    27        super().__init__(
    28            name="urfall_media",
    29            description="Lightweight feature extractor for UrFall depth/RGB/video modalities"
    30        )
    31        self.config = {
    32            'verbose': verbose,
    33            'use_motion': True,
    34            'grayscale': True,  # for RGB convert to gray before stats
    35        }
    36
    37    def extract_features(self, windows: List[Dict], fs: int, **kwargs) -> List[Dict]:
    38        self.config.update(kwargs)
    39        features: List[Dict[str, Any]] = []
    40        for window in windows:
    41            name = window.get('name', 'unknown')
    42            frames = window.get('data', [])
    43            if not isinstance(frames, list) or len(frames) == 0:
    44                continue
    45            # frames is a list of numpy arrays (HxW) or (HxWxC)
    46            intensities = []
    47            motions = []
    48            prev_gray = None
    49            for f in frames:
    50                arr = np.array(f)
    51                if arr.ndim == 3 and self.config['grayscale']:
    52                    arr = arr.mean(axis=2)
    53                intensities.append(float(np.mean(arr)))
    54                if self.config['use_motion']:
    55                    if prev_gray is not None:
    56                        diff = np.abs(arr.astype(np.float32) - prev_gray.astype(np.float32))
    57                        motions.append(float(np.mean(diff)))
    58                    prev_gray = arr
    59            fdict: Dict[str, Any] = {'name': name, 'features': {}}
    60            if intensities:
    61                fdict['features']['mean_intensity'] = float(np.mean(intensities))
    62                fdict['features']['std_intensity'] = float(np.std(intensities))
    63            if motions:
    64                fdict['features']['motion_mean'] = float(np.mean(motions))
    65                fdict['features']['motion_std'] = float(np.std(motions))
    66            features.append(fdict)
    67        return features
    68
    69    def get_feature_names(self) -> List[str]:
    70        return ['mean_intensity', 'std_intensity', 'motion_mean', 'motion_std']

UrFall image/video feature extractor.

Extracts per-window features from sequences of images or decoded video frames:

- mean_intensity
- std_intensity
- motion_mean (if pairwise differences are available)
- motion_std

UrFallMediaFeatureExtractor(verbose: bool = False) View Source

    26    def __init__(self, verbose: bool = False):
    27        super().__init__(
    28            name="urfall_media",
    29            description="Lightweight feature extractor for UrFall depth/RGB/video modalities"
    30        )
    31        self.config = {
    32            'verbose': verbose,
    33            'use_motion': True,
    34            'grayscale': True,  # for RGB convert to gray before stats
    35        }

Initialize the feature extractor.

Args: name: Name of the feature extractor description: Description of the feature extractor

config
def extract_features(self, windows: List[Dict], fs: int, **kwargs) -> List[Dict]: View Source

    37    def extract_features(self, windows: List[Dict], fs: int, **kwargs) -> List[Dict]:
    38        self.config.update(kwargs)
    39        features: List[Dict[str, Any]] = []
    40        for window in windows:
    41            name = window.get('name', 'unknown')
    42            frames = window.get('data', [])
    43            if not isinstance(frames, list) or len(frames) == 0:
    44                continue
    45            # frames is a list of numpy arrays (HxW) or (HxWxC)
    46            intensities = []
    47            motions = []
    48            prev_gray = None
    49            for f in frames:
    50                arr = np.array(f)
    51                if arr.ndim == 3 and self.config['grayscale']:
    52                    arr = arr.mean(axis=2)
    53                intensities.append(float(np.mean(arr)))
    54                if self.config['use_motion']:
    55                    if prev_gray is not None:
    56                        diff = np.abs(arr.astype(np.float32) - prev_gray.astype(np.float32))
    57                        motions.append(float(np.mean(diff)))
    58                    prev_gray = arr
    59            fdict: Dict[str, Any] = {'name': name, 'features': {}}
    60            if intensities:
    61                fdict['features']['mean_intensity'] = float(np.mean(intensities))
    62                fdict['features']['std_intensity'] = float(np.std(intensities))
    63            if motions:
    64                fdict['features']['motion_mean'] = float(np.mean(motions))
    65                fdict['features']['motion_std'] = float(np.std(motions))
    66            features.append(fdict)
    67        return features

Extract features from sliding windows.

Args: windows: List of sliding window dictionaries fs: Sampling frequency **kwargs: Additional arguments for feature extraction

Returns: List of feature dictionaries

def get_feature_names(self) -> List[str]: View Source

    69    def get_feature_names(self) -> List[str]:
    70        return ['mean_intensity', 'std_intensity', 'motion_mean', 'motion_std']

Get names of features extracted by this extractor.

Returns: List of feature names

##### Inherited Members

gaitsetpy.core.base_classes.BaseFeatureExtractor
  name
  description
  configure
  get_info