예제 #1
0
파일: YOLO.Train.cs 프로젝트: molekm/YOLOv4
        public static Model CreateV4Trainable(int inputSize, int classCount, ReadOnlySpan <int> strides)
        {
            if (inputSize <= 0)
            {
                throw new ArgumentOutOfRangeException(nameof(inputSize));
            }
            if (classCount <= 0)
            {
                throw new ArgumentOutOfRangeException(nameof(classCount));
            }

            Tensor input       = tf.keras.Input(new TensorShape(inputSize, inputSize, 3), name: "image");
            var    featureMaps = YOLOv4.Apply(input, classCount: classCount);

            var anchors = tf.constant(YOLOv4.Anchors);

            var bboxTensors = new PythonList <Tensor>();

            foreach (var(scaleIndex, featureMap) in Tools.Enumerate(featureMaps.SSBox, featureMaps.MBBox, featureMaps.LBBox))
            {
                int featuresOutputSize = (inputSize / 8) >> scaleIndex;
                var bbox = DecodeTrain(featureMap, classCount: classCount,
                                       outputSize: featuresOutputSize,
                                       anchors: anchors, strides: strides,
                                       scaleIndex: scaleIndex, xyScale: YOLOv4.XYScale);
                bboxTensors.Add(featureMap);
                bboxTensors.Add(bbox);
            }
            return(new Model(new { inputs = input, outputs = bboxTensors }.AsKwArgs()));
        }
예제 #2
0
        public static Model CreateRaw(int inputSize, int classCount)
        {
            Tensor input             = tf.keras.Input(new TensorShape(inputSize, inputSize, 3));
            var    featureMaps       = YOLOv4.Apply(input, classCount: classCount);
            var    featureMapTensors = new PythonList <Tensor> {
                featureMaps.SSBox, featureMaps.MBBox, featureMaps.LBBox
            };

            return(new Model(new { inputs = input, outputs = featureMapTensors }.AsKwArgs()));
        }
예제 #3
0
        public static Model CreateSaveable(int inputSize, int classCount,
                                           ReadOnlySpan <int> strides, Tensor <int> anchors,
                                           ReadOnlySpan <float> xyScale,
                                           float scoreThreshold)
        {
            Tensor input       = tf.keras.Input(new TensorShape(inputSize, inputSize, 3));
            var    featureMaps = YOLOv4.Apply(input, classCount: classCount);

            return(CreateSaveable(inputSize: inputSize, input: input, featureMaps,
                                  classCount: classCount,
                                  strides: strides, anchors: anchors, xyScale: xyScale,
                                  scoreThreshold: scoreThreshold));
        }
예제 #4
0
        public static Model CreateV4EvalOnly(int inputSize, int classCount)
        {
            if (inputSize <= 0)
            {
                throw new ArgumentOutOfRangeException(nameof(inputSize));
            }
            if (classCount <= 0)
            {
                throw new ArgumentOutOfRangeException(nameof(classCount));
            }

            Tensor input       = tf.keras.Input(new TensorShape(inputSize, inputSize, 3));
            var    featureMaps = YOLOv4.Apply(input, classCount: classCount);

            var bboxTensors = new PythonList <Tensor>();

            foreach (var featureMap in new[] { featureMaps.SSBox, featureMaps.MBBox, featureMaps.LBBox })
            {
                var bbox = DecodeEval(featureMap, classCount: classCount);
                bboxTensors.Add(bbox);
            }
            return(new Model(new { inputs = input, outputs = bboxTensors }.AsKwArgs()));
        }