示例#1
0
        private ObjectPool <PredictionEngine <TData, TPrediction> > CreatePredictionEngineObjectPool()
        {
            var pooledObjectPolicy = new ModelPredictionEnginePooledObjectPolicy <TData, TPrediction>(_mlContext, Model, _options, _logger);

            DefaultObjectPool <PredictionEngine <TData, TPrediction> > pool;

            if (_options.MaximumObjectsRetained != -1)
            {
                pool = new DefaultObjectPool <PredictionEngine <TData, TPrediction> >(pooledObjectPolicy, _options.MaximumObjectsRetained);
            }
            else
            {
                //default maximumRetained is Environment.ProcessorCount * 2, if not explicitly provided
                pool = new DefaultObjectPool <PredictionEngine <TData, TPrediction> >(pooledObjectPolicy);
            }

            return(pool);
        }
示例#2
0
        private void LoadPool()
        {
            var mlContext = _options.MLContext();

            Interlocked.Exchange(ref _model, _options.CreateModel(mlContext));

            var pooledObjectPolicy = new ModelPredictionEnginePooledObjectPolicy <TData, TPrediction>(mlContext, _model, _options, _logger);

            if (_options.MaximumObjectsRetained != -1)
            {
                Interlocked.Exchange(ref _pool, new DefaultObjectPool <PredictionEngine <TData, TPrediction> >(pooledObjectPolicy, _options.MaximumObjectsRetained));
            }
            else
            {
                // default maximumRetained is Environment.ProcessorCount * 2, if not explicitly provided
                Interlocked.Exchange(ref _pool, new DefaultObjectPool <PredictionEngine <TData, TPrediction> >(pooledObjectPolicy));
            }

            _logger.LogDebug(
                "[{className}][{methodName}] ML.NET Model name: {modelName}",
                nameof(ModelPredictionEngineObjectPool <TData, TPrediction>),
                nameof(LoadPool),
                _options.ModelName);
        }