Exemple #1
0
        /// <summary>
        /// ML.NET uses IEnumerable to pass into the input layer
        /// </summary>
        /// <returns>IEnumerable of this object</returns>
        public IEnumerable <HeadPoseObject> getHeadPoseIEnumerable()
        {
            IEnumerable <HeadPoseObject> objects = new HeadPoseObject[] { this };

            return(objects);
        }
Exemple #2
0
        private void ReceiveData(HeadPose input, Envelope envelope)
        {
            // input: T_x, T_y, T_z, R_x, R_y, R_z
            List <float> inputTRTRTransDiff = new List <float>(); //T_x, T_y, T_z, R_x, R_y, R_z, diff_Tx, diff_Ty, diff_Tz, diff_Rx, diff_Ry, diff_Rz
            List <float> inputTRTRDiffDiff2 = new List <float>(); //diff_Tx, diff_Ty, diff_Tz, diff_Rx, diff_Ry, diff_Rz, diff2_Tx, diff2_Ty, diff2_Tz, diff2_Rx, diff2_Ry, diff2_Rz

            // calculate diff of T_x, T_y, T_z, R_x, R_y, R_z

            for (int i = 0; i < input.Count(); i++)
            {
                inputTRTRTransDiff.Add((float)input[i]);
            }
            for (int i = 0; i < input.Count(); i++)
            {
                inputTRTRTransDiff.Add((float)input[i] - dataQueueTransDiff.Last()[i]);
            }
            // calculate diff and diff2 of T_x, T_y, T_z, R_x, R_y, R_z
            // add diff

            for (int i = 0; i < input.Count(); i++)
            {
                inputTRTRDiffDiff2.Add(inputTRTRTransDiff[input.Count + i]);
            }
            // add diff2
            for (int i = 0; i < input.Count(); i++)
            {
                inputTRTRDiffDiff2.Add(inputTRTRDiffDiff2[i] - lastInputTRTRDiffDiff2[i]);
            }


            // reorder into diff_Tx, diff_Ty, diff2_Tx, diff2_Ty, diff2_Tz, diff_Tz, diff_Rx, diff_Ry, diff_Rz, diff2_Rx, diff2_Ry, diff2_Rz
            List <float> inputTTRRDiffDiff2 = deepCopyList(inputTRTRDiffDiff2);


            for (int i = 3; i < 6; i++)
            {
                inputTTRRDiffDiff2[i] = inputTRTRDiffDiff2[i + 3];
            }
            for (int i = 6; i < 9; i++)
            {
                inputTTRRDiffDiff2[i] = inputTRTRDiffDiff2[i - 3];
            }


            lastInputTRTRDiffDiff2 = inputTRTRDiffDiff2;
            dataQueueTransDiff.AddLast(inputTRTRTransDiff);
            dataQueueTTRRDiffDiff2.AddLast(inputTTRRDiffDiff2);


            if (dataQueueTransDiff.Count() > NUM_OF_FRAME)
            {
                dataQueueTransDiff.RemoveFirst();
            }
            if (dataQueueTTRRDiffDiff2.Count() > NUM_OF_FRAME)
            {
                dataQueueTTRRDiffDiff2.RemoveFirst();
            }

            // flatten the whole list
            List <float>         networkInput  = new List <float>();
            List <List <float> > dataQueueList = dataQueueTTRRDiffDiff2.ToList();


            //row major
            for (int i = 0; i < dataQueueList.Count(); i++)
            {
                for (int j = 0; j < dataQueueList[i].Count; j++)
                {
                    networkInput.Add(dataQueueList[i][j]);
                }
            }

            try {
                // evaluate using the model
                HeadPoseObject headPoseObj          = new HeadPoseObject(networkInput);
                IEnumerable <HeadPoseObject> images = headPoseObj.getHeadPoseIEnumerable();
                IDataView             imageDataView = mlContext.Data.LoadFromEnumerable(images);
                IEnumerable <float[]> probabilities = modelScorer.Score(imageDataView);
                var probList = probabilities.ToList();

                Out.Post(probList[0][31], envelope.OriginatingTime);
            } catch (Exception ex) {
                Console.WriteLine(ex.ToString());
            }
        }