InferNetOnnxAutoBlineSeg.cs 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. using System.Collections.Generic;
  2. using AI.Common;
  3. using AI.Common.InferenceNetworks;
  4. using Microsoft.ML.OnnxRuntime;
  5. namespace AutoBlineCalculationLib
  6. {
  7. public class InferNetOnnxAutoBlineSeg : InferNetOnnxSemanticSegBasic
  8. {
  9. #region override
  10. /// <summary>
  11. /// 哈希值
  12. /// </summary>
  13. public override string HashCode => "e4cb7203d35e5a42fc313ba37ea112ab";
  14. /// <summary>
  15. /// 网络名
  16. /// </summary>
  17. public override string NetworkName => "BlineSegment.emd";
  18. /// <summary>
  19. /// 复制
  20. /// </summary>
  21. /// <param name="cloneMethod"></param>
  22. /// <returns></returns>
  23. public override IInferenceNetwork Clone(EnumCloneMethod cloneMethod)
  24. {
  25. if (!_modelLoaded)
  26. {
  27. return new InferNetOnnxAutoBlineSeg();
  28. }
  29. return new InferNetOnnxAutoBlineSeg(_trainedModel, _sessionOption);
  30. }
  31. #endregion
  32. #region constructor
  33. public InferNetOnnxAutoBlineSeg()
  34. {
  35. ModelParamsAssign();
  36. ConstructIntermediateVariables();
  37. }
  38. public InferNetOnnxAutoBlineSeg(byte[] trainedModel, SessionOptions sessionOption)
  39. {
  40. ModelParamsAssign();
  41. ConstructIntermediateVariables();
  42. ConstructClonedModelRelatedVariables(trainedModel, sessionOption);
  43. }
  44. #endregion
  45. #region private
  46. private void ModelParamsAssign()
  47. {
  48. _inputVariableName = "input.1";
  49. _inputAxisOrder = EnumAxisOrder.CHW;
  50. _modelInputH = 256;
  51. _modelInputW = 256;
  52. _modelInputC = 3;
  53. _outputVariableName = "575";
  54. _outputAxisOrder = EnumAxisOrder.CHW;
  55. _modelOutputC = 5;
  56. _modelOutputH = 256;
  57. _modelOutputW = 256;
  58. _resizeMode = EnumResizeMode.Warp;
  59. _meanValueType = EnumMeanValueType.None;
  60. _scaleType = EnumScaleValueType.ConstantScale;
  61. _scaleR = 1.0f;
  62. _scaleG = 1.0f;
  63. _scaleB = 1.0f;
  64. _normType = EnumNormalizationType.None;
  65. _reverseInputChannels = true;
  66. _segPostProcessParam = new Dictionary<int, SemanticSegmentationPostProcessParams>
  67. {
  68. // 1为胸膜线;2为B线;3为A线;4为肺实变
  69. { 1, new SemanticSegmentationPostProcessParams( new List<LesionAreaSelectInfo>(){new LesionAreaSelectInfo(EnumLesionAreaThresholdType.PixelInMask, 20, -1)}, 20)},
  70. { 2, new SemanticSegmentationPostProcessParams( new List<LesionAreaSelectInfo>(){new LesionAreaSelectInfo(EnumLesionAreaThresholdType.PixelInMask, 20, -1)}, 20)},
  71. { 3, new SemanticSegmentationPostProcessParams( new List<LesionAreaSelectInfo>(){new LesionAreaSelectInfo(EnumLesionAreaThresholdType.PixelInMask, 20, -1)}, 20)},
  72. { 4, new SemanticSegmentationPostProcessParams( new List<LesionAreaSelectInfo>(){new LesionAreaSelectInfo(EnumLesionAreaThresholdType.PixelInMask, 20, -1)}, 20)},
  73. };
  74. }
  75. #endregion
  76. }
  77. }