You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi,
I'm using the fill_missing function in the analysis example. However, I found sometimes the plot is 'jumpy'. I checked the prediction and I found it was because some frames in the new video are predicted very far from the actual location or previous frame location. Since the wrong prediction is only for few frames, and usually the next frame is predicted correctly, I wonder if there's code can help to address this problem, or if SLEAP can avoid this problem(like set a range for the position change in pixels between each frame).
from scipy.interpolate import interp1d
def fill_missing(Y, kind="linear"):
"""Fills missing values independently along each dimension after the first."""
# Store initial shape.
initial_shape = Y.shape
# Flatten after first dim.
Y = Y.reshape((initial_shape[0], -1))
# Interpolate along each slice.
for i in range(Y.shape[-1]):
y = Y[:, i]
# Build interpolant.
x = np.flatnonzero(~np.isnan(y))
f = interp1d(x, y[x], kind=kind, fill_value=np.nan, bounds_error=False)
# Fill missing
xq = np.flatnonzero(np.isnan(y))
y[xq] = f(xq)
# Fill leading or trailing NaNs with the nearest non-NaN values
mask = np.isnan(y)
y[mask] = np.interp(np.flatnonzero(mask), np.flatnonzero(~mask), y[~mask])
# Save slice
Y[:, i] = y
# Restore to initial shape.
Y = Y.reshape(initial_shape)
return Y
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hi,
I'm using the
fill_missing
function in the analysis example. However, I found sometimes the plot is 'jumpy'. I checked the prediction and I found it was because some frames in the new video are predicted very far from the actual location or previous frame location. Since the wrong prediction is only for few frames, and usually the next frame is predicted correctly, I wonder if there's code can help to address this problem, or if SLEAP can avoid this problem(like set a range for the position change in pixels between each frame).from scipy.interpolate import interp1d
def fill_missing(Y, kind="linear"):
"""Fills missing values independently along each dimension after the first."""
Beta Was this translation helpful? Give feedback.
All reactions