Esempio n. 1
0
        //推論する
        public bool Predict(float[] output_data, float[] input_data)
        {
            if (ailia == IntPtr.Zero)
            {
                return(false);
            }

            //バッファの固定
            GCHandle input_buf_handle = GCHandle.Alloc(input_data, GCHandleType.Pinned);
            IntPtr   input_buf_ptr    = input_buf_handle.AddrOfPinnedObject();

            GCHandle output_buf_handle = GCHandle.Alloc(output_data, GCHandleType.Pinned);
            IntPtr   output_buf_ptr    = output_buf_handle.AddrOfPinnedObject();

            //推論
            int status = Ailia.ailiaPredict(ailia, output_buf_ptr, (uint)(output_data.Length * 4), input_buf_ptr, (uint)(input_data.Length * 4));

            //バッファの開放
            input_buf_handle.Free();
            output_buf_handle.Free();

            if (status != Ailia.AILIA_STATUS_SUCCESS)
            {
                if (logging)
                {
                    Debug.Log("ailiaPredict failed" + status);
                }
                return(false);
            }
            return(true);
        }
Esempio n. 2
0
        public Ailia.AILIAShape GetBlobShape(string layer_name)
        {
            if (ailia == IntPtr.Zero)
            {
                return(null);
            }
            Ailia.AILIAShape shape = new Ailia.AILIAShape();
            uint             id    = 0;
            int status             = Ailia.ailiaFindBlobIndexByName(ailia, ref id, layer_name);

            if (status != Ailia.AILIA_STATUS_SUCCESS)
            {
                if (logging)
                {
                    Debug.Log("ailiaFindBlobIndexByName failed" + status);
                }
                return(null);
            }
            status = Ailia.ailiaGetBlobShape(ailia, shape, id, Ailia.AILIA_SHAPE_VERSION);
            if (status != Ailia.AILIA_STATUS_SUCCESS)
            {
                if (logging)
                {
                    Debug.Log("ailiaGetBlobShape failed" + status);
                }
                return(null);
            }
            return(shape);
        }
