InferNetOnnxNerveSeg.cs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. using AI.Common;
  2. using AI.Common.InferenceNetworks;
  3. using Microsoft.ML.OnnxRuntime;
  4. using System.Collections.Generic;
  5. namespace NerveIdentificationLib
  6. {
  7. /// <summary>
  8. /// 分割神经
  9. /// </summary>
  10. public class InferNetOnnxNerveSeg: InferNetOnnxSemanticSegBasic
  11. {
  12. #region override
  13. /// <summary>
  14. /// 哈希值
  15. /// </summary>
  16. public override string HashCode => "283f7ec736b2570d9a09fc79264d76f7";
  17. /// <summary>
  18. /// 网络名
  19. /// </summary>
  20. public override string NetworkName => "Nerve-ContourSeg.emd";
  21. /// <summary>
  22. /// 后处理
  23. /// </summary>
  24. /// <param name="image"></param>
  25. /// <returns></returns>
  26. public override IDetectedObject[] PostProcess(InferenceNetworkInputImage image)
  27. {
  28. // 调用基类的Process
  29. var results = base.PostProcess(image);
  30. return results;
  31. }
  32. /// <summary>
  33. /// 复制
  34. /// </summary>
  35. /// <param name="cloneMethod"></param>
  36. /// <returns></returns>
  37. public override IInferenceNetwork Clone(EnumCloneMethod cloneMethod)
  38. {
  39. if (!_modelLoaded)
  40. {
  41. return new InferNetOnnxNerveSeg();
  42. }
  43. return new InferNetOnnxNerveSeg(_trainedModel, _sessionOption);
  44. }
  45. #endregion
  46. #region constructor
  47. public InferNetOnnxNerveSeg()
  48. {
  49. ModelParamsAssign();
  50. ConstructIntermediateVariables();
  51. }
  52. public InferNetOnnxNerveSeg(byte[] trainedModel, SessionOptions sessionOption)
  53. {
  54. ModelParamsAssign();
  55. ConstructIntermediateVariables();
  56. ConstructClonedModelRelatedVariables(trainedModel, sessionOption);
  57. }
  58. #endregion
  59. #region private funcs
  60. private void ModelParamsAssign()
  61. {
  62. _inputVariableName = "input.1";
  63. _inputAxisOrder = EnumAxisOrder.CHW;
  64. _modelInputC = 3;
  65. _modelInputH = 256;
  66. _modelInputW = 256;
  67. _outputVariableName = "755";
  68. _outputAxisOrder = EnumAxisOrder.CHW;
  69. _modelOutputC = 4;
  70. _modelOutputH = 256;
  71. _modelOutputW = 256;
  72. _resizeMode = EnumResizeMode.Warp;
  73. _meanValueType = EnumMeanValueType.None;
  74. _scaleType = EnumScaleValueType.ConstantScale;
  75. _scaleR = 255;
  76. _scaleG = 255;
  77. _scaleB = 255;
  78. _normType = EnumNormalizationType.None;
  79. _reverseInputChannels = true;
  80. _segPostProcessParam = new Dictionary<int, SemanticSegmentationPostProcessParams>
  81. {
  82. // 神经
  83. { 1, new SemanticSegmentationPostProcessParams(new List<LesionAreaSelectInfo>(){new LesionAreaSelectInfo(EnumLesionAreaThresholdType.RatioInMask, 1.0f/100, 1.0f)}, 5)},
  84. // 动脉
  85. { 2, new SemanticSegmentationPostProcessParams(new List<LesionAreaSelectInfo>(){new LesionAreaSelectInfo(EnumLesionAreaThresholdType.RatioInMask, 1.0f/100, 1.0f)}, 2)},
  86. // 静脉
  87. { 3, new SemanticSegmentationPostProcessParams(new List<LesionAreaSelectInfo>(){new LesionAreaSelectInfo(EnumLesionAreaThresholdType.RatioInMask, 1.0f/100, 1.0f)}, 2)},
  88. };
  89. }
  90. #endregion
  91. }
  92. }