@@ -14,9 +14,10 @@ public class MLModel<TData, TPrediction>
14
14
private readonly ITransformer _model ;
15
15
private readonly ObjectPool < PredictionFunction < TData , TPrediction > > _predictionEnginePool ;
16
16
private readonly int _minPredictionEngineObjectsInPool ;
17
+ private readonly int _maxPredictionEngineObjectsInPool ;
17
18
18
19
//Constructor with modelFilePathName to load
19
- public MLModel ( MLContext mlContext , string modelFilePathName , int minPredictionEngineObjectsInPool = 10 )
20
+ public MLModel ( MLContext mlContext , string modelFilePathName , int minPredictionEngineObjectsInPool = 10 , int maxPredictionEngineObjectsInPool = 1000 )
20
21
{
21
22
_mlContext = mlContext ;
22
23
@@ -27,25 +28,29 @@ public MLModel(MLContext mlContext, string modelFilePathName, int minPredictionE
27
28
}
28
29
29
30
_minPredictionEngineObjectsInPool = minPredictionEngineObjectsInPool ;
31
+ _maxPredictionEngineObjectsInPool = maxPredictionEngineObjectsInPool ;
30
32
31
33
//Create PredictionEngine Object Pool
32
34
_predictionEnginePool = CreatePredictionEngineObjectPool ( ) ;
33
35
}
34
36
35
37
//Constructor with ITransformer model already created
36
- public MLModel ( MLContext mlContext , ITransformer model , int minPredictionEngineObjectsInPool = 10 )
38
+ public MLModel ( MLContext mlContext , ITransformer model , int minPredictionEngineObjectsInPool = 10 , int maxPredictionEngineObjectsInPool = 1000 )
37
39
{
38
40
_mlContext = mlContext ;
39
41
_model = model ;
40
42
_minPredictionEngineObjectsInPool = minPredictionEngineObjectsInPool ;
43
+ _maxPredictionEngineObjectsInPool = maxPredictionEngineObjectsInPool ;
41
44
42
45
//Create PredictionEngine Object Pool
43
46
_predictionEnginePool = CreatePredictionEngineObjectPool ( ) ;
44
47
}
45
48
46
49
private ObjectPool < PredictionFunction < TData , TPrediction > > CreatePredictionEngineObjectPool ( )
47
50
{
48
- return new ObjectPool < PredictionFunction < TData , TPrediction > > ( ( ) => _model . MakePredictionFunction < TData , TPrediction > ( _mlContext ) , _minPredictionEngineObjectsInPool ) ;
51
+ return new ObjectPool < PredictionFunction < TData , TPrediction > > ( ( ) => _model . MakePredictionFunction < TData , TPrediction > ( _mlContext ) ,
52
+ _minPredictionEngineObjectsInPool ,
53
+ _maxPredictionEngineObjectsInPool ) ;
49
54
}
50
55
51
56
public TPrediction Predict ( TData dataSample )
0 commit comments