Esempio n. 3
0
        //AndroidのRenderScriptのパス設定
        private bool SetTemporaryCachePath()
        {
#if (UNITY_ANDROID && !UNITY_EDITOR)
            using (AndroidJavaClass unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer"))
            {
                using (AndroidJavaObject currentActivity = unityPlayer.GetStatic <AndroidJavaObject>("currentActivity"))
                {
                    using (AndroidJavaObject cacheDir = currentActivity.Call <AndroidJavaObject>("getCacheDir"))
                    {
                        string _CacheDir = cacheDir.Call <string>("getCanonicalPath");
                        int    status    = Ailia.ailiaSetTemporaryCachePath(_CacheDir);
                        if (status != Ailia.AILIA_STATUS_SUCCESS)
                        {
                            if (logging)
                            {
                                Debug.Log("ailiaSetTemporaryCachePath failed " + status);
                            }
                            return(false);
                        }
                    }
                }
            }
#endif
            return(true);
        }
Esempio n. 4
0
 //開放する
 public virtual void Close()
 {
     if (ailia != IntPtr.Zero)
     {
         Ailia.ailiaDestroy(ailia);
         ailia = IntPtr.Zero;
     }
 }
Esempio n. 5
0
        //内部データのインデックスを名前で探し取得
        public int FindBlobIndexByName(string name)
        {
            uint idx    = 0;
            int  status = Ailia.ailiaFindBlobIndexByName(ailia, ref idx, name);

            if (status != Ailia.AILIA_STATUS_SUCCESS)
            {
                if (logging)
                {
                    Debug.Log("FindBlobIndexByName failed" + status);
                }
                return(-1);
            }
            return((int)idx);
        }
Esempio n. 6
0
        //入力形式の取得
        public Ailia.AILIAShape GetInputShape()
        {
            Ailia.AILIAShape shape = new Ailia.AILIAShape();
            int status             = Ailia.ailiaGetInputShape(ailia, shape, Ailia.AILIA_SHAPE_VERSION);

            if (status != Ailia.AILIA_STATUS_SUCCESS)
            {
                if (logging)
                {
                    Debug.Log("ailiaGetInputShape failed" + status);
                }
                return(null);
            }
            return(shape);
        }
Esempio n. 7
0
        //ファイルを開く(メモリ)
        public virtual bool OpenMem(byte[] prototxt_buf, byte[] model_buf)
        {
            Close();

            if (prototxt_buf == null || model_buf == null || prototxt_buf.Length == 0 || model_buf.Length == 0)
            {
                if (logging)
                {
                    Debug.Log("input buffer is empty");
                }
                return(false);
            }

            int status = Ailia.ailiaCreate(ref ailia, env_id, Ailia.AILIA_MULTITHREAD_AUTO);

            if (status != Ailia.AILIA_STATUS_SUCCESS)
            {
                if (logging)
                {
                    Debug.Log("ailiaCreate failed " + status);
                }
                return(false);
            }

            status = Ailia.ailiaOpenStreamMem(ailia, prototxt_buf, (uint)prototxt_buf.Length);
            if (status != Ailia.AILIA_STATUS_SUCCESS)
            {
                if (logging)
                {
                    Debug.Log("ailiaOpenStreamMem failed " + status);
                }
                Close();
                return(false);
            }

            status = Ailia.ailiaOpenWeightMem(ailia, model_buf, (uint)model_buf.Length);
            if (status != Ailia.AILIA_STATUS_SUCCESS)
            {
                if (logging)
                {
                    Debug.Log("ailiaOpenWeightMem filed " + status);
                }
                Close();
                return(false);
            }

            return(true);
        }
Esempio n. 8
0
        //環境選択(詳細)
        public int GetEnvironmentCount()
        {
            SetTemporaryCachePath();
            int count  = 0;
            int status = Ailia.ailiaGetEnvironmentCount(ref count);

            if (status != Ailia.AILIA_STATUS_SUCCESS)
            {
                if (logging)
                {
                    Debug.Log("ailiaGetEnvironmentCount failed " + status);
                }
                return(-1);
            }
            return(count);
        }
Esempio n. 9
0
        //推論する
        public bool Update()
        {
            if (ailia == IntPtr.Zero)
            {
                return(false);
            }
            int status = Ailia.ailiaUpdate(ailia);

            if (status != Ailia.AILIA_STATUS_SUCCESS)
            {
                if (logging)
                {
                    Debug.Log("ailiaUpdate failed" + status);
                }
                return(false);
            }
            return(true);
        }
Esempio n. 10
0
        //Blobの形式を設定
        public bool SetInputBlobShape(Ailia.AILIAShape shape, int idx)
        {
            if (ailia == IntPtr.Zero || idx < 0)
            {
                return(false);
            }

            int status = Ailia.ailiaSetInputBlobShape(ailia, shape, (uint)idx, Ailia.AILIA_SHAPE_VERSION);

            if (status != Ailia.AILIA_STATUS_SUCCESS)
            {
                if (logging)
                {
                    Debug.Log("ailiaSetInputBlobShape failed" + status);
                }
                return(false);
            }
            return(true);
        }
Esempio n. 11
0
        public Ailia.AILIAEnvironment GetEnvironment(int idx)
        {
            IntPtr env_ptr = IntPtr.Zero;
            int    status  = Ailia.ailiaGetEnvironment(ref env_ptr, (uint)idx, Ailia.AILIA_ENVIRONMENT_VERSION);

            if (status != Ailia.AILIA_STATUS_SUCCESS)
            {
                if (logging)
                {
                    Debug.Log("ailiaGetEnvironment failed " + status);
                }
                return(null);
            }
            Ailia.AILIAEnvironment env = (Ailia.AILIAEnvironment)Marshal.PtrToStructure(env_ptr, typeof(Ailia.AILIAEnvironment));
            if (logging)
            {
                //Debug.Log("ENV id:"+env.id+", name:"+Marshal.PtrToStringAnsi(env.name)+", type:"+env.type);
            }
            return(env);
        }
Esempio n. 12
0
        //Blobの形状を取得
        public Ailia.AILIAShape GetBlobShape(int idx)
        {
            if (ailia == IntPtr.Zero || idx < 0)
            {
                return(null);
            }

            Ailia.AILIAShape shape = new Ailia.AILIAShape();
            int status             = Ailia.ailiaGetBlobShape(ailia, shape, (uint)idx, Ailia.AILIA_SHAPE_VERSION);

            if (status != Ailia.AILIA_STATUS_SUCCESS)
            {
                if (logging)
                {
                    Debug.Log("ailiaGetBlobShape failed" + status);
                }
                return(null);
            }
            return(shape);
        }
Esempio n. 13
0
        //ファイルを開く(コールバック)
        public virtual bool OpenEx(Ailia.ailiaFileCallback callback, IntPtr arg1, IntPtr arg2)
        {
            Close();

            int status = Ailia.ailiaCreate(ref ailia, env_id, Ailia.AILIA_MULTITHREAD_AUTO);

            if (status != Ailia.AILIA_STATUS_SUCCESS)
            {
                if (logging)
                {
                    Debug.Log("ailiaCreate failed" + status);
                }
                return(false);
            }

            status = Ailia.ailiaOpenStreamEx(ailia, arg1, callback, Ailia.AILIA_FILE_CALLBACK_VERSION);
            if (status != Ailia.AILIA_STATUS_SUCCESS)
            {
                if (logging)
                {
                    Debug.Log("ailiaOpenStreamFileEx failed" + status);
                }
                Close();
                return(false);
            }

            status = Ailia.ailiaOpenWeightEx(ailia, arg2, callback, Ailia.AILIA_FILE_CALLBACK_VERSION);
            if (status != Ailia.AILIA_STATUS_SUCCESS)
            {
                if (logging)
                {
                    Debug.Log("ailiaOpenWeightFileEx failed" + status);
                }
                Close();
                return(false);
            }

            return(true);
        }
Esempio n. 14
0
        //ファイルを開く(ファイル)
        public virtual bool OpenFile(string prototxt_path, string model_path)
        {
            Close();

            int status = Ailia.ailiaCreate(ref ailia, env_id, Ailia.AILIA_MULTITHREAD_AUTO);

            if (status != Ailia.AILIA_STATUS_SUCCESS)
            {
                if (logging)
                {
                    Debug.Log("ailiaCreate failed " + status);
                }
                return(false);
            }

            status = Ailia.ailiaOpenStreamFile(ailia, prototxt_path);
            if (status != Ailia.AILIA_STATUS_SUCCESS)
            {
                if (logging)
                {
                    Debug.Log("ailiaOpenStreamFile failed" + status);
                }
                Close();
                return(false);
            }

            status = Ailia.ailiaOpenWeightFile(ailia, model_path);
            if (status != Ailia.AILIA_STATUS_SUCCESS)
            {
                if (logging)
                {
                    Debug.Log("ailiaOpenWeightFile failed" + status);
                }
                Close();
                return(false);
            }

            return(true);
        }
Esempio n. 15
0
        //Blobのデータを設定
        public bool SetInputBlobData(float[] input_data, int idx)
        {
            if (ailia == IntPtr.Zero || idx < 0)
            {
                return(false);
            }

            GCHandle input_buf_handle = GCHandle.Alloc(input_data, GCHandleType.Pinned);
            IntPtr   input_buf_ptr    = input_buf_handle.AddrOfPinnedObject();
            int      status           = Ailia.ailiaSetInputBlobData(ailia, input_buf_ptr, (uint)(input_data.Length * 4), (uint)idx);

            input_buf_handle.Free();

            if (status != Ailia.AILIA_STATUS_SUCCESS)
            {
                if (logging)
                {
                    Debug.Log("ailiaSetInputBlobData failed" + status);
                }
                return(false);
            }
            return(true);
        }