예제 #1
0
 public override void Dispose()
 {
     sess?.Dispose();
     sess = null;
     model?.Dispose();
     model = null;
 }
        private async Task LoadModelAsync()
        {
            Debug.Write("LoadModelBegin | ");

            Debug.Write("LoadModel Lock | ");

            _binding?.Clear();
            _session?.Dispose();

            StorageFile modelFile = await StorageFile.GetFileFromApplicationUriAsync(new Uri($"ms-appx:///Assets/{_appModel.ModelSource}.onnx"));

            _learningModel = await LearningModel.LoadFromStorageFileAsync(modelFile);

            _inferenceDeviceSelected = UseGpu ? LearningModelDeviceKind.DirectX : LearningModelDeviceKind.Cpu;

            // Lock so can't create a new session or binding while also being disposed
            lock (_processLock)
            {
                _session = new LearningModelSession(_learningModel, new LearningModelDevice(_inferenceDeviceSelected));
                _binding = new LearningModelBinding(_session);
            }

            debugModelIO();
            _inputImageDescription  = _learningModel.InputFeatures.ToList().First().Name;
            _outputImageDescription = _learningModel.OutputFeatures.ToList().First().Name;

            Debug.Write("LoadModel Unlock\n");
        }
 void Reset()
 {
     // let everything go in reverse order, taking care to dispose
     _session.Dispose();
     _session = null;
     _model.Dispose();
     _model = null;
 }
예제 #4
0
        private void RecreateSessions()
        {
            tensorizationSession_?.Dispose();
            tensorizationSession_ =
                CreateLearningModelSession(
                    TensorizationModels.ReshapeFlatBufferToNCHW(
                        1,
                        4,
                        currentImageHeight_,
                        currentImageWidth_));

            resizeEffectSession_?.Dispose();
            resizeEffectSession_ = GetEffect(ResizeToggleSplitButton, ResizePicker);

            pixelSwizzleEffectSession_?.Dispose();
            pixelSwizzleEffectSession_ = GetPixelSwizzleEffect();

            blurSharpenEffectSession_?.Dispose();
            blurSharpenEffectSession_ = GetEffect(BlurSharpenToggleSplitButton, BlurSharpenPicker);

            contrastEffectSession_?.Dispose();
            contrastEffectSession_ = ContrastToggleSplitButton.IsChecked ?
                                     CreateLearningModelSession(TensorizationModels.AdjustBrightnessAndContrast(
                                                                    1,
                                                                    3,
                                                                    resizeEffectSession_ != null ? 224 : currentImageHeight_,
                                                                    resizeEffectSession_ != null ? 224 : currentImageWidth_)) :
                                     null;

            artisticEffectsEffectSession_?.Dispose();
            artisticEffectsEffectSession_ = GetEffect(ArtisticEffectsToggleSplitButton, ArtisticEffectsPicker);

            orientationEffectSession_?.Dispose();
            orientationEffectSession_ = GetOrientationEffect();

            shapeSession_?.Dispose();
            shapeSession_ = CreateLearningModelSession(TensorizationModels.ShapeNCHW(1, 3, currentImageHeight_, currentImageWidth_));

            detensorizationSession_?.Dispose();
            detensorizationSession_ = CreateLearningModelSession(TensorizationModels.IdentityNCHW(
                                                                     1,
                                                                     3,
                                                                     resizeEffectSession_ != null ? 224 : currentImageHeight_,
                                                                     resizeEffectSession_ != null ? 224 : currentImageWidth_));
        }
        public void CleanUp()
        {
            if (!_isInitialized)
            {
                throw new InvalidOperationException("Service not initialized.");
            }

            CameraService.Current.SoftwareBitmapFrameCaptured -= Current_SoftwareBitmapFrameCaptured;

            _current = null;
            _model.Dispose();
            _session.Dispose();
            _model   = null;
            _session = null;

            Debug.WriteLine("The evaluation event handler should have been removed");
            _isInitialized = false;
        }
예제 #6
0
 public void Dispose()
 {
     session?.Dispose();
     model?.Dispose();
 }