KumarLabJax / JABS-behavior-classifier

Behavior Classifier Component from the Jax Animal Behavior System
Other
11 stars 1 forks source link

Feature adjustments #22

Closed SkepticRaven closed 5 months ago

SkepticRaven commented 11 months ago

Development branch for merging in new features from Nick

List of new features

SkepticRaven commented 11 months ago

Current state of this effort:

Integrated branches/pulls:

Segmentation features integration status:

Known issues:

Still TODO:

SkepticRaven commented 7 months ago

Backwards compatibility was resolved with recent merge + patch (9a5e173) Now just need to focus on 2 remaining merges...

SkepticRaven commented 6 months ago

Signal processing code has been integrated and converted to be efficient enough for standard usage, but tests are pretty broken due to internal changes (eg NaN propagation, feature structure changes).

18 still needs to be merged

Almost done with this unreasonably massive branch!

SkepticRaven commented 6 months ago

Attempted a merge of #18, and I think we need to leave that to another timepoint. Moment storage location has drastically changed and will need a new method for propagating centroid information.

dahhei commented 6 months ago

Runtime warnings encountered when calculating features (used initialize.py). Seems to only occur with np.min and np.max

/behavior-classifier/src/feature_extraction/window_operations/window_stats.py:144: RuntimeWarning: All-NaN slice encountered
  return np.min(window_values, axis=1, initial=np.nanmax(values), where=window_masks)
/behavior-classifier/src/feature_extraction/window_operations/window_stats.py:156: RuntimeWarning: All-NaN slice encountered
  return np.max(window_values, axis=1, initial=np.nanmin(values), where=window_masks)
dahhei commented 6 months ago

Error while running initialize.py.

Traceback (most recent call last):
  File "/usr/local/lib/python3.10/multiprocessing/pool.py", line 125, in worker
    result = (True, func(*args, **kwds))
  File "/behavior-classifier/initialize_project.py", line 52, in generate_files_worker
    _ = features.get_window_features(w, use_social,
  File "/behavior-classifier/src/feature_extraction/features.py", line 346, in get_window_features
    features = self.__compute_window_features(window_size)
  File "/behavior-classifier/src/feature_extraction/features.py", line 468, in __compute_window_features
    self._feature_modules[key].window(self._identity, window_size,
  File "/behavior-classifier/src/feature_extraction/feature_group_base_class.py", line 54, in window
    return {
  File "/behavior-classifier/src/feature_extraction/feature_group_base_class.py", line 55, in <dictcomp>
    name: mod.window(identity, window_size, per_frame_values[name]) for name, mod in
  File "/behavior-classifier/src/feature_extraction/feature_base_class.py", line 139, in window
    signal_features = self.window_signal(identity, window_size, per_frame_values)
  File "/behavior-classifier/src/feature_extraction/feature_base_class.py", line 162, in window_signal
    freqs, ts, Zxx = signal.stft(np.nan_to_num(per_frame, nan=0), fs=self._fps, nperseg=window_size * 2 + 1, noverlap=window_size * 2, window='hann', scaling='psd', detrend='linear')
  File "/usr/local/lib/python3.10/site-packages/scipy/signal/_spectral_py.py", line 1211, in stft
    freqs, time, Zxx = _spectral_helper(x, x, fs, window, nperseg, noverlap,
  File "/usr/local/lib/python3.10/site-packages/scipy/signal/_spectral_py.py", line 1812, in _spectral_helper
    raise ValueError('noverlap must be less than nperseg.')
ValueError: noverlap must be less than nperseg.
SkepticRaven commented 5 months ago

I was able to reproduce the second one, where fft features would crash when windows were larger than the entire file. I was not able to reproduce the warnings on the first, but added some checks that would hopefully silence them. They're only warnings and behavior is to just pass forward a NaN (which is what we want), so can ignore it.