Skip to content

Commit 65aa81b

Browse files
committed
Only load half precision through python
1 parent f3968c1 commit 65aa81b

1 file changed

Lines changed: 12 additions & 9 deletions

File tree

SharpEyes/ViewModels/MotionEnergyViewModel.cs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
using Avalonia.Threading;
1414
using Mat = OpenCvSharp.Mat;
1515
using NumSharp;
16+
using Num = NumSharp.np;
1617
using ReactiveUI;
1718
using SharpEyes.Models;
1819
using Eyetracking;
@@ -1437,12 +1438,12 @@ private void ComputeNormalizationStatistics()
14371438
return;
14381439
}
14391440

1440-
NDArray columnMaxes = np.amax(_motionEnergyFeatures, axis: 0);
1441+
NDArray columnMaxes = Num.amax(_motionEnergyFeatures, axis: 0);
14411442
_perFilterMax = columnMaxes.ToArray<float>();
1442-
_globalMax = (float)np.amax(_motionEnergyFeatures);
1443+
_globalMax = (float)Num.amax(_motionEnergyFeatures);
14431444

1444-
NDArray columnMeans = np.mean(_motionEnergyFeatures, axis: 0);
1445-
NDArray columnStds = np.std(_motionEnergyFeatures, axis: 0);
1445+
NDArray columnMeans = Num.mean(_motionEnergyFeatures, axis: 0);
1446+
NDArray columnStds = Num.std(_motionEnergyFeatures, axis: 0);
14461447
_perFilterPercentile = (columnMeans + 2.326 * columnStds).ToArray<float>();
14471448
}
14481449

@@ -1914,13 +1915,16 @@ public async void LoadSavedFeatures()
19141915
gazeLocations[frameIndex, 1] = meta.GazeSpaceHeight / 2.0;
19151916
}
19161917
}
1917-
1918-
// Load the feature array (float32) through Python so lower-dtype saves read back correctly.
1919-
NDArray features = await Task.Run(() =>
1918+
1919+
int dtypeIndex = OutputDtypeNames.IndexOf(meta.OutputDtype);
1920+
// Load the feature array
1921+
// dtype == 0 is float16, which numsharp does not support, so that has to go through python
1922+
// the other kinds can be loaded from numsharp
1923+
NDArray features = dtypeIndex == 0 ? await Task.Run(() =>
19201924
{
19211925
PythonEnvironmentManager.Instance.Initialize();
19221926
return motionEnergyFeatures.LoadFeatures(featuresPath);
1923-
});
1927+
}) : Num.load(featuresPath).astype(NPTypeCode.Single);
19241928

19251929
// Apply parsed parameters via the public setters so the UI updates.
19261930
ResetDynamicState();
@@ -1929,7 +1933,6 @@ public async void LoadSavedFeatures()
19291933
FrameScale = meta.FrameScale;
19301934
VideoFps = meta.VideoFps;
19311935
StartFrame = meta.StartFrame;
1932-
int dtypeIndex = OutputDtypeNames.IndexOf(meta.OutputDtype);
19331936
if (dtypeIndex >= 0) SelectedOutputDtypeIndex = dtypeIndex;
19341937

19351938
SpatialFrequencies.Clear();

0 commit comments

Comments
 (0)