123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159 |
- using System;
- using System.Collections.Generic;
- using System.Text;
- using AI.Common.Implements;
- using AI.Common.Interface;
- namespace YOLOInstanceSegProcessLib
- {
- public class InferNetOnnxInstanceSegYOLOV5 : InferNetOnnxInstanceSegYOLOBasic
- {
- #region override
- protected override string NetworkHashCode => "6a6fd0d2fcc4b280177c15c5c4324c82";
- public override string NetworkName => "ThyroidLesionSegYOLOV5.emd";
- /// <summary>
- /// 复制
- /// </summary>
- /// <returns></returns>
- public override IInferenceNetwork Clone()
- {
- if (!_modelLoaded)
- {
- return new InferNetOnnxInstanceSegYOLOV5();
- }
- return new InferNetOnnxInstanceSegYOLOV5(_trainedModel, _numCPU);
- }
- #endregion
- #region constructor
- public InferNetOnnxInstanceSegYOLOV5()
- {
- ModelParamsAssign();
- ConstructIntermediateVariables();
- }
- public InferNetOnnxInstanceSegYOLOV5(byte[] trainedModel, int numCPU)
- {
- ModelParamsAssign();
- ConstructIntermediateVariables();
- ConstructClonedModelRelatedVariables(trainedModel, numCPU);
- }
- private void ModelParamsAssign()
- {
- _inputTensorNames = new[] { "images" };
- _inputAxisOrder = EnumAxisOrder.CHW;
- _outputTensorNames = new[] { "output0", "output1" };
- _meanValueType = EnumMeanValueType.None;
- _meanR = 0;
- _meanG = 0;
- _meanB = 0;
- _resizeMode = EnumResizeMode.Warp;
- _meanValueType = EnumMeanValueType.None;
- _scaleType = EnumScaleValueType.ConstantScale;
- _scaleR = 255;
- _scaleG = 255;
- _scaleB = 255;
- _normType = EnumNormalizationType.None;
- _channelOrder = EnumChannelOrder.RGB;
- _yoloType = YoloType.yolov5;
- _boxConfThres = 0.5f;
- _clsConfThres = 0.5f;
- _batchSize = 1;
- _maxDet = 100;
- _minBoxRatio = 0.001f;
- _postProcessTopK = 6400;
- _enableIouFilt = true;
- _enableIosFilt = true;
- _iouFltth = 0.3f;
- _iosFltth = 0.3f;
- _enableIouFiltDiffCls = true;
- _enableIosFiltDiffCls = true;
- _iouFltthDiffCls = 0.5f;
- _iosFltthDiffCls = 0.5f;
- _maskThres = 0.7f;
- //模型输入输出的尺寸,netron直接读取即可,此处可以直接赋值,暂时放这边是为了大家理解输出的组成
- _inputVariableShapes = new List<int[]> { new int[] { 1, 3, 320, 320 } };
- _outputVariableShapes = new List<int[]> { new int[] { 1, 6300, 6 + 5 + 32 },
- new int[] { 1, 32, 80, 80 } };
- _segPostProcessParam = new Dictionary<int, InstanceSegmentationPostProcessParams>
- {
- // 1:TIRADS 2
- { 1, new InstanceSegmentationPostProcessParams( new List<LesionAreaSelectInfo>(){new LesionAreaSelectInfo(EnumLesionAreaThresholdType.RatioInMask, 1.0f/1000, 1.0f),
- new LesionAreaSelectInfo(EnumLesionAreaThresholdType.PixelInOrigImg, 0, 50000)}, 5)},
- // 2:TIRADS 3
- { 2, new InstanceSegmentationPostProcessParams( new List<LesionAreaSelectInfo>(){new LesionAreaSelectInfo(EnumLesionAreaThresholdType.RatioInMask, 1.0f/1000, 1.0f)}, 5)},
-
- // 3:TIRADS 4a
- { 3, new InstanceSegmentationPostProcessParams( new List<LesionAreaSelectInfo>(){new LesionAreaSelectInfo(EnumLesionAreaThresholdType.RatioInMask, 1.0f/1000, 1.0f)}, 5)},
- //// 4:TIRADS 4b
- { 4, new InstanceSegmentationPostProcessParams( new List<LesionAreaSelectInfo>(){new LesionAreaSelectInfo(EnumLesionAreaThresholdType.RatioInMask, 1.0f/1000, 1.0f)}, 5)},
- // 5:TIRADS 4c
- { 5, new InstanceSegmentationPostProcessParams( new List<LesionAreaSelectInfo>(){new LesionAreaSelectInfo(EnumLesionAreaThresholdType.RatioInMask, 1.0f/1000, 1.0f)}, 5)},
- // 6:TIRADS 5
- { 6, new InstanceSegmentationPostProcessParams( new List<LesionAreaSelectInfo>(){new LesionAreaSelectInfo(EnumLesionAreaThresholdType.RatioInMask, 1.0f/1000, 1.0f)}, 5)},
- };
- ConfidenceMapInfo confidenceMap = new ConfidenceMapInfo(0.5f, 1.0f, 0.5f, 0.9f);
- _confidenceMapInfo = new Dictionary<int, ConfidenceMapInfo>
- {
- { 1, confidenceMap},
- { 2, confidenceMap},
- { 3, confidenceMap},
- { 4, confidenceMap},
- { 5, confidenceMap},
- };
- var validTypes = new List<Type>
- {
- typeof(LesionMalignantDegreeLabelExtraInfo),
- typeof(LesionInvolvedScopeLabelExtraInfo),
- };
- _labelGroup = new LabelGroup("AI.Vaid.Thyroid.FocalLesion", validTypes);
- _labelGroup.RegistLabel(0, "NoObviousLesion");
- _labelGroup.RegistLabel(1, "TI-RADS 2", new List<ILabelExtraInfo>
- {
- new LesionMalignantDegreeLabelExtraInfo(EnumLesionMalignantDegree.BenignLesion),
- new LesionInvolvedScopeLabelExtraInfo(EnumLesionInvolvedScope.FocalLesion),
- });
- _labelGroup.RegistLabel(2, "TI-RADS 3", new List<ILabelExtraInfo>
- {
- new LesionMalignantDegreeLabelExtraInfo(EnumLesionMalignantDegree.BenignLesion),
- new LesionInvolvedScopeLabelExtraInfo(EnumLesionInvolvedScope.FocalLesion),
- });
- _labelGroup.RegistLabel(3, "TI-RADS 4a", new List<ILabelExtraInfo>
- {
- new LesionMalignantDegreeLabelExtraInfo(EnumLesionMalignantDegree.MalignantLesion),
- new LesionInvolvedScopeLabelExtraInfo(EnumLesionInvolvedScope.FocalLesion),
- });
- _labelGroup.RegistLabel(4, "TI-RADS 4b", new List<ILabelExtraInfo>
- {
- new LesionMalignantDegreeLabelExtraInfo(EnumLesionMalignantDegree.MalignantLesion),
- new LesionInvolvedScopeLabelExtraInfo(EnumLesionInvolvedScope.FocalLesion),
- });
- _labelGroup.RegistLabel(5, "TI-RADS 4c", new List<ILabelExtraInfo>
- {
- new LesionMalignantDegreeLabelExtraInfo(EnumLesionMalignantDegree.MalignantLesion),
- new LesionInvolvedScopeLabelExtraInfo(EnumLesionInvolvedScope.FocalLesion),
- });
- _labelGroup.RegistLabel(6, "TI-RADS 5", new List<ILabelExtraInfo>
- {
- new LesionMalignantDegreeLabelExtraInfo(EnumLesionMalignantDegree.MalignantLesion),
- new LesionInvolvedScopeLabelExtraInfo(EnumLesionInvolvedScope.FocalLesion),
- });
- }
- #endregion
- }
- }
|