Beispiel #1
0
        private static FloatPair get_rnn_vid_data(Network net, string[] files, int n, int batch, int steps)
        {
            int   b;
            Image outIm      = Network.get_network_image(net);
            int   outputSize = outIm.W * outIm.H * outIm.C;

            Console.Write($"%d %d %d\n", outIm.W, outIm.H, outIm.C);
            float[] feats = new float[net.Batch * batch * outputSize];
            for (b = 0; b < batch; ++b)
            {
                int     inputSize = net.W * net.H * net.C;
                float[] input     = new float[inputSize * net.Batch];
                string  filename  = files[Utils.Rand.Next() % n];
                using (VideoCapture cap = new VideoCapture(filename))
                {
                    int frames = (int)cap.GetCaptureProperty(CapProp.FrameCount);
                    int index  = Utils.Rand.Next() % (frames - steps - 2);
                    if (frames < (steps + 4))
                    {
                        --b;
                        continue;
                    }

                    Console.Write($"frames: %d, index: %d\n", frames, index);
                    cap.SetCaptureProperty(CapProp.PosFrames, index);

                    int i;
                    for (i = 0; i < net.Batch; ++i)
                    {
                        using (Mat src = cap.QueryFrame())
                        {
                            Image im = new Image(src);

                            LoadArgs.rgbgr_image(im);
                            Image re = LoadArgs.resize_image(im, net.W, net.H);
                            Array.Copy(re.Data, 0, input, i * inputSize, inputSize);
                        }
                    }

                    float[] output = Network.network_predict(net, input);

                    for (i = 0; i < net.Batch; ++i)
                    {
                        Array.Copy(output, i * outputSize, feats, (b + i * batch) * outputSize, outputSize);
                    }
                }
            }

            FloatPair p = new FloatPair();

            p.X = feats;
            p.Y = new float[feats.Length - outputSize * batch];
            Array.Copy(feats, outputSize * batch, p.Y, 0, p.Y.Length);

            return(p);
        }