Exemplo n.º 1
0
    private void Start()
    {
        // Initialize
        HeatMapCol_Squared  = HeatMapCol * HeatMapCol;
        HeatMapCol_Cube     = HeatMapCol * HeatMapCol * HeatMapCol;
        HeatMapCol_JointNum = HeatMapCol * JointNum;
        CubeOffsetLinear    = HeatMapCol * JointNum_Cube;
        CubeOffsetSquared   = HeatMapCol_Squared * JointNum_Cube;

        heatMap2D          = new float[JointNum * HeatMapCol_Squared];
        offset2D           = new float[JointNum * HeatMapCol_Squared * 2];
        heatMap3D          = new float[JointNum * HeatMapCol_Cube];
        offset3D           = new float[JointNum * HeatMapCol_Cube * 3];
        unit               = 1f / (float)HeatMapCol;
        InputImageSizeF    = InputImageSize;
        InputImageSizeHalf = InputImageSizeF / 2f;
        ImageScale         = InputImageSize / (float)HeatMapCol;// 224f / (float)InputImageSize;

        // Disabel sleep
        Screen.sleepTimeout = SleepTimeout.NeverSleep;

        // Init model
        _model  = ModelLoader.Load(NNModel, Verbose);
        _worker = BarracudaWorkerFactory.CreateWorker(WorkerType, _model, Verbose);
        StartCoroutine("WaitLoad");

        // Init VNect model
        jointPoints = VNectModel.Init();
        // Init VideoCapture
        videoCapture.Init(InputImageSize, InputImageSize);
    }
Exemplo n.º 2
0
    private IEnumerator WaitLoad()
    {
        inputs[inputName_1] = new Tensor(InitImg);
        inputs[inputName_2] = new Tensor(InitImg);
        inputs[inputName_3] = new Tensor(InitImg);

        // Create input and Execute model
        yield return(_worker.StartManualSchedule(inputs));

        // Get outputs
        for (var i = 2; i < _model.outputs.Count; i++)
        {
            b_outputs[i] = _worker.PeekOutput(_model.outputs[i]);
        }

        // Get data from outputs
        offset3D  = b_outputs[2].data.Download(b_outputs[2].shape);
        heatMap3D = b_outputs[3].data.Download(b_outputs[3].shape);

        // Release outputs
        for (var i = 2; i < b_outputs.Length; i++)
        {
            b_outputs[i].Dispose();
        }

        System.IO.File.WriteAllText("offset3D.txt", string.Join(" ", offset3D));
        // Init VNect model
        jointPoints = VNectModel.Init();

        PredictPose();

        yield return(new WaitForSeconds(WaitTimeModelLoad));

        // Init VideoCapture
        videoCapture.Init(InputImageSize, InputImageSize);
        Lock = false;
        Msg.gameObject.SetActive(false);
    }
