Skip to content

Commit ac28194

Browse files
committed
- Redesigned disposing code for objects which interact with inference sessions
1 parent d69eaba commit ac28194

File tree

8 files changed

+30
-8
lines changed

8 files changed

+30
-8
lines changed

src/MOT.CORE/Matchers/Abstract/Matcher.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
using MOT.CORE.Utils.Pool;
22
using MOT.CORE.YOLO;
3+
using System;
34
using System.Collections.Generic;
45
using System.Drawing;
56
using System.Linq;
67
using System.Runtime.CompilerServices;
78

89
namespace MOT.CORE.Matchers.Abstract
910
{
10-
public abstract class Matcher
11+
public abstract class Matcher : IDisposable
1112
{
1213
private int _startTrackerIndex = 1;
1314

@@ -66,5 +67,7 @@ protected virtual void InitNewTrack<TTracker, TTrack>(TTracker tracker, TTrack t
6667
if (_startTrackerIndex == int.MaxValue)
6768
_startTrackerIndex = 1;
6869
}
70+
71+
public abstract void Dispose();
6972
}
7073
}

src/MOT.CORE/Matchers/Deep/DeepMatcher.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,12 @@ public override IReadOnlyList<ITrack> Run(Bitmap frame, float targetConfidence,
5757
return tracks;
5858
}
5959

60+
public override void Dispose()
61+
{
62+
_predictor.Dispose();
63+
_appearanceExtractor.Dispose();
64+
}
65+
6066
[MethodImpl(MethodImplOptions.AggressiveInlining)]
6167
private List<DeepTrack> Init(IReadOnlyList<IPrediction> detectedObjects, IReadOnlyList<Vector> appearances)
6268
{

src/MOT.CORE/Matchers/Deep/DeepSortMatcher.cs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ public class DeepSortMatcher : Matcher
2222
private List<PoolObject<KalmanTracker<DeepSortTrack>>> _trackers = new List<PoolObject<KalmanTracker<DeepSortTrack>>>();
2323

2424
public DeepSortMatcher(IPredictor predictor, IAppearanceExtractor appearanceExtractor,
25-
float appearanceWeight = 0.775f, float threshold = 0.765f, int maxMisses = 50,
26-
int framesToAppearanceSmooth = 70, float smoothAppearanceWeight = 0.875f,
27-
int minStreak = 5, int poolCapacity = 50)
25+
float appearanceWeight = 0.775f, float threshold = 0.5f, int maxMisses = 50,
26+
int framesToAppearanceSmooth = 40, float smoothAppearanceWeight = 0.875f,
27+
int minStreak = 8, int poolCapacity = 50)
2828
: base(maxMisses, minStreak)
2929
{
3030
_predictor = predictor;
@@ -68,6 +68,12 @@ public override IReadOnlyList<ITrack> Run(Bitmap frame, float targetConfidence,
6868
return tracks;
6969
}
7070

71+
public override void Dispose()
72+
{
73+
_predictor.Dispose();
74+
_appearanceExtractor.Dispose();
75+
}
76+
7177
[MethodImpl(MethodImplOptions.AggressiveInlining)]
7278
private List<DeepSortTrack> Init(IReadOnlyList<IPrediction> detectedObjects, IReadOnlyList<Vector> appearances)
7379
{

src/MOT.CORE/Matchers/SORT/SortMatcher.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@ public override IReadOnlyList<ITrack> Run(Bitmap frame, float targetConfidence,
5252
return tracks;
5353
}
5454

55+
public override void Dispose()
56+
{
57+
_predictor.Dispose();
58+
}
59+
5560
[MethodImpl(MethodImplOptions.AggressiveInlining)]
5661
private List<SortTrack> Init(IReadOnlyList<IPrediction> detectedObjects)
5762
{

src/MOT.CORE/ReID/IAppearanceExtractor.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
using MOT.CORE.Utils.DataStructs;
22
using MOT.CORE.YOLO;
3+
using System;
34
using System.Collections.Generic;
45
using System.Drawing;
56

67
namespace MOT.CORE.ReID
78
{
8-
public interface IAppearanceExtractor
9+
public interface IAppearanceExtractor : IDisposable
910
{
1011
public abstract IReadOnlyList<Vector> Predict(Bitmap image, IPrediction[] detectedBounds);
1112
}

src/MOT.CORE/ReID/ReidScorer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
namespace MOT.CORE.ReID
1414
{
15-
public class ReidScorer<TReidModel> : IDisposable, IAppearanceExtractor where TReidModel : IReidModel
15+
public class ReidScorer<TReidModel> : IAppearanceExtractor where TReidModel : IReidModel
1616
{
1717
private readonly IReidModel _reidModel;
1818
private readonly List<InferenceSession> _inferenceSessions;

src/MOT.CORE/YOLO/IPredictor.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
using System.Drawing;
22
using System.Collections.Generic;
3+
using System;
34

45
namespace MOT.CORE.YOLO
56
{
6-
public interface IPredictor
7+
public interface IPredictor : IDisposable
78
{
89
public abstract IReadOnlyList<IPrediction> Predict(Bitmap image, float targetConfidence, params DetectionObjectType[] targetDetectionTypes);
910
}

src/MOT.CORE/YOLO/YoloScorer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
namespace MOT.CORE.YOLO
1717
{
18-
public class YoloScorer<TYoloModel> : IDisposable, IPredictor where TYoloModel : IYoloModel
18+
public class YoloScorer<TYoloModel> : IPredictor where TYoloModel : IYoloModel
1919
{
2020
private readonly InferenceSession _inferenceSession;
2121
private readonly TYoloModel _yoloModel;

0 commit comments

Comments
 (0)