Exemplo n.º 3
0
    private void Start()
    {
        // デバッグ用ファイルを開く
        //Encoding enc = Encoding.GetEncoding("Shift_JIS");
        //var csvPath = System.IO.Path.Combine(Application.streamingAssetsPath, "data.csv");
        //writer = new StreamWriter(csvPath, false, enc);

        if (DebugMode)
        {
            if (User3Input)
            {
                UpdateVNectModel = new UpdateVNectModelDelegate(UpdateVNectAsync);
            }
            else
            {
                UpdateVNectModel = new UpdateVNectModelDelegate(UpdateVNect);
            }

            /*
             * var streamingPath = System.IO.Path.Combine(Application.streamingAssetsPath, HighQualityModelName);
             * var writer = new BinaryWriter(new FileStream(streamingPath, FileMode.Create));
             * writer.Write(NNModel.modelData.Value);
             * writer.Close();
             */
            _model = ModelLoader.Load(NNModel, Verbose);
        }
        else
        {
            var streamingPath = System.IO.Path.Combine(Application.streamingAssetsPath, HighQualityModelName);
            if (!File.Exists(streamingPath))
            {
                ModelQuality = 0;
            }

            if (ModelQuality == 0)
            {
                InputImageSize   = 224;
                HeatMapCol       = 14;
                User3Input       = false;
                UpdateVNectModel = new UpdateVNectModelDelegate(UpdateVNect);
                _model           = ModelLoader.Load(NNModel, Verbose);
            }
            else
            {
                InputImageSize   = 448;
                HeatMapCol       = 28;
                User3Input       = true;
                UpdateVNectModel = new UpdateVNectModelDelegate(UpdateVNectAsync);
                _model           = ModelLoader.LoadFromStreamingAssets(streamingPath);
            }
        }

        // Init VideoCapture
        videoCapture.Init(InputImageSize, InputImageSize);
        videoCapture.VideoReady += videoCapture_VideoReady;

        HeatMapCol_Half     = HeatMapCol / 2;
        HeatMapCol_Squared  = HeatMapCol * HeatMapCol;
        HeatMapCol_Cube     = HeatMapCol * HeatMapCol * HeatMapCol;
        HeatMapCol_JointNum = HeatMapCol * JointNum;
        heatMap2D           = new float[JointNum * HeatMapCol_Squared];
        offset2D            = new float[JointNum * HeatMapCol_Squared * 2];
        heatMap3D           = new float[JointNum * HeatMapCol_Cube];
        offset3D            = new float[JointNum * HeatMapCol_Cube * 3];
        InputImageSizeF     = InputImageSize;
        InputImageSizeHalf  = InputImageSizeF / 2f;
        unit = 1f / (float)HeatMapCol;

        cubeOffsetLinear  = HeatMapCol * JointNum_Cube;
        cubeOffsetSquared = HeatMapCol_Squared * JointNum_Cube;

        // Disabel sleep
        Screen.sleepTimeout = SleepTimeout.NeverSleep;

        _worker = WorkerFactory.CreateWorker(WorkerType, _model, Verbose);
        StartCoroutine("WaitLoad");

        var texture = new RenderTexture(InputImageSize, InputImageSize, 0, RenderTextureFormat.RGB565, RenderTextureReadWrite.sRGB)
        {
            useMipMap        = false,
            autoGenerateMips = false,
            wrapMode         = TextureWrapMode.Clamp,
            filterMode       = FilterMode.Point,
        };

        if (User3Input)
        {
            inputs[inputName_1] = new Tensor(texture, 3);
            inputs[inputName_2] = new Tensor(texture, 3);
            inputs[inputName_3] = new Tensor(texture, 3);
            _worker.Execute(inputs);
            inputs[inputName_1].Dispose();
            inputs[inputName_2].Dispose();
            inputs[inputName_3].Dispose();
        }
        else
        {
            input = new Tensor(texture, 3);
            _worker.Execute(input);
            input.Dispose();
        }
    }
    private void Start()
    {
        if (DebugMode)
        {
            if (User3Input)
            {
                UpdateVNectModel = new UpdateVNectModelDelegate(UpdateVNectAsync);
            }
            else
            {
                UpdateVNectModel = new UpdateVNectModelDelegate(UpdateVNect);
            }

            /*
             * var streamingPath = System.IO.Path.Combine(Application.streamingAssetsPath, HighQualityModelName);
             * var writer = new BinaryWriter(new FileStream(streamingPath, FileMode.Create));
             * writer.Write(NNModel.Value);
             * writer.Close();
             */
            _model = ModelLoader.Load(NNModel, Verbose);
        }
        else
        {
            var streamingPath = System.IO.Path.Combine(Application.streamingAssetsPath, HighQualityModelName);
            if (!File.Exists(streamingPath))
            {
                ModelQuality = 0;
            }

            if (ModelQuality == 0)
            {
                InputImageSize   = 224;
                HeatMapCol       = 14;
                UpdateVNectModel = new UpdateVNectModelDelegate(UpdateVNect);
                _model           = ModelLoader.Load(NNModel, Verbose);
            }
            else
            {
                InputImageSize   = 448;
                HeatMapCol       = 28;
                UpdateVNectModel = new UpdateVNectModelDelegate(UpdateVNectAsync);
                _model           = ModelLoader.LoadFromStreamingAssets(streamingPath);
            }
        }

        HeatMapCol_Half     = HeatMapCol / 2;
        HeatMapCol_Squared  = HeatMapCol * HeatMapCol;
        HeatMapCol_Cube     = HeatMapCol * HeatMapCol * HeatMapCol;
        HeatMapCol_JointNum = HeatMapCol * JointNum;
        heatMap2D           = new float[JointNum * HeatMapCol_Squared];
        offset2D            = new float[JointNum * HeatMapCol_Squared * 2];
        heatMap3D           = new float[JointNum * HeatMapCol_Cube];
        offset3D            = new float[JointNum * HeatMapCol_Cube * 3];
        InputImageSizeF     = InputImageSize;
        InputImageSizeHalf  = InputImageSizeF / 2f;
        unit = 1f / (float)HeatMapCol;

        cubeOffsetLinear  = HeatMapCol * JointNum_Cube;
        cubeOffsetSquared = HeatMapCol_Squared * JointNum_Cube;

        // Disabel sleep
        Screen.sleepTimeout = SleepTimeout.NeverSleep;

        _worker = WorkerFactory.CreateWorker(WorkerType, _model, Verbose);
        StartCoroutine("WaitLoad");

        // Init VideoCapture
        videoCapture.Init(InputImageSize, InputImageSize);
        videoCapture.VideoReady += videoCapture_VideoReady;
    }