├── .gitignore ├── Assets ├── Materials.meta ├── Materials │ ├── red.mat │ └── red.mat.meta ├── Scenes.meta ├── Scenes │ ├── BlazePose.meta │ └── BlazePose │ │ ├── BlazePose.unity │ │ ├── BlazePose.unity.meta │ │ ├── BlazePoseSample.cs │ │ ├── BlazePoseSample.cs.meta │ │ ├── PoseDetect.cs │ │ ├── PoseDetect.cs.meta │ │ ├── PoseLandmarkDetect.cs │ │ ├── PoseLandmarkDetect.cs.meta │ │ ├── PoseLandmarks.cs │ │ ├── PoseLandmarks.cs.meta │ │ ├── pose-landmarks-map.png │ │ └── pose-landmarks-map.png.meta ├── StreamingAssets.meta ├── StreamingAssets │ ├── mediapipe.meta │ └── mediapipe │ │ ├── palm_detection_builtin_256_float16_quant.tflite │ │ ├── palm_detection_builtin_256_float16_quant.tflite.meta │ │ ├── pose_detection.tflite │ │ ├── pose_detection.tflite.meta │ │ ├── pose_landmark_lite.tflite │ │ └── pose_landmark_lite.tflite.meta ├── _Scripts.meta ├── _Scripts │ ├── UIToggles.cs │ └── UIToggles.cs.meta ├── link.xml └── link.xml.meta ├── Packages ├── com.github.asus4.mediapipe │ ├── Editor.meta │ ├── Editor │ │ ├── MediaPipe.Editor.asmdef │ │ ├── MediaPipe.Editor.asmdef.meta │ │ ├── SsdAnchorsCalculatorTest.cs │ │ ├── SsdAnchorsCalculatorTest.cs.meta │ │ ├── TestData.meta │ │ └── TestData │ │ │ ├── anchor_golden_file_0.txt │ │ │ ├── anchor_golden_file_0.txt.meta │ │ │ ├── anchor_golden_file_1.txt │ │ │ └── anchor_golden_file_1.txt.meta │ ├── Runtime.meta │ ├── Runtime │ │ ├── LowPassFilter.cs │ │ ├── LowPassFilter.cs.meta │ │ ├── MediaPipe.asmdef │ │ ├── MediaPipe.asmdef.meta │ │ ├── RectTransformationCalculator.cs │ │ ├── RectTransformationCalculator.cs.meta │ │ ├── RelativeVelocityFilter.cs │ │ ├── RelativeVelocityFilter.cs.meta │ │ ├── SsdAnchor.cs │ │ └── SsdAnchor.cs.meta │ ├── package.json │ └── package.json.meta ├── com.github.asus4.tflite.common │ ├── Editor.meta │ ├── Editor │ │ ├── ArrayExtensionTest.cs │ │ ├── ArrayExtensionTest.cs.meta │ │ ├── MathTFTest.cs │ │ ├── MathTFTest.cs.meta │ │ ├── TensorFlowLite.Common.Editor.asmdef │ │ └── TensorFlowLite.Common.Editor.asmdef.meta │ ├── Resources.meta │ ├── Resources │ │ ├── PrimitiveDraw.mat │ │ ├── PrimitiveDraw.mat.meta │ │ ├── PrimitiveDraw.shader │ │ ├── PrimitiveDraw.shader.meta │ │ ├── Resize.shader │ │ ├── Resize.shader.meta │ │ ├── TextureToTensor.compute │ │ └── TextureToTensor.compute.meta │ ├── Runtime.meta │ ├── Runtime │ │ ├── ArrayExtension.cs │ │ ├── ArrayExtension.cs.meta │ │ ├── BaseImagePredictor.cs │ │ ├── BaseImagePredictor.cs.meta │ │ ├── Color32Extension.cs │ │ ├── Color32Extension.cs.meta │ │ ├── DisposeUtil.cs │ │ ├── DisposeUtil.cs.meta │ │ ├── FilePopupAttribute.cs │ │ ├── FilePopupAttribute.cs.meta │ │ ├── FileUtil.cs │ │ ├── FileUtil.cs.meta │ │ ├── InterpreterExtension.cs │ │ ├── InterpreterExtension.cs.meta │ │ ├── MathTF.cs │ │ ├── MathTF.cs.meta │ │ ├── MatrixExtension.cs │ │ ├── MatrixExtension.cs.meta │ │ ├── PrimitiveDraw.cs │ │ ├── PrimitiveDraw.cs.meta │ │ ├── RectExtension.cs │ │ ├── RectExtension.cs.meta │ │ ├── TensorFlowLite.Common.asmdef │ │ ├── TensorFlowLite.Common.asmdef.meta │ │ ├── TextureResizer.cs │ │ ├── TextureResizer.cs.meta │ │ ├── TextureToTensor.cs │ │ ├── TextureToTensor.cs.meta │ │ ├── WebCamUtil.cs │ │ └── WebCamUtil.cs.meta │ ├── package.json │ └── package.json.meta ├── com.github.asus4.tflite │ ├── Plugins.meta │ ├── Plugins │ │ ├── Android.meta │ │ ├── Android │ │ │ ├── libnnapi_delegate.so │ │ │ ├── libnnapi_delegate.so.meta │ │ │ ├── libtensorflowlite_c.so │ │ │ ├── libtensorflowlite_c.so.meta │ │ │ ├── libtensorflowlite_gpu_delegate.so │ │ │ └── libtensorflowlite_gpu_delegate.so.meta │ │ ├── Linux.meta │ │ ├── Linux │ │ │ ├── libtensorflowlite_c.so │ │ │ └── libtensorflowlite_c.so.meta │ │ ├── Windows.meta │ │ ├── Windows │ │ │ ├── libtensorflowlite_c.dll │ │ │ └── libtensorflowlite_c.dll.meta │ │ ├── iOS.meta │ │ ├── iOS │ │ │ ├── TensorFlowLiteC.framework.meta │ │ │ ├── TensorFlowLiteC.framework │ │ │ │ ├── Headers.meta │ │ │ │ ├── Headers │ │ │ │ │ ├── TensorFlowLiteC.h │ │ │ │ │ ├── TensorFlowLiteC.h.meta │ │ │ │ │ ├── c_api.h │ │ │ │ │ ├── c_api.h.meta │ │ │ │ │ ├── c_api_experimental.h │ │ │ │ │ ├── c_api_experimental.h.meta │ │ │ │ │ ├── c_api_types.h │ │ │ │ │ ├── c_api_types.h.meta │ │ │ │ │ ├── common.h │ │ │ │ │ ├── common.h.meta │ │ │ │ │ ├── metal_delegate.h │ │ │ │ │ ├── metal_delegate.h.meta │ │ │ │ │ ├── xnnpack_delegate.h │ │ │ │ │ └── xnnpack_delegate.h.meta │ │ │ │ ├── Modules.meta │ │ │ │ ├── Modules │ │ │ │ │ ├── module.modulemap │ │ │ │ │ └── module.modulemap.meta │ │ │ │ ├── TensorFlowLiteC │ │ │ │ └── TensorFlowLiteC.meta │ │ │ ├── TensorFlowLiteCMetal.framework.meta │ │ │ └── TensorFlowLiteCMetal.framework │ │ │ │ ├── Headers.meta │ │ │ │ ├── Headers │ │ │ │ ├── TensorFlowLiteCMetal.h │ │ │ │ ├── TensorFlowLiteCMetal.h.meta │ │ │ │ ├── metal_delegate.h │ │ │ │ └── metal_delegate.h.meta │ │ │ │ ├── Modules.meta │ │ │ │ ├── Modules │ │ │ │ ├── module.modulemap │ │ │ │ └── module.modulemap.meta │ │ │ │ ├── TensorFlowLiteCMetal │ │ │ │ └── TensorFlowLiteCMetal.meta │ │ ├── macOS.meta │ │ ├── macOS │ │ │ ├── libtensorflowlite_c.dylib │ │ │ ├── libtensorflowlite_c.dylib.meta │ │ │ ├── libtensorflowlite_metal_delegate.dylib │ │ │ └── libtensorflowlite_metal_delegate.dylib.meta │ │ ├── tflite_unity_helper.cpp │ │ └── tflite_unity_helper.cpp.meta │ ├── Runtime.meta │ ├── Runtime │ │ ├── BuiltinOps.cs │ │ ├── BuiltinOps.cs.meta │ │ ├── ErrorReporter.cs │ │ ├── ErrorReporter.cs.meta │ │ ├── GlDelegate.cs │ │ ├── GlDelegate.cs.meta │ │ ├── GpuDelegateV2.cs │ │ ├── GpuDelegateV2.cs.meta │ │ ├── IGpuDelegate.cs │ │ ├── IGpuDelegate.cs.meta │ │ ├── Interpreter.cs │ │ ├── Interpreter.cs.meta │ │ ├── InterpreterExperimental.cs │ │ ├── InterpreterExperimental.cs.meta │ │ ├── InterpreterOptions.cs │ │ ├── InterpreterOptions.cs.meta │ │ ├── MetalDelegate.cs │ │ ├── MetalDelegate.cs.meta │ │ ├── TensorFlowLite.asmdef │ │ └── TensorFlowLite.asmdef.meta │ ├── package.json │ └── package.json.meta ├── manifest.json └── packages-lock.json ├── ProjectSettings ├── AudioManager.asset ├── ClusterInputManager.asset ├── DynamicsManager.asset ├── EditorBuildSettings.asset ├── EditorSettings.asset ├── GraphicsSettings.asset ├── InputManager.asset ├── NavMeshAreas.asset ├── PackageManagerSettings.asset ├── Physics2DSettings.asset ├── PresetManager.asset ├── ProjectSettings.asset ├── ProjectVersion.txt ├── QualitySettings.asset ├── TagManager.asset ├── TimeManager.asset ├── UnityConnectSettings.asset ├── VFXManager.asset ├── VersionControlSettings.asset └── XRSettings.asset ├── README.md └── build_tflite.py /.gitignore: -------------------------------------------------------------------------------- 1 | # This .gitignore file should be placed at the root of your Unity project directory 2 | # 3 | # Get latest from https://github.com/github/gitignore/blob/master/Unity.gitignore 4 | # 5 | /[Ll]ibrary/ 6 | /[Tt]emp/ 7 | /[Oo]bj/ 8 | /[Bb]uild/ 9 | /[Bb]uilds/ 10 | /[Ll]ogs/ 11 | /[Uu]ser[Ss]ettings/ 12 | 13 | # MemoryCaptures can get excessive in size. 14 | # They also could contain extremely sensitive data 15 | /[Mm]emoryCaptures/ 16 | 17 | # Asset meta data should only be ignored when the corresponding asset is also ignored 18 | !/[Aa]ssets/**/*.meta 19 | 20 | # Uncomment this line if you wish to ignore the asset store tools plugin 21 | # /[Aa]ssets/AssetStoreTools* 22 | 23 | # Autogenerated Jetbrains Rider plugin 24 | /[Aa]ssets/Plugins/Editor/JetBrains* 25 | 26 | # Visual Studio cache directory 27 | .vs/ 28 | 29 | # Gradle cache directory 30 | .gradle/ 31 | 32 | # Autogenerated VS/MD/Consulo solution and project files 33 | ExportedObj/ 34 | .consulo/ 35 | *.csproj 36 | *.unityproj 37 | *.sln 38 | *.suo 39 | *.tmp 40 | *.user 41 | *.userprefs 42 | *.pidb 43 | *.booproj 44 | *.svd 45 | *.pdb 46 | *.mdb 47 | *.opendb 48 | *.VC.db 49 | *.vsconfig 50 | 51 | # Unity3D generated meta files 52 | *.pidb.meta 53 | *.pdb.meta 54 | *.mdb.meta 55 | 56 | # Unity3D generated file on crash reports 57 | sysinfo.txt 58 | 59 | # Builds 60 | *.apk 61 | *.aab 62 | *.unitypackage 63 | 64 | # Crashlytics generated file 65 | crashlytics-build.properties 66 | 67 | # Packed Addressables 68 | /[Aa]ssets/[Aa]ddressable[Aa]ssets[Dd]ata/*/*.bin* 69 | 70 | # Temporary auto-generated Android Assets 71 | /[Aa]ssets/[Ss]treamingAssets/aa.meta 72 | /[Aa]ssets/[Ss]treamingAssets/aa/* 73 | -------------------------------------------------------------------------------- /Assets/Materials.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 016c9c8b290f64a61b43a9bcdeb3c034 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Assets/Materials/red.mat: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!21 &2100000 4 | Material: 5 | serializedVersion: 6 6 | m_ObjectHideFlags: 0 7 | m_CorrespondingSourceObject: {fileID: 0} 8 | m_PrefabInstance: {fileID: 0} 9 | m_PrefabAsset: {fileID: 0} 10 | m_Name: red 11 | m_Shader: {fileID: 46, guid: 0000000000000000f000000000000000, type: 0} 12 | m_ShaderKeywords: 13 | m_LightmapFlags: 4 14 | m_EnableInstancingVariants: 0 15 | m_DoubleSidedGI: 0 16 | m_CustomRenderQueue: -1 17 | stringTagMap: {} 18 | disabledShaderPasses: [] 19 | m_SavedProperties: 20 | serializedVersion: 3 21 | m_TexEnvs: 22 | - _BumpMap: 23 | m_Texture: {fileID: 0} 24 | m_Scale: {x: 1, y: 1} 25 | m_Offset: {x: 0, y: 0} 26 | - _DetailAlbedoMap: 27 | m_Texture: {fileID: 0} 28 | m_Scale: {x: 1, y: 1} 29 | m_Offset: {x: 0, y: 0} 30 | - _DetailMask: 31 | m_Texture: {fileID: 0} 32 | m_Scale: {x: 1, y: 1} 33 | m_Offset: {x: 0, y: 0} 34 | - _DetailNormalMap: 35 | m_Texture: {fileID: 0} 36 | m_Scale: {x: 1, y: 1} 37 | m_Offset: {x: 0, y: 0} 38 | - _EmissionMap: 39 | m_Texture: {fileID: 0} 40 | m_Scale: {x: 1, y: 1} 41 | m_Offset: {x: 0, y: 0} 42 | - _MainTex: 43 | m_Texture: {fileID: 0} 44 | m_Scale: {x: 1, y: 1} 45 | m_Offset: {x: 0, y: 0} 46 | - _MetallicGlossMap: 47 | m_Texture: {fileID: 0} 48 | m_Scale: {x: 1, y: 1} 49 | m_Offset: {x: 0, y: 0} 50 | - _OcclusionMap: 51 | m_Texture: {fileID: 0} 52 | m_Scale: {x: 1, y: 1} 53 | m_Offset: {x: 0, y: 0} 54 | - _ParallaxMap: 55 | m_Texture: {fileID: 0} 56 | m_Scale: {x: 1, y: 1} 57 | m_Offset: {x: 0, y: 0} 58 | m_Floats: 59 | - _BumpScale: 1 60 | - _Cutoff: 0.5 61 | - _DetailNormalMapScale: 1 62 | - _DstBlend: 0 63 | - _GlossMapScale: 1 64 | - _Glossiness: 0.5 65 | - _GlossyReflections: 1 66 | - _Metallic: 0 67 | - _Mode: 0 68 | - _OcclusionStrength: 1 69 | - _Parallax: 0.02 70 | - _SmoothnessTextureChannel: 0 71 | - _SpecularHighlights: 1 72 | - _SrcBlend: 1 73 | - _UVSec: 0 74 | - _ZWrite: 1 75 | m_Colors: 76 | - _Color: {r: 1, g: 0, b: 0, a: 1} 77 | - _EmissionColor: {r: 0, g: 0, b: 0, a: 1} 78 | m_BuildTextureStacks: [] 79 | -------------------------------------------------------------------------------- /Assets/Materials/red.mat.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 88c61954dfd6448c4a506bfc9e89cea2 3 | NativeFormatImporter: 4 | externalObjects: {} 5 | mainObjectFileID: 2100000 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Assets/Scenes.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b4b71bfd89c5f4de0a61b227d8b22f6d 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Assets/Scenes/BlazePose.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 4cda3735c479249b5b024ce394cec3b5 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Assets/Scenes/BlazePose/BlazePose.unity.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 3abf2ff7d3acd4eda8d5014c1830c433 3 | DefaultImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /Assets/Scenes/BlazePose/BlazePoseSample.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: ac6c2ecddc84d4bfb931c1f8ad12eac7 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/Scenes/BlazePose/PoseDetect.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Linq; 3 | using System.Threading; 4 | using Cysharp.Threading.Tasks; 5 | using UnityEngine; 6 | 7 | namespace TensorFlowLite 8 | { 9 | public sealed class PoseDetect : BaseImagePredictor 10 | { 11 | 12 | public class Result : System.IComparable 13 | { 14 | public float score; 15 | public Rect rect; 16 | public Vector2[] keypoints; 17 | 18 | public static Result Negative => new Result() { score = -1, }; 19 | 20 | public int CompareTo(Result other) 21 | { 22 | return score > other.score ? -1 : 1; 23 | } 24 | } 25 | 26 | const int MAX_POSE_NUM = 100; 27 | const int ANCHOR_LENGTH = 2254; 28 | public int KeypointsCount { get; private set; } 29 | 30 | // regressors / points 31 | // 0 - 3 are bounding box offset, width and height: dx, dy, w ,h 32 | // 4 - 11 are 4 keypoints x and y coordinates: x0,y0,x1,y1,x2,y2,x3,y3 33 | private float[,] output0 = new float[ANCHOR_LENGTH, 12]; 34 | 35 | // classificators / scores 36 | private float[] output1 = new float[ANCHOR_LENGTH]; 37 | 38 | private SsdAnchor[] anchors; 39 | private SortedSet results = new SortedSet(); 40 | 41 | public PoseDetect(string modelPath) : base(modelPath, true) 42 | { 43 | var options = new SsdAnchorsCalculator.Options() 44 | { 45 | inputSizeWidth = width, 46 | inputSizeHeight = height, 47 | 48 | minScale = 0.1484375f, 49 | maxScale = 0.75f, 50 | 51 | anchorOffsetX = 0.5f, 52 | anchorOffsetY = 0.5f, 53 | 54 | numLayers = 5, 55 | featureMapWidth = new int[0], 56 | featureMapHeight = new int[0], 57 | strides = new int[] { 8, 16, 32, 32, 32 }, 58 | 59 | aspectRatios = new float[] { 1.0f }, 60 | 61 | reduceBoxesInLowestLayer = false, 62 | interpolatedScaleAspectRatio = 1.0f, 63 | fixedAnchorSize = true, 64 | }; 65 | 66 | anchors = SsdAnchorsCalculator.Generate(options); 67 | UnityEngine.Debug.AssertFormat( 68 | anchors.Length == ANCHOR_LENGTH, 69 | $"Anchors count must be {ANCHOR_LENGTH}, but was {anchors.Length}"); 70 | 71 | // Get Keypoint Mode 72 | var odim0 = interpreter.GetOutputTensorInfo(0).shape; 73 | KeypointsCount = (odim0[2] - 4) / 2; 74 | } 75 | 76 | public override void Invoke(Texture inputTex) 77 | { 78 | ToTensor(inputTex, input0); 79 | 80 | interpreter.SetInputTensorData(0, input0); 81 | interpreter.Invoke(); 82 | 83 | interpreter.GetOutputTensorData(0, output0); 84 | interpreter.GetOutputTensorData(1, output1); 85 | } 86 | 87 | public async UniTask InvokeAsync(Texture inputTex, CancellationToken cancellationToken, PlayerLoopTiming timing = PlayerLoopTiming.Update) 88 | { 89 | await ToTensorAsync(inputTex, input0, cancellationToken); 90 | await UniTask.SwitchToThreadPool(); 91 | 92 | interpreter.SetInputTensorData(0, input0); 93 | interpreter.Invoke(); 94 | 95 | interpreter.GetOutputTensorData(0, output0); 96 | interpreter.GetOutputTensorData(1, output1); 97 | 98 | var results = GetResults(); 99 | 100 | await UniTask.SwitchToMainThread(timing, cancellationToken); 101 | return results; 102 | } 103 | 104 | public Result GetResults(float scoreThreshold = 0.5f, float iouThreshold = 0.3f) 105 | { 106 | results.Clear(); 107 | 108 | int keypointsCount = KeypointsCount; 109 | 110 | for (int i = 0; i < anchors.Length; i++) 111 | { 112 | float score = MathTF.Sigmoid(output1[i]); 113 | if (score < scoreThreshold) 114 | { 115 | continue; 116 | } 117 | 118 | SsdAnchor anchor = anchors[i]; 119 | 120 | float sx = output0[i, 0]; 121 | float sy = output0[i, 1]; 122 | float w = output0[i, 2]; 123 | float h = output0[i, 3]; 124 | 125 | float cx = sx + anchor.x * width; 126 | float cy = sy + anchor.y * height; 127 | 128 | cx /= (float)width; 129 | cy /= (float)height; 130 | w /= (float)width; 131 | h /= (float)height; 132 | 133 | var keypoints = new Vector2[keypointsCount]; 134 | for (int j = 0; j < keypointsCount; j++) 135 | { 136 | float lx = output0[i, 4 + (2 * j) + 0]; 137 | float ly = output0[i, 4 + (2 * j) + 1]; 138 | lx += anchor.x * width; 139 | ly += anchor.y * height; 140 | lx /= (float)width; 141 | ly /= (float)height; 142 | keypoints[j] = new Vector2(lx, ly); 143 | } 144 | 145 | results.Add(new Result() 146 | { 147 | score = score, 148 | rect = new Rect(cx - w * 0.5f, cy - h * 0.5f, w, h), 149 | keypoints = keypoints, 150 | }); 151 | } 152 | 153 | // No result 154 | if (results.Count == 0) 155 | { 156 | return Result.Negative; 157 | } 158 | 159 | return results.First(); 160 | // return NonMaxSuppression(results, iouThreshold).First(); 161 | } 162 | 163 | private static List NonMaxSuppression(List results, float iouThreshold) 164 | { 165 | var filtered = new List(); 166 | 167 | // FIXME LinQ allocs GC each frame 168 | foreach (Result original in results.OrderByDescending(o => o.score)) 169 | { 170 | bool ignoreCandidate = false; 171 | foreach (Result newResult in filtered) 172 | { 173 | float iou = original.rect.IntersectionOverUnion(newResult.rect); 174 | if (iou >= iouThreshold) 175 | { 176 | ignoreCandidate = true; 177 | break; 178 | } 179 | } 180 | 181 | if (!ignoreCandidate) 182 | { 183 | filtered.Add(original); 184 | if (filtered.Count >= MAX_POSE_NUM) 185 | { 186 | break; 187 | } 188 | } 189 | } 190 | 191 | return filtered; 192 | } 193 | } 194 | } 195 | -------------------------------------------------------------------------------- /Assets/Scenes/BlazePose/PoseDetect.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 549662b27e3b54f419477b2654196111 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/Scenes/BlazePose/PoseLandmarkDetect.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 0044f6d3e9a2c4d70afb381da6d09077 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/Scenes/BlazePose/PoseLandmarks.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | /** 6 | * List according to 7 | * Assets/Scenes/BlazePose/pose-landmarks-map.png 8 | */ 9 | public static class PoseLandmarks { 10 | 11 | public const int NOSE = 0; 12 | 13 | public const int LEFT_EYE_INNER = 1; 14 | public const int LEFT_EYE = 2; 15 | public const int LEFT_EYE_OUTER = 3; 16 | 17 | public const int RIGHT_EYE_INNER = 4; 18 | public const int RIGHT_EYE = 5; 19 | public const int RIGHT_EYE_OUTER = 6; 20 | 21 | public const int LEFT_EAR = 7; 22 | public const int RIGHT_EAR = 8; 23 | 24 | public const int LEFT_MOUTH = 9; 25 | public const int RIGHT_MOUTH = 10; 26 | 27 | public const int LEFT_SHOULDER = 11; 28 | public const int RIGHT_SHOULDER = 12; 29 | 30 | public const int LEFT_ELBOW = 13; 31 | public const int RIGHT_ELBOW = 14; 32 | 33 | public const int LEFT_WRIST = 15; 34 | public const int RIGHT_WRIST = 16; 35 | 36 | public const int LEFT_PINKY = 17; 37 | public const int RIGHT_PINKY = 18; 38 | 39 | public const int LEFT_INDEX = 19; 40 | public const int RIGHT_INDEX = 20; 41 | 42 | public const int LEFT_THUMB = 21; 43 | public const int RIGHT_THUMB = 22; 44 | 45 | public const int LEFT_HIP = 23; 46 | public const int RIGHT_HIP = 24; 47 | 48 | public const int LEFT_KNEE = 25; 49 | public const int RIGHT_KNEE = 26; 50 | 51 | public const int LEFT_ANKLE = 27; 52 | public const int RIGHT_ANKLE = 28; 53 | 54 | public const int LEFT_HEEL = 29; 55 | public const int RIGHT_HEEL = 30; 56 | 57 | public const int LEFT_FOOT_INDEX = 31; 58 | public const int RIGHT_FOOT_INDEX = 32; 59 | 60 | } 61 | -------------------------------------------------------------------------------- /Assets/Scenes/BlazePose/PoseLandmarks.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: daa7c5f8237dd431e88beb23284ed471 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/Scenes/BlazePose/pose-landmarks-map.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alibros/blazepose-unity/cadb1e0da1004eca287e7910e6488bee6e8c7e76/Assets/Scenes/BlazePose/pose-landmarks-map.png -------------------------------------------------------------------------------- /Assets/Scenes/BlazePose/pose-landmarks-map.png.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: e284baf021deb493f9e43be8665bf747 3 | TextureImporter: 4 | internalIDToNameTable: [] 5 | externalObjects: {} 6 | serializedVersion: 11 7 | mipmaps: 8 | mipMapMode: 0 9 | enableMipMap: 1 10 | sRGBTexture: 1 11 | linearTexture: 0 12 | fadeOut: 0 13 | borderMipMap: 0 14 | mipMapsPreserveCoverage: 0 15 | alphaTestReferenceValue: 0.5 16 | mipMapFadeDistanceStart: 1 17 | mipMapFadeDistanceEnd: 3 18 | bumpmap: 19 | convertToNormalMap: 0 20 | externalNormalMap: 0 21 | heightScale: 0.25 22 | normalMapFilter: 0 23 | isReadable: 0 24 | streamingMipmaps: 0 25 | streamingMipmapsPriority: 0 26 | grayScaleToAlpha: 0 27 | generateCubemap: 6 28 | cubemapConvolution: 0 29 | seamlessCubemap: 0 30 | textureFormat: 1 31 | maxTextureSize: 2048 32 | textureSettings: 33 | serializedVersion: 2 34 | filterMode: -1 35 | aniso: -1 36 | mipBias: -100 37 | wrapU: -1 38 | wrapV: -1 39 | wrapW: -1 40 | nPOTScale: 1 41 | lightmap: 0 42 | compressionQuality: 50 43 | spriteMode: 0 44 | spriteExtrude: 1 45 | spriteMeshType: 1 46 | alignment: 0 47 | spritePivot: {x: 0.5, y: 0.5} 48 | spritePixelsToUnits: 100 49 | spriteBorder: {x: 0, y: 0, z: 0, w: 0} 50 | spriteGenerateFallbackPhysicsShape: 1 51 | alphaUsage: 1 52 | alphaIsTransparency: 0 53 | spriteTessellationDetail: -1 54 | textureType: 0 55 | textureShape: 1 56 | singleChannelComponent: 0 57 | maxTextureSizeSet: 0 58 | compressionQualitySet: 0 59 | textureFormatSet: 0 60 | applyGammaDecoding: 0 61 | platformSettings: 62 | - serializedVersion: 3 63 | buildTarget: DefaultTexturePlatform 64 | maxTextureSize: 2048 65 | resizeAlgorithm: 0 66 | textureFormat: -1 67 | textureCompression: 1 68 | compressionQuality: 50 69 | crunchedCompression: 0 70 | allowsAlphaSplitting: 0 71 | overridden: 0 72 | androidETC2FallbackOverride: 0 73 | forceMaximumCompressionQuality_BC6H_BC7: 0 74 | spriteSheet: 75 | serializedVersion: 2 76 | sprites: [] 77 | outline: [] 78 | physicsShape: [] 79 | bones: [] 80 | spriteID: 81 | internalID: 0 82 | vertices: [] 83 | indices: 84 | edges: [] 85 | weights: [] 86 | secondaryTextures: [] 87 | spritePackingTag: 88 | pSDRemoveMatte: 0 89 | pSDShowRemoveMatteOption: 0 90 | userData: 91 | assetBundleName: 92 | assetBundleVariant: 93 | -------------------------------------------------------------------------------- /Assets/StreamingAssets.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: c51919b9b7f2e452c947e92da4fc87df 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Assets/StreamingAssets/mediapipe.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: e28590b9f1e65445bb9c88c8f955606e 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Assets/StreamingAssets/mediapipe/palm_detection_builtin_256_float16_quant.tflite: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alibros/blazepose-unity/cadb1e0da1004eca287e7910e6488bee6e8c7e76/Assets/StreamingAssets/mediapipe/palm_detection_builtin_256_float16_quant.tflite -------------------------------------------------------------------------------- /Assets/StreamingAssets/mediapipe/palm_detection_builtin_256_float16_quant.tflite.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: feaec87a4bd3c4a32a2f0129f6dc1bcf 3 | DefaultImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /Assets/StreamingAssets/mediapipe/pose_detection.tflite: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alibros/blazepose-unity/cadb1e0da1004eca287e7910e6488bee6e8c7e76/Assets/StreamingAssets/mediapipe/pose_detection.tflite -------------------------------------------------------------------------------- /Assets/StreamingAssets/mediapipe/pose_detection.tflite.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 3b029ea60e01340e28583c0b3d220e68 3 | DefaultImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /Assets/StreamingAssets/mediapipe/pose_landmark_lite.tflite: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alibros/blazepose-unity/cadb1e0da1004eca287e7910e6488bee6e8c7e76/Assets/StreamingAssets/mediapipe/pose_landmark_lite.tflite -------------------------------------------------------------------------------- /Assets/StreamingAssets/mediapipe/pose_landmark_lite.tflite.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 2d2679bb1c4804918b02bf38ae13f26e 3 | DefaultImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /Assets/_Scripts.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 446d4c5175e3d4a6b8568cb23cb9faad 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Assets/_Scripts/UIToggles.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | public class UIToggles : MonoBehaviour { 6 | 7 | [SerializeField] private GameObject _canvas; 8 | [SerializeField] private BlazePoseSample _blaze; 9 | 10 | public void OnButtonToggleCameraHandler () { 11 | _canvas.SetActive(!_canvas.activeSelf); 12 | } 13 | 14 | public void OnButtonToggleOutlineHandler() { 15 | _blaze.DrawStickFigure = !_blaze.DrawStickFigure; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Assets/_Scripts/UIToggles.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 5967f5689655f417d8f1d7e21bf19aa0 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/link.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Assets/link.xml.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 76b6376f9e6b34b36a7b321cddad0a13 3 | TextScriptImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /Packages/com.github.asus4.mediapipe/Editor.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: c8cc06dd6f70c44bca1d9caa147d18b9 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Packages/com.github.asus4.mediapipe/Editor/MediaPipe.Editor.asmdef: -------------------------------------------------------------------------------- 1 | { 2 | "name": "MediaPipe.Editor", 3 | "references": [ 4 | "GUID:0acc523941302664db1f4e527237feb3", 5 | "GUID:98f31ee3d205e4a19aea6d3a179ae522" 6 | ], 7 | "includePlatforms": [ 8 | "Editor" 9 | ], 10 | "excludePlatforms": [], 11 | "allowUnsafeCode": false, 12 | "overrideReferences": false, 13 | "precompiledReferences": [], 14 | "autoReferenced": true, 15 | "defineConstraints": [], 16 | "versionDefines": [], 17 | "noEngineReferences": false 18 | } -------------------------------------------------------------------------------- /Packages/com.github.asus4.mediapipe/Editor/MediaPipe.Editor.asmdef.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 95b16a93b1aae46fabd6d98727e342ee 3 | AssemblyDefinitionImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /Packages/com.github.asus4.mediapipe/Editor/SsdAnchorsCalculatorTest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using NUnit.Framework; 6 | using UnityEditor; 7 | using UnityEngine; 8 | 9 | namespace TensorFlowLite 10 | { 11 | public class SsdAnchorsCalculatorTest 12 | { 13 | [Test] 14 | public void FaceDetectionConfigTest() 15 | { 16 | var options = new SsdAnchorsCalculator.Options() 17 | { 18 | numLayers = 5, 19 | 20 | minScale = 0.1171875f, 21 | maxScale = 0.75f, 22 | 23 | inputSizeHeight = 256, 24 | inputSizeWidth = 256, 25 | 26 | anchorOffsetX = 0.5f, 27 | anchorOffsetY = 0.5f, 28 | 29 | featureMapWidth = new int[0] { }, 30 | featureMapHeight = new int[0] { }, 31 | strides = new int[] { 8, 16, 32, 32, 32 }, 32 | aspectRatios = new float[] { 1.0f }, 33 | 34 | reduceBoxesInLowestLayer = false, 35 | interpolatedScaleAspectRatio = 1.0f, 36 | fixedAnchorSize = true, 37 | }; 38 | 39 | var testData = LoadTestData("anchor_golden_file_0.txt"); 40 | var anchors = SsdAnchorsCalculator.Generate(options); 41 | AreEqual(testData, anchors); 42 | } 43 | 44 | [Test] 45 | public void MobileSSDConfig() 46 | { 47 | var options = new SsdAnchorsCalculator.Options() 48 | { 49 | numLayers = 6, 50 | 51 | minScale = 0.2f, 52 | maxScale = 0.95f, 53 | 54 | inputSizeHeight = 300, 55 | inputSizeWidth = 300, 56 | 57 | anchorOffsetX = 0.5f, 58 | anchorOffsetY = 0.5f, 59 | 60 | featureMapWidth = new int[0] { }, 61 | featureMapHeight = new int[0] { }, 62 | strides = new int[] { 16, 32, 64, 128, 256, 512 }, 63 | aspectRatios = new float[] { 1.0f, 2.0f, 0.5f, 3.0f, 0.3333f }, 64 | 65 | reduceBoxesInLowestLayer = true, 66 | interpolatedScaleAspectRatio = 1.0f, 67 | fixedAnchorSize = false, 68 | }; 69 | 70 | var testData = LoadTestData("anchor_golden_file_1.txt"); 71 | var anchors = SsdAnchorsCalculator.Generate(options); 72 | AreEqual(testData, anchors); 73 | } 74 | 75 | private static void AreEqual(SsdAnchor[] expected, SsdAnchor[] actual) 76 | { 77 | Assert.AreEqual(expected.Length, actual.Length); 78 | 79 | int length = expected.Length; 80 | for (int i = 0; i < length; i++) 81 | { 82 | Assert.IsTrue(expected[i] == actual[i]); 83 | // Assert.AreEqual(expected[i], actual[i]); 84 | } 85 | Debug.Log("all equal"); 86 | } 87 | 88 | private static SsdAnchor[] LoadTestData(string testFile) 89 | { 90 | const string testDataPath = "Packages/com.github.asus4.mediapipe/Editor/TestData"; 91 | string path = Path.GetFullPath(Path.Combine(testDataPath, testFile)); 92 | Assert.IsTrue(File.Exists(path)); 93 | 94 | var anchors = new List(); 95 | 96 | using (var reader = new StreamReader(path)) 97 | { 98 | string line; 99 | while ((line = reader.ReadLine()) != null) 100 | { 101 | if (string.IsNullOrWhiteSpace(line)) continue; 102 | 103 | string[] chunks = line.Split(' '); 104 | anchors.Add(new SsdAnchor() 105 | { 106 | x = float.Parse(chunks[0]), 107 | y = float.Parse(chunks[1]), 108 | width = float.Parse(chunks[2]), 109 | height = float.Parse(chunks[3]), 110 | }); 111 | } 112 | } 113 | return anchors.ToArray(); 114 | } 115 | } 116 | } 117 | 118 | -------------------------------------------------------------------------------- /Packages/com.github.asus4.mediapipe/Editor/SsdAnchorsCalculatorTest.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: d15e18ab105414018bffd23cb86f5755 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Packages/com.github.asus4.mediapipe/Editor/TestData.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 8be3ff3e342324b82b8229af47018a7f 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Packages/com.github.asus4.mediapipe/Editor/TestData/anchor_golden_file_0.txt.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b2b77c5cb96514b869d4a221403d5af5 3 | TextScriptImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /Packages/com.github.asus4.mediapipe/Editor/TestData/anchor_golden_file_1.txt.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 453edfeed026d4604bf030bbc592abfc 3 | TextScriptImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /Packages/com.github.asus4.mediapipe/Runtime.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 48d7a8bdccee1496bb571615f737d367 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Packages/com.github.asus4.mediapipe/Runtime/LowPassFilter.cs: -------------------------------------------------------------------------------- 1 |  2 | namespace TensorFlowLite 3 | { 4 | /// 5 | /// Super simple low pass filter 6 | /// 7 | public class LowPassFilter 8 | { 9 | public float alpha; 10 | 11 | private float rawValue; 12 | private float storedValue; 13 | private bool isInitialized; 14 | 15 | public float Apply(float value) 16 | { 17 | float result; 18 | if (isInitialized) 19 | { 20 | result = alpha * value + (1.0f - alpha) * storedValue; 21 | } 22 | else 23 | { 24 | result = value; 25 | isInitialized = true; 26 | } 27 | rawValue = value; 28 | storedValue = result; 29 | return result; 30 | } 31 | 32 | public float Apply(float value, float alpha) 33 | { 34 | this.alpha = alpha; 35 | return Apply(value); 36 | } 37 | 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /Packages/com.github.asus4.mediapipe/Runtime/LowPassFilter.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 1e00a63cfba9144b491e0f04e9b4114b 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Packages/com.github.asus4.mediapipe/Runtime/MediaPipe.asmdef: -------------------------------------------------------------------------------- 1 | { 2 | "name": "MediaPipe", 3 | "references": [ 4 | "GUID:6e1d47a1424c040aca79d8b6a2710888", 5 | "GUID:f51ebe6a0ceec4240a699833d6309b23" 6 | ], 7 | "includePlatforms": [], 8 | "excludePlatforms": [], 9 | "allowUnsafeCode": false, 10 | "overrideReferences": false, 11 | "precompiledReferences": [], 12 | "autoReferenced": true, 13 | "defineConstraints": [], 14 | "versionDefines": [], 15 | "noEngineReferences": false 16 | } -------------------------------------------------------------------------------- /Packages/com.github.asus4.mediapipe/Runtime/MediaPipe.asmdef.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 98f31ee3d205e4a19aea6d3a179ae522 3 | AssemblyDefinitionImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /Packages/com.github.asus4.mediapipe/Runtime/RectTransformationCalculator.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | 3 | namespace TensorFlowLite 4 | { 5 | /// 6 | /// RectTransformationCalculator from MediaPipe 7 | /// https://github.com/google/mediapipe/blob/master/mediapipe/calculators/util/rect_transformation_calculator.cc 8 | /// 9 | public class RectTransformationCalculator 10 | { 11 | public ref struct Options 12 | { 13 | /// 14 | /// The Normalized Rect (0, 0, 1, 1) 15 | /// 16 | public Rect rect; 17 | public float rotationDegree; 18 | public Vector2 shift; 19 | public Vector2 scale; 20 | 21 | // Custom options for WebCamTexture 22 | public float cameraRotationDegree; 23 | public bool mirrorHorizontal; 24 | public bool mirrorVertiacal; 25 | 26 | public bool IsCameraModified => 27 | cameraRotationDegree != 0 28 | || mirrorHorizontal 29 | || mirrorVertiacal; 30 | } 31 | 32 | public static readonly Matrix4x4 POP_MATRIX = Matrix4x4.Translate(new Vector3(0.5f, 0.5f, 0)); 33 | public static readonly Matrix4x4 PUSH_MATRIX = Matrix4x4.Translate(new Vector3(-0.5f, -0.5f, 0)); 34 | 35 | public static Matrix4x4 CalcMatrix(Options options) 36 | { 37 | Quaternion rotation = Quaternion.Euler(0, 0, options.rotationDegree); 38 | Vector2 size = Vector2.Scale(options.rect.size, options.scale); 39 | Vector2 shift = options.shift; 40 | 41 | // Calc center position 42 | Vector2 center = options.rect.center + new Vector2(-0.5f, -0.5f); 43 | center = (Vector2)(rotation * center); 44 | center += (shift * size); 45 | center /= size; 46 | 47 | Matrix4x4 trs = Matrix4x4.TRS( 48 | new Vector3(-center.x, -center.y, 0), 49 | rotation, 50 | new Vector3(1 / size.x, -1 / size.y, 1) 51 | ); 52 | 53 | if (!options.IsCameraModified) 54 | { 55 | return POP_MATRIX * trs * PUSH_MATRIX; 56 | } 57 | Matrix4x4 cameraMtx = Matrix4x4.TRS( 58 | new Vector3(0, 0, 0), 59 | Quaternion.Euler(0, 0, -options.cameraRotationDegree), 60 | new Vector3( 61 | options.mirrorHorizontal ? -1 : 1, 62 | options.mirrorVertiacal ? -1 : 1, 63 | 1 64 | ) 65 | ); 66 | return POP_MATRIX * trs * cameraMtx * PUSH_MATRIX; 67 | } 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /Packages/com.github.asus4.mediapipe/Runtime/RectTransformationCalculator.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 36378895b4627471c9481ef99379a0f2 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Packages/com.github.asus4.mediapipe/Runtime/RelativeVelocityFilter.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 48bba539a153a47a9b3b1fa034c71bdd 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Packages/com.github.asus4.mediapipe/Runtime/SsdAnchor.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 957402e43c4c645ca98a67a1f9a4ceaa 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Packages/com.github.asus4.mediapipe/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "com.github.asus4.mediapipe", 3 | "displayName": "MediaPipe", 4 | "author": "Koki Ibukuro", 5 | "description": "MediaPipe for Unity", 6 | "keywords": [ 7 | "unity" 8 | ], 9 | "license": "SEE LICENSE IN LICENSE", 10 | "unity": "2019.3", 11 | "unityRelease": "0f1", 12 | "version": "2.4.1", 13 | "type": "library", 14 | "hideInEditor": false, 15 | "dependencies": { 16 | "com.github.asus4.tflite": "2.4.1", 17 | "com.github.asus4.tflite.common": "2.4.1" 18 | } 19 | } -------------------------------------------------------------------------------- /Packages/com.github.asus4.mediapipe/package.json.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 8e276f3eafd064b0ea82dc12d7dc73b9 3 | PackageManifestImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /Packages/com.github.asus4.tflite.common/Editor.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: aafcd7893e7c04f7fbddba5d341161b9 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Packages/com.github.asus4.tflite.common/Editor/ArrayExtensionTest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | using UnityEditor; 4 | using NUnit.Framework; 5 | 6 | namespace TensorFlowLite 7 | { 8 | public class ArrayExtensionTest 9 | { 10 | [Test] 11 | public void ToIndexValueTuple() 12 | { 13 | var input = new int[] { 10, 11, 12, 13, 14 }; 14 | var expected = new Tuple[] 15 | { 16 | new Tuple(0, 10), 17 | new Tuple(1, 11), 18 | new Tuple(2, 12), 19 | new Tuple(3, 13), 20 | new Tuple(4, 14), 21 | }; 22 | var result = input.ToIndexValueTuple().ToArray(); 23 | 24 | Assert.AreEqual(input.Length, result.Length); 25 | for (int i = 0; i < input.Length; i++) 26 | { 27 | AreEqual(expected[i], result[i]); 28 | } 29 | } 30 | 31 | private static void AreEqual(Tuple expected, Tuple actual) 32 | { 33 | Assert.AreEqual(expected.Item1, actual.Item1); 34 | Assert.AreEqual(expected.Item2, actual.Item2); 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /Packages/com.github.asus4.tflite.common/Editor/ArrayExtensionTest.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 9320c441511f5409f9128711db501c0e 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Packages/com.github.asus4.tflite.common/Editor/MathTFTest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | using UnityEditor; 4 | using NUnit.Framework; 5 | 6 | namespace TensorFlowLite 7 | { 8 | 9 | public class MathTFTest 10 | { 11 | [TestCase(new double[] { 1.0, 2.0, 3.0, 4.0, 5.0, }, 12 | new double[] { 0.011656231, 0.031684921, 0.086128544, 0.234121657, 0.636408647, })] 13 | [TestCase(new double[] { -1.0, -2.0, -3.0, -4.0, -5.0, }, 14 | new double[] { 0.636408647, 0.234121657, 0.086128544, 0.031684921, 0.011656231, })] 15 | public void SoftMaxDoubleTest(double[] input, double[] expected) 16 | { 17 | const double EPSILON = 0.00001; 18 | // const double EPSILON = double.Epsilon; 19 | ArrayEqual(input.Softmax().ToArray(), expected, EPSILON); 20 | } 21 | 22 | [TestCase(new float[] { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, }, 23 | new float[] { 0.011656231f, 0.031684921f, 0.086128544f, 0.234121657f, 0.636408647f, })] 24 | [TestCase(new float[] { -1.0f, -2.0f, -3.0f, -4.0f, -5.0f, }, 25 | new float[] { 0.636408647f, 0.234121657f, 0.086128544f, 0.031684921f, 0.011656231f, })] 26 | public void SoftMaxFloatTest(float[] input, float[] expected) 27 | { 28 | const float EPSILON = 0.00001f; 29 | // const float EPSILON = float.Epsilon; 30 | ArrayEqual(input.Softmax().ToArray(), expected, EPSILON); 31 | } 32 | 33 | private static void ArrayEqual(double[] actual, double[] expected, double epsilon) 34 | { 35 | Assert.AreEqual(expected.Length, actual.Length); 36 | for (int i = 0; i < expected.Length; i++) 37 | { 38 | double diff = Math.Abs(expected[i] - actual[i]); 39 | Assert.True(diff <= epsilon, $"expected: {expected[i]}, actual: {actual[i]}, diff: {diff}, epsilon: {epsilon}, diff/epsilon: {diff / epsilon}"); 40 | } 41 | } 42 | 43 | private static void ArrayEqual(float[] actual, float[] expected, float epsilon) 44 | { 45 | Assert.AreEqual(expected.Length, actual.Length); 46 | for (int i = 0; i < expected.Length; i++) 47 | { 48 | float diff = Math.Abs(expected[i] - actual[i]); 49 | Assert.True(diff <= epsilon, $"expected: {expected[i]}, actual: {actual[i]}, diff: {diff}, epsilon: {epsilon}, diff/epsilon: {diff / epsilon}"); 50 | } 51 | } 52 | 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /Packages/com.github.asus4.tflite.common/Editor/MathTFTest.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 4d3252fc96bd54422b5f23442c5f5f21 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Packages/com.github.asus4.tflite.common/Editor/TensorFlowLite.Common.Editor.asmdef: -------------------------------------------------------------------------------- 1 | { 2 | "name": "TensorFlowLite.Common.Editor", 3 | "references": [ 4 | "GUID:0acc523941302664db1f4e527237feb3", 5 | "GUID:6e1d47a1424c040aca79d8b6a2710888", 6 | "GUID:bf0184192290e4dbd82dadbbe75162b1" 7 | ], 8 | "includePlatforms": [ 9 | "Editor" 10 | ], 11 | "excludePlatforms": [], 12 | "allowUnsafeCode": false, 13 | "overrideReferences": false, 14 | "precompiledReferences": [], 15 | "autoReferenced": true, 16 | "defineConstraints": [], 17 | "versionDefines": [], 18 | "noEngineReferences": false 19 | } -------------------------------------------------------------------------------- /Packages/com.github.asus4.tflite.common/Editor/TensorFlowLite.Common.Editor.asmdef.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 998dd6f4e06a040909106f874152bb84 3 | AssemblyDefinitionImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /Packages/com.github.asus4.tflite.common/Resources.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 8eb4c44d405054df4b9f47cc13b18fe2 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Packages/com.github.asus4.tflite.common/Resources/PrimitiveDraw.mat: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!21 &2100000 4 | Material: 5 | serializedVersion: 6 6 | m_ObjectHideFlags: 0 7 | m_CorrespondingSourceObject: {fileID: 0} 8 | m_PrefabInstance: {fileID: 0} 9 | m_PrefabAsset: {fileID: 0} 10 | m_Name: PrimitiveDraw 11 | m_Shader: {fileID: 4800000, guid: b6313144306f44d38b2a4a81b873ad8b, type: 3} 12 | m_ShaderKeywords: 13 | m_LightmapFlags: 4 14 | m_EnableInstancingVariants: 1 15 | m_DoubleSidedGI: 0 16 | m_CustomRenderQueue: -1 17 | stringTagMap: {} 18 | disabledShaderPasses: [] 19 | m_SavedProperties: 20 | serializedVersion: 3 21 | m_TexEnvs: 22 | - _BumpMap: 23 | m_Texture: {fileID: 0} 24 | m_Scale: {x: 1, y: 1} 25 | m_Offset: {x: 0, y: 0} 26 | - _DetailAlbedoMap: 27 | m_Texture: {fileID: 0} 28 | m_Scale: {x: 1, y: 1} 29 | m_Offset: {x: 0, y: 0} 30 | - _DetailMask: 31 | m_Texture: {fileID: 0} 32 | m_Scale: {x: 1, y: 1} 33 | m_Offset: {x: 0, y: 0} 34 | - _DetailNormalMap: 35 | m_Texture: {fileID: 0} 36 | m_Scale: {x: 1, y: 1} 37 | m_Offset: {x: 0, y: 0} 38 | - _EmissionMap: 39 | m_Texture: {fileID: 0} 40 | m_Scale: {x: 1, y: 1} 41 | m_Offset: {x: 0, y: 0} 42 | - _MainTex: 43 | m_Texture: {fileID: 0} 44 | m_Scale: {x: 1, y: 1} 45 | m_Offset: {x: 0, y: 0} 46 | - _MetallicGlossMap: 47 | m_Texture: {fileID: 0} 48 | m_Scale: {x: 1, y: 1} 49 | m_Offset: {x: 0, y: 0} 50 | - _OcclusionMap: 51 | m_Texture: {fileID: 0} 52 | m_Scale: {x: 1, y: 1} 53 | m_Offset: {x: 0, y: 0} 54 | - _ParallaxMap: 55 | m_Texture: {fileID: 0} 56 | m_Scale: {x: 1, y: 1} 57 | m_Offset: {x: 0, y: 0} 58 | m_Floats: 59 | - _BumpScale: 1 60 | - _Cull: 0 61 | - _Cutoff: 0.5 62 | - _DetailNormalMapScale: 1 63 | - _DstBlend: 0 64 | - _GlossMapScale: 1 65 | - _Glossiness: 0.5 66 | - _GlossyReflections: 1 67 | - _Metallic: 0 68 | - _Mode: 0 69 | - _OcclusionStrength: 1 70 | - _Parallax: 0.02 71 | - _SmoothnessTextureChannel: 0 72 | - _SpecularHighlights: 1 73 | - _SrcBlend: 1 74 | - _UVSec: 0 75 | - _ZBias: 0 76 | - _ZTest: 4 77 | - _ZWrite: 1 78 | m_Colors: 79 | - _Color: {r: 1, g: 0, b: 0, a: 1} 80 | - _EmissionColor: {r: 0, g: 0, b: 0, a: 1} 81 | -------------------------------------------------------------------------------- /Packages/com.github.asus4.tflite.common/Resources/PrimitiveDraw.mat.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 4de17cc76cae946fb8b4e78776071fa9 3 | NativeFormatImporter: 4 | externalObjects: {} 5 | mainObjectFileID: 0 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Packages/com.github.asus4.tflite.common/Resources/PrimitiveDraw.shader: -------------------------------------------------------------------------------- 1 | // Unity built-in shader source. Copyright (c) 2016 Unity Technologies. MIT license (see license.txt) 2 | 3 | // Simple "just colors" shader that's used for built-in debug visualizations, 4 | // in the editor etc. Just outputs _Color * vertex color; and blend/Z/cull/bias 5 | // controlled by material parameters. 6 | 7 | Shader "Hidden/PrimitiveDraw" 8 | { 9 | Properties 10 | { 11 | _Color ("Color", Color) = (1,1,1,1) 12 | _SrcBlend ("SrcBlend", Int) = 5.0 // SrcAlpha 13 | _DstBlend ("DstBlend", Int) = 10.0 // OneMinusSrcAlpha 14 | _ZWrite ("ZWrite", Int) = 1.0 // On 15 | _ZTest ("ZTest", Int) = 4.0 // LEqual 16 | _Cull ("Cull", Int) = 0.0 // Off 17 | _ZBias ("ZBias", Float) = 0.0 18 | } 19 | 20 | SubShader 21 | { 22 | Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" } 23 | Pass 24 | { 25 | Blend [_SrcBlend] [_DstBlend] 26 | ZWrite [_ZWrite] 27 | ZTest [_ZTest] 28 | Cull [_Cull] 29 | Offset [_ZBias], [_ZBias] 30 | 31 | CGPROGRAM 32 | #pragma vertex vert 33 | #pragma fragment frag 34 | #pragma target 3.0 35 | #pragma multi_compile _ UNITY_SINGLE_PASS_STEREO STEREO_INSTANCING_ON STEREO_MULTIVIEW_ON 36 | #pragma multi_compile_instancing 37 | #include "UnityCG.cginc" 38 | 39 | struct appdata_t { 40 | float4 vertex : POSITION; 41 | float4 color : COLOR; 42 | UNITY_VERTEX_INPUT_INSTANCE_ID 43 | }; 44 | struct v2f { 45 | fixed4 color : COLOR; 46 | float4 vertex : SV_POSITION; 47 | UNITY_VERTEX_OUTPUT_STEREO 48 | }; 49 | float4 _Color; 50 | v2f vert (appdata_t v) 51 | { 52 | v2f o; 53 | UNITY_SETUP_INSTANCE_ID(v); 54 | UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); 55 | o.vertex = UnityObjectToClipPos(v.vertex); 56 | o.color = v.color * _Color; 57 | return o; 58 | } 59 | 60 | fixed4 frag (v2f i) : SV_Target 61 | { 62 | return i.color; 63 | } 64 | ENDCG 65 | } 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /Packages/com.github.asus4.tflite.common/Resources/PrimitiveDraw.shader.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b6313144306f44d38b2a4a81b873ad8b 3 | ShaderImporter: 4 | externalObjects: {} 5 | defaultTextures: [] 6 | nonModifiableTextures: [] 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Packages/com.github.asus4.tflite.common/Resources/Resize.shader: -------------------------------------------------------------------------------- 1 | Shader "Hidden/TFLite/Resize" 2 | { 3 | Properties 4 | { 5 | _MainTex ("Texture", 2D) = "white" {} 6 | } 7 | SubShader 8 | { 9 | Cull Off 10 | ZWrite Off 11 | ZTest LEqual 12 | 13 | Pass 14 | { 15 | CGPROGRAM 16 | 17 | #pragma vertex vert 18 | #pragma fragment frag 19 | 20 | #include "UnityCG.cginc" 21 | 22 | uniform float4x4 _VertTransform; 23 | uniform float4 _UVRect; // the same as _MainTex_ST; 24 | 25 | struct appdata 26 | { 27 | float4 vertex : POSITION; 28 | float2 uv : TEXCOORD0; 29 | }; 30 | 31 | struct v2f 32 | { 33 | float2 uv : TEXCOORD0; 34 | float4 vertex : SV_POSITION; 35 | }; 36 | 37 | v2f vert (appdata v) 38 | { 39 | v2f o; 40 | o.vertex = UnityObjectToClipPos(mul(_VertTransform, v.vertex)); 41 | o.uv = v.uv * _UVRect.xy + _UVRect.zw; 42 | return o; 43 | } 44 | 45 | sampler2D _MainTex; 46 | 47 | fixed4 frag (v2f i) : SV_Target 48 | { 49 | if(i.uv.x < 0 || i.uv.x > 1 || i.uv.y < 0 || i.uv.y > 1) 50 | { 51 | return fixed4(0, 0, 0, 0); 52 | } 53 | return tex2D(_MainTex, i.uv); 54 | } 55 | ENDCG 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /Packages/com.github.asus4.tflite.common/Resources/Resize.shader.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 21ffff8492c1e4776902ecd90884ec73 3 | ShaderImporter: 4 | externalObjects: {} 5 | defaultTextures: [] 6 | nonModifiableTextures: [] 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Packages/com.github.asus4.tflite.common/Resources/TextureToTensor.compute: -------------------------------------------------------------------------------- 1 | // Each #kernel tells which function to compile; you can have many kernels 2 | #pragma kernel TextureToFloatTensor 3 | 4 | Texture2D InputTexture; 5 | int TextureWidth; 6 | int TextureHeight; 7 | 8 | RWStructuredBuffer OutputFloatTensor; 9 | 10 | [numthreads(8,8,1)] 11 | void TextureToFloatTensor(uint2 tid : SV_DispatchThreadID) 12 | { 13 | uint gid = (TextureHeight - 1 - tid.y) * TextureWidth + tid.x; 14 | float4 c = InputTexture[tid]; 15 | OutputFloatTensor[gid] = float3(c.x, c.y, c.z); 16 | } -------------------------------------------------------------------------------- /Packages/com.github.asus4.tflite.common/Resources/TextureToTensor.compute.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 7fd907a98056f45c9b112cae0a035404 3 | ComputeShaderImporter: 4 | externalObjects: {} 5 | currentAPIMask: 65537 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Packages/com.github.asus4.tflite.common/Runtime.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 4f2bd4cb00fc4401aa4f86a604b6d5dc 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Packages/com.github.asus4.tflite.common/Runtime/ArrayExtension.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | 5 | namespace TensorFlowLite 6 | { 7 | public static class ArrayExtension 8 | { 9 | public static IEnumerable> ToIndexValueTuple(this T[] arr) 10 | { 11 | int index = 0; 12 | return arr.Select(o => 13 | { 14 | return Tuple.Create(index++, o); 15 | }); 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Packages/com.github.asus4.tflite.common/Runtime/ArrayExtension.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 94cb7c3ca30ec450a829bd6b3c23f212 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Packages/com.github.asus4.tflite.common/Runtime/BaseImagePredictor.cs: -------------------------------------------------------------------------------- 1 | using System.Threading; 2 | using Cysharp.Threading.Tasks; 3 | using UnityEngine; 4 | 5 | namespace TensorFlowLite 6 | { 7 | public abstract class BaseImagePredictor : System.IDisposable where T : struct 8 | { 9 | protected Interpreter interpreter; 10 | protected int width; 11 | protected int height; 12 | protected int channels; 13 | protected T[,,] input0; 14 | protected TextureToTensor tex2tensor; 15 | protected TextureResizer resizer; 16 | protected TextureResizer.ResizeOptions resizeOptions; 17 | 18 | public Texture inputTex 19 | { 20 | get 21 | { 22 | return (tex2tensor.texture != null) 23 | ? tex2tensor.texture as Texture 24 | : resizer.texture as Texture; 25 | } 26 | } 27 | public Material transformMat => resizer.material; 28 | 29 | public TextureResizer.ResizeOptions ResizeOptions 30 | { 31 | get => resizeOptions; 32 | set => resizeOptions = value; 33 | } 34 | 35 | public BaseImagePredictor(string modelPath, bool useGPU = true) 36 | { 37 | var options = new InterpreterOptions(); 38 | if (useGPU) 39 | { 40 | options.AddGpuDelegate(); 41 | } 42 | else 43 | { 44 | options.threads = SystemInfo.processorCount; 45 | } 46 | 47 | interpreter = new Interpreter(FileUtil.LoadFile(modelPath), options); 48 | interpreter.LogIOInfo(); 49 | InitInputs(); 50 | 51 | tex2tensor = new TextureToTensor(); 52 | resizer = new TextureResizer(); 53 | resizeOptions = new TextureResizer.ResizeOptions() 54 | { 55 | aspectMode = TextureResizer.AspectMode.Fill, 56 | rotationDegree = 0, 57 | mirrorHorizontal = false, 58 | mirrorVertical = false, 59 | width = width, 60 | height = height, 61 | }; 62 | } 63 | 64 | public virtual void Dispose() 65 | { 66 | interpreter?.Dispose(); 67 | tex2tensor?.Dispose(); 68 | resizer?.Dispose(); 69 | } 70 | 71 | public abstract void Invoke(Texture inputTex); 72 | 73 | protected void ToTensor(Texture inputTex, float[,,] inputs) 74 | { 75 | RenderTexture tex = resizer.Resize(inputTex, resizeOptions); 76 | tex2tensor.ToTensor(tex, inputs); 77 | } 78 | 79 | protected void ToTensor(RenderTexture inputTex, float[,,] inputs, bool resize) 80 | { 81 | RenderTexture tex = resize ? resizer.Resize(inputTex, resizeOptions) : inputTex; 82 | tex2tensor.ToTensor(tex, inputs); 83 | } 84 | 85 | protected void ToTensor(Texture inputTex, float[,,] inputs, float offset, float scale) 86 | { 87 | RenderTexture tex = resizer.Resize(inputTex, resizeOptions); 88 | tex2tensor.ToTensor(tex, inputs, offset, scale); 89 | } 90 | 91 | protected void ToTensor(Texture inputTex, sbyte[,,] inputs) 92 | { 93 | RenderTexture tex = resizer.Resize(inputTex, resizeOptions); 94 | tex2tensor.ToTensor(tex, inputs); 95 | } 96 | 97 | protected async UniTask ToTensorAsync(Texture inputTex, float[,,] inputs, CancellationToken cancellationToken) 98 | { 99 | RenderTexture tex = resizer.Resize(inputTex, resizeOptions); 100 | await tex2tensor.ToTensorAsync(tex, inputs); 101 | return true; 102 | } 103 | 104 | protected async UniTask ToTensorAsync(RenderTexture inputTex, float[,,] inputs, bool resize, CancellationToken cancellationToken) 105 | { 106 | RenderTexture tex = resize ? resizer.Resize(inputTex, resizeOptions) : inputTex; 107 | await tex2tensor.ToTensorAsync(tex, inputs); 108 | return true; 109 | } 110 | 111 | private void InitInputs() 112 | { 113 | var idim0 = interpreter.GetInputTensorInfo(0).shape; 114 | height = idim0[1]; 115 | width = idim0[2]; 116 | channels = idim0[3]; 117 | input0 = new T[height, width, channels]; 118 | 119 | int inputCount = interpreter.GetInputTensorCount(); 120 | for (int i = 0; i < inputCount; i++) 121 | { 122 | int[] dim = interpreter.GetInputTensorInfo(i).shape; 123 | interpreter.ResizeInputTensor(i, dim); 124 | } 125 | interpreter.AllocateTensors(); 126 | } 127 | } 128 | } 129 | -------------------------------------------------------------------------------- /Packages/com.github.asus4.tflite.common/Runtime/BaseImagePredictor.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 4bdaba9fb2b2f44cba00722bd1e98533 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Packages/com.github.asus4.tflite.common/Runtime/Color32Extension.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using Unity.Mathematics; 3 | 4 | namespace TensorFlowLite 5 | { 6 | public static class Color32Extension 7 | { 8 | public static float4 ToARGB(this Color32 c) 9 | { 10 | return new float4( 11 | unchecked((sbyte)c.a) / 255f, 12 | unchecked((sbyte)c.r) / 255f, 13 | unchecked((sbyte)c.g) / 255f, 14 | unchecked((sbyte)c.b) / 255f 15 | ); 16 | } 17 | 18 | public static float4 ToRGBA(this Color32 c) 19 | { 20 | return new float4( 21 | (float)unchecked((sbyte)c.r) / 255f, 22 | (float)unchecked((sbyte)c.g) / 255f, 23 | (float)unchecked((sbyte)c.b) / 255f, 24 | (float)unchecked((sbyte)c.a) / 255f 25 | ); 26 | } 27 | 28 | public static Color32 FromHex(uint c) 29 | { 30 | return new Color32() 31 | { 32 | a = unchecked((byte)(sbyte)((c & 0xFF000000) >> 24)), 33 | r = unchecked((byte)(sbyte)((c) & 0x00FF0000 >> 16)), 34 | g = unchecked((byte)(sbyte)((c & 0x0000FF00) >> 8)), 35 | b = unchecked((byte)(sbyte)((c & 0x000000FF))), 36 | }; 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /Packages/com.github.asus4.tflite.common/Runtime/Color32Extension.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 4e3325678ff4b4e37b11ccccf44628b7 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Packages/com.github.asus4.tflite.common/Runtime/DisposeUtil.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | 3 | namespace TensorFlowLite 4 | { 5 | public static class DisposeUtil 6 | { 7 | public static void TryDispose(RenderTexture tex) 8 | { 9 | if (tex != null) 10 | { 11 | tex.Release(); 12 | Object.Destroy(tex); 13 | } 14 | } 15 | 16 | public static void TryDispose(Texture2D tex) 17 | { 18 | if (tex != null) 19 | { 20 | Object.Destroy(tex); 21 | } 22 | } 23 | 24 | public static void TryDispose(Material mat) 25 | { 26 | if (mat != null) 27 | { 28 | Object.Destroy(mat); 29 | } 30 | } 31 | 32 | public static void TryDispose(ComputeBuffer buf) 33 | { 34 | if (buf != null) 35 | { 36 | buf.Dispose(); 37 | } 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /Packages/com.github.asus4.tflite.common/Runtime/DisposeUtil.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: e70d8425bfa174d8bb4cddb6cb92f91a 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Packages/com.github.asus4.tflite.common/Runtime/FilePopupAttribute.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | 6 | using UnityEngine; 7 | #if UNITY_EDITOR 8 | using UnityEditor; 9 | #endif // UNITY_EDITOR 10 | 11 | namespace TensorFlowLite 12 | { 13 | public class FilePopupAttribute : PropertyAttribute 14 | { 15 | public string regex; 16 | 17 | public FilePopupAttribute(string searchPattern) 18 | { 19 | this.regex = searchPattern; 20 | } 21 | } 22 | 23 | #if UNITY_EDITOR 24 | [CustomPropertyDrawer(typeof(FilePopupAttribute))] 25 | public class FilePopupDrawer : PropertyDrawer 26 | { 27 | string[] displayNames = null; 28 | int selectedIndex = -1; 29 | 30 | public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) 31 | { 32 | if (property.propertyType != SerializedPropertyType.String) 33 | { 34 | Debug.LogError($"type: {property.propertyType} is not supported."); 35 | EditorGUI.LabelField(position, label.text, "Use FilePopup with string."); 36 | return; 37 | } 38 | 39 | if (displayNames == null) 40 | { 41 | string regex = (attribute as FilePopupAttribute).regex; 42 | InitDisplayNames(regex); 43 | } 44 | 45 | if (selectedIndex < 0) 46 | { 47 | selectedIndex = FindSlectedIndex(property.stringValue); 48 | } 49 | 50 | EditorGUI.BeginProperty(position, label, property); 51 | 52 | selectedIndex = EditorGUI.Popup(position, label.text, selectedIndex, displayNames); 53 | property.stringValue = displayNames[selectedIndex]; 54 | 55 | EditorGUI.EndProperty(); 56 | } 57 | 58 | void InitDisplayNames(string regex) 59 | { 60 | string[] fullpathes = Directory.GetFiles(Application.streamingAssetsPath, regex, SearchOption.AllDirectories); 61 | 62 | displayNames = fullpathes.Select(f => 63 | { 64 | string path = f.Replace(Application.streamingAssetsPath, "") 65 | .Replace('\\', '/'); 66 | if (path.StartsWith("/")) 67 | { 68 | path = path.Substring(1); 69 | } 70 | return path; 71 | }).ToArray(); 72 | } 73 | 74 | int FindSlectedIndex(string value) 75 | { 76 | for (int i = 0; i < displayNames.Length; i++) 77 | { 78 | if (displayNames[i] == value) 79 | { 80 | return i; 81 | } 82 | } 83 | return 0; 84 | } 85 | } 86 | #endif // UNITY_EDITOR 87 | 88 | } 89 | -------------------------------------------------------------------------------- /Packages/com.github.asus4.tflite.common/Runtime/FilePopupAttribute.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b59c9e97b35ab43ceac5a7b74067b471 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Packages/com.github.asus4.tflite.common/Runtime/FileUtil.cs: -------------------------------------------------------------------------------- 1 | using System.IO; 2 | using UnityEngine; 3 | using UnityEngine.Networking; 4 | 5 | namespace TensorFlowLite 6 | { 7 | public static class FileUtil 8 | { 9 | public static byte[] LoadFile(string path) 10 | { 11 | if (!IsPathRooted(path)) 12 | { 13 | path = Path.Combine(Application.streamingAssetsPath, path); 14 | } 15 | 16 | if (Application.platform != RuntimePlatform.Android) 17 | { 18 | path = "file://" + path; 19 | } 20 | 21 | var request = UnityWebRequest.Get(path); 22 | request.SendWebRequest(); 23 | while (!request.isDone) 24 | { 25 | } 26 | return request.downloadHandler.data; 27 | } 28 | 29 | static bool IsPathRooted(string path) 30 | { 31 | if (path.StartsWith("jar:file:")) 32 | { 33 | return true; 34 | } 35 | return Path.IsPathRooted(path); 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /Packages/com.github.asus4.tflite.common/Runtime/FileUtil.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: c2d0076f6e0f54a3d9526d0371bed726 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Packages/com.github.asus4.tflite.common/Runtime/InterpreterExtension.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | 3 | namespace TensorFlowLite 4 | { 5 | public static class InterpreterExtension 6 | { 7 | public static void LogIOInfo(this Interpreter interpreter) 8 | { 9 | int inputCount = interpreter.GetInputTensorCount(); 10 | int outputCount = interpreter.GetOutputTensorCount(); 11 | var sb = new System.Text.StringBuilder(); 12 | for (int i = 0; i < inputCount; i++) 13 | { 14 | sb.AppendFormat("intput {0}: {1}", i, interpreter.GetInputTensorInfo(i)); 15 | sb.AppendLine(); 16 | } 17 | for (int i = 0; i < outputCount; i++) 18 | { 19 | sb.AppendFormat("output {0}: {1}", i, interpreter.GetOutputTensorInfo(i)); 20 | sb.AppendLine(); 21 | } 22 | Debug.Log(sb.ToString()); 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Packages/com.github.asus4.tflite.common/Runtime/InterpreterExtension.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 2217c37a359c24e438e32adc244d5f18 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Packages/com.github.asus4.tflite.common/Runtime/MathTF.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Runtime.CompilerServices; 5 | using UnityEngine; 6 | 7 | namespace TensorFlowLite 8 | { 9 | public static class MathTF 10 | { 11 | [MethodImpl(MethodImplOptions.AggressiveInlining)] 12 | public static float Sigmoid(float x) 13 | { 14 | return (1.0f / (1.0f + Mathf.Exp(-x))); 15 | } 16 | 17 | [MethodImpl(MethodImplOptions.AggressiveInlining)] 18 | public static Vector3 Lerp(in Vector3 a, in Vector3 b, in Vector3 t, bool invertY = false) 19 | { 20 | return new Vector3( 21 | Mathf.Lerp(a.x, b.x, t.x), 22 | Mathf.Lerp(a.y, b.y, invertY ? 1f - t.y : t.y), 23 | Mathf.Lerp(a.z, b.z, t.z) 24 | ); 25 | } 26 | 27 | [MethodImpl(MethodImplOptions.AggressiveInlining)] 28 | public static Rect Lerp(in Vector3 a, in Vector3 b, in Rect t, bool invertY = false) 29 | { 30 | return new Rect( 31 | Mathf.Lerp(a.x, b.x, t.x), 32 | Mathf.Lerp(a.y, b.y, invertY ? 1f - t.y - t.height : t.y), 33 | t.width * (b.x - a.x), 34 | t.height * (b.y - a.y) 35 | ); 36 | } 37 | 38 | [MethodImpl(MethodImplOptions.AggressiveInlining)] 39 | public static Vector3 LerpUnclamped(in Vector3 a, in Vector3 b, in Vector3 t) 40 | { 41 | return new Vector3( 42 | Mathf.LerpUnclamped(a.x, b.x, t.x), 43 | Mathf.LerpUnclamped(a.y, b.y, t.y), 44 | Mathf.LerpUnclamped(a.z, b.z, t.z) 45 | ); 46 | } 47 | 48 | public static IEnumerable Softmax(this IEnumerable arr) 49 | { 50 | float max = arr.Max(); 51 | var expArr = arr.Select(n => Mathf.Exp(n - max)); 52 | var sum = expArr.Sum(); 53 | return expArr.Select(n => n / sum); 54 | } 55 | 56 | public static IEnumerable Softmax(this IEnumerable arr) 57 | { 58 | double max = arr.Max(); 59 | var expArr = arr.Select(n => Math.Exp(n - max)); 60 | var sum = expArr.Sum(); 61 | return expArr.Select(n => n / sum); 62 | } 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /Packages/com.github.asus4.tflite.common/Runtime/MathTF.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 5d1e4ec836dc44c378c692f175079085 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Packages/com.github.asus4.tflite.common/Runtime/MatrixExtension.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | 3 | namespace TensorFlowLite 4 | { 5 | public static class MatrixExtension 6 | { 7 | // https://forum.unity.com/threads/how-to-assign-matrix4x4-to-transform.121966/ 8 | 9 | 10 | public static Quaternion ExtractRotation(this Matrix4x4 matrix) 11 | { 12 | Vector3 forward; 13 | forward.x = matrix.m02; 14 | forward.y = matrix.m12; 15 | forward.z = matrix.m22; 16 | 17 | Vector3 upwards; 18 | upwards.x = matrix.m01; 19 | upwards.y = matrix.m11; 20 | upwards.z = matrix.m21; 21 | 22 | return Quaternion.LookRotation(forward, upwards); 23 | } 24 | 25 | public static Vector3 ExtractPosition(this Matrix4x4 matrix) 26 | { 27 | Vector3 position; 28 | position.x = matrix.m03; 29 | position.y = matrix.m13; 30 | position.z = matrix.m23; 31 | return position; 32 | } 33 | 34 | public static Vector3 ExtractScale(this Matrix4x4 matrix) 35 | { 36 | Vector3 scale; 37 | scale.x = new Vector4(matrix.m00, matrix.m10, matrix.m20, matrix.m30).magnitude; 38 | scale.y = new Vector4(matrix.m01, matrix.m11, matrix.m21, matrix.m31).magnitude; 39 | scale.z = new Vector4(matrix.m02, matrix.m12, matrix.m22, matrix.m32).magnitude; 40 | return scale; 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /Packages/com.github.asus4.tflite.common/Runtime/MatrixExtension.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 66ad322f37169467a9ebddfd7fd71907 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Packages/com.github.asus4.tflite.common/Runtime/PrimitiveDraw.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: c706176b26403450fbb6733ced095a06 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Packages/com.github.asus4.tflite.common/Runtime/RectExtension.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using UnityEngine; 3 | 4 | namespace TensorFlowLite 5 | { 6 | 7 | public static class RectExtension 8 | { 9 | public static float IntersectionOverUnion(this Rect rect0, Rect rect1) 10 | { 11 | float sx0 = rect0.xMin; 12 | float sy0 = rect0.yMin; 13 | float ex0 = rect0.xMax; 14 | float ey0 = rect0.yMax; 15 | float sx1 = rect1.xMin; 16 | float sy1 = rect1.yMin; 17 | float ex1 = rect1.xMax; 18 | float ey1 = rect1.yMax; 19 | 20 | float xmin0 = Mathf.Min(sx0, ex0); 21 | float ymin0 = Mathf.Min(sy0, ey0); 22 | float xmax0 = Mathf.Max(sx0, ex0); 23 | float ymax0 = Mathf.Max(sy0, ey0); 24 | float xmin1 = Mathf.Min(sx1, ex1); 25 | float ymin1 = Mathf.Min(sy1, ey1); 26 | float xmax1 = Mathf.Max(sx1, ex1); 27 | float ymax1 = Mathf.Max(sy1, ey1); 28 | 29 | float area0 = (ymax0 - ymin0) * (xmax0 - xmin0); 30 | float area1 = (ymax1 - ymin1) * (xmax1 - xmin1); 31 | if (area0 <= 0 || area1 <= 0) 32 | { 33 | return 0.0f; 34 | } 35 | 36 | float intersect_xmin = Mathf.Max(xmin0, xmin1); 37 | float intersect_ymin = Mathf.Max(ymin0, ymin1); 38 | float intersect_xmax = Mathf.Min(xmax0, xmax1); 39 | float intersect_ymax = Mathf.Min(ymax0, ymax1); 40 | 41 | float intersect_area = Mathf.Max(intersect_ymax - intersect_ymin, 0.0f) * 42 | Mathf.Max(intersect_xmax - intersect_xmin, 0.0f); 43 | 44 | return intersect_area / (area0 + area1 - intersect_area); 45 | } 46 | 47 | public static Rect GetBoundingBox(Vector2[] arr) 48 | { 49 | float xMin = float.MaxValue; 50 | float yMin = float.MaxValue; 51 | float xMax = float.MinValue; 52 | float yMax = float.MinValue; 53 | 54 | foreach (Vector2 v in arr) 55 | { 56 | xMin = Math.Min(xMin, v.x); 57 | yMin = Math.Min(yMin, v.y); 58 | xMax = Math.Max(xMax, v.x); 59 | yMax = Math.Max(yMax, v.y); 60 | } 61 | 62 | return Rect.MinMaxRect(xMin, yMin, xMax, yMax); 63 | } 64 | 65 | public static Rect GetBoundingBox(Vector3[] arr) 66 | { 67 | float xMin = float.MaxValue; 68 | float yMin = float.MaxValue; 69 | float xMax = float.MinValue; 70 | float yMax = float.MinValue; 71 | 72 | foreach (Vector3 v in arr) 73 | { 74 | xMin = Math.Min(xMin, v.x); 75 | yMin = Math.Min(yMin, v.y); 76 | xMax = Math.Max(xMax, v.x); 77 | yMax = Math.Max(yMax, v.y); 78 | } 79 | 80 | return Rect.MinMaxRect(xMin, yMin, xMax, yMax); 81 | } 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /Packages/com.github.asus4.tflite.common/Runtime/RectExtension.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: c23c4212c4fd6466382abd989af2e432 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Packages/com.github.asus4.tflite.common/Runtime/TensorFlowLite.Common.asmdef: -------------------------------------------------------------------------------- 1 | { 2 | "name": "TensorFlowLite.Common", 3 | "references": [ 4 | "GUID:d8b63aba1907145bea998dd612889d6b", 5 | "GUID:6e1d47a1424c040aca79d8b6a2710888", 6 | "GUID:f51ebe6a0ceec4240a699833d6309b23" 7 | ], 8 | "includePlatforms": [], 9 | "excludePlatforms": [], 10 | "allowUnsafeCode": false, 11 | "overrideReferences": false, 12 | "precompiledReferences": [], 13 | "autoReferenced": true, 14 | "defineConstraints": [], 15 | "versionDefines": [], 16 | "noEngineReferences": false 17 | } -------------------------------------------------------------------------------- /Packages/com.github.asus4.tflite.common/Runtime/TensorFlowLite.Common.asmdef.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: bf0184192290e4dbd82dadbbe75162b1 3 | AssemblyDefinitionImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /Packages/com.github.asus4.tflite.common/Runtime/TextureResizer.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | 3 | namespace TensorFlowLite 4 | { 5 | /// 6 | /// Utility to resize the texture 7 | /// 8 | public class TextureResizer : System.IDisposable 9 | { 10 | public enum AspectMode 11 | { 12 | None, 13 | Fit, 14 | Fill, 15 | } 16 | 17 | public struct ResizeOptions 18 | { 19 | public int width; 20 | public int height; 21 | public float rotationDegree; 22 | public bool mirrorHorizontal; 23 | public bool mirrorVertical; 24 | public AspectMode aspectMode; 25 | 26 | public ResizeOptions GetModifedForWebcam(WebCamTexture texture) 27 | { 28 | ResizeOptions modified = this; // copy 29 | int videoRotationAngle = texture.videoRotationAngle; 30 | if (rotationDegree - videoRotationAngle < 0) 31 | { 32 | modified.rotationDegree = 360f + rotationDegree - videoRotationAngle; 33 | } 34 | else 35 | { 36 | modified.rotationDegree = rotationDegree - videoRotationAngle; 37 | } 38 | 39 | bool needFlip90 = videoRotationAngle == 90 || videoRotationAngle == 270; 40 | if (needFlip90) 41 | { 42 | modified.mirrorVertical = mirrorHorizontal; 43 | modified.mirrorHorizontal = mirrorVertical; 44 | } 45 | 46 | if (texture.videoVerticallyMirrored) 47 | { 48 | modified.mirrorVertical = !modified.mirrorVertical; 49 | } 50 | return modified; 51 | } 52 | } 53 | 54 | RenderTexture resizeTexture; 55 | Material _blitMaterial; 56 | 57 | static readonly int _VertTransform = Shader.PropertyToID("_VertTransform"); 58 | static readonly int _UVRect = Shader.PropertyToID("_UVRect"); 59 | 60 | public RenderTexture texture => resizeTexture; 61 | 62 | public Material material 63 | { 64 | get 65 | { 66 | if (_blitMaterial == null) 67 | { 68 | _blitMaterial = new Material(Shader.Find("Hidden/TFLite/Resize")); 69 | } 70 | return _blitMaterial; 71 | } 72 | } 73 | 74 | public Vector4 UVRect 75 | { 76 | get => material.GetVector(_UVRect); 77 | set => material.SetVector(_UVRect, value); 78 | } 79 | 80 | public Matrix4x4 VertexTransfrom 81 | { 82 | get => material.GetMatrix(_VertTransform); 83 | set => material.SetMatrix(_VertTransform, value); 84 | } 85 | 86 | public TextureResizer() 87 | { 88 | 89 | } 90 | 91 | public void Dispose() 92 | { 93 | DisposeUtil.TryDispose(resizeTexture); 94 | DisposeUtil.TryDispose(_blitMaterial); 95 | } 96 | 97 | 98 | public RenderTexture Resize(Texture texture, ResizeOptions options) 99 | { 100 | // Set options 101 | if (texture is WebCamTexture) 102 | { 103 | options = options.GetModifedForWebcam((WebCamTexture)texture); 104 | } 105 | 106 | VertexTransfrom = GetVertTransform(options.rotationDegree, options.mirrorHorizontal, options.mirrorVertical); 107 | UVRect = GetTextureST(texture, options); 108 | return ApplyResize(texture, options.width, options.height, false); 109 | } 110 | 111 | public RenderTexture Resize(Texture texture, 112 | int width, int height, bool fillBackground, 113 | Matrix4x4 transform, 114 | Vector4 uvRect) 115 | { 116 | VertexTransfrom = transform; 117 | UVRect = uvRect; 118 | return ApplyResize(texture, width, height, fillBackground); 119 | } 120 | 121 | private RenderTexture ApplyResize(Texture texture, int width, int height, bool fillBackground) 122 | { 123 | if (resizeTexture == null 124 | || resizeTexture.width != width 125 | || resizeTexture.height != height) 126 | { 127 | DisposeUtil.TryDispose(resizeTexture); 128 | resizeTexture = new RenderTexture(width, height, 0, RenderTextureFormat.ARGB32); 129 | } 130 | 131 | if (fillBackground) 132 | { 133 | // Fill with color 0,0,0,0 134 | Graphics.Blit(Texture2D.blackTexture, resizeTexture); 135 | } 136 | 137 | Graphics.Blit(texture, resizeTexture, material, 0); 138 | return resizeTexture; 139 | } 140 | 141 | private static Vector4 GetTextureST(float srcAspect, float dstAspect, AspectMode mode) 142 | { 143 | switch (mode) 144 | { 145 | case AspectMode.None: 146 | return new Vector4(1, 1, 0, 0); 147 | case AspectMode.Fit: 148 | if (srcAspect > dstAspect) 149 | { 150 | float s = srcAspect / dstAspect; 151 | return new Vector4(1, s, 0, (1 - s) / 2); 152 | } 153 | else 154 | { 155 | float s = dstAspect / srcAspect; 156 | return new Vector4(s, 1, (1 - s) / 2, 0); 157 | } 158 | case AspectMode.Fill: 159 | if (srcAspect > dstAspect) 160 | { 161 | float s = dstAspect / srcAspect; 162 | return new Vector4(s, 1, (1 - s) / 2, 0); 163 | } 164 | else 165 | { 166 | float s = srcAspect / dstAspect; 167 | return new Vector4(1, s, 0, (1 - s) / 2); 168 | } 169 | } 170 | throw new System.Exception("Unknown aspect mode"); 171 | } 172 | 173 | public static Vector4 GetTextureST(Texture sourceTex, ResizeOptions options) 174 | { 175 | return GetTextureST( 176 | (float)sourceTex.width / (float)sourceTex.height, // src 177 | (float)options.width / (float)options.height, // dst 178 | options.aspectMode); 179 | } 180 | 181 | private static readonly Matrix4x4 PUSH_MATRIX = Matrix4x4.Translate(new Vector3(0.5f, 0.5f, 0)); 182 | private static readonly Matrix4x4 POP_MATRIX = Matrix4x4.Translate(new Vector3(-0.5f, -0.5f, 0)); 183 | private static Matrix4x4 GetVertTransform(float rotation, bool mirrorHorizontal, bool mirrorVertical) 184 | { 185 | Vector3 scale = new Vector3( 186 | mirrorHorizontal ? -1 : 1, 187 | mirrorVertical ? -1 : 1, 188 | 1); 189 | Matrix4x4 trs = Matrix4x4.TRS( 190 | Vector3.zero, 191 | Quaternion.Euler(0, 0, rotation), 192 | scale 193 | ); 194 | return PUSH_MATRIX * trs * POP_MATRIX; 195 | } 196 | 197 | } 198 | } 199 | -------------------------------------------------------------------------------- /Packages/com.github.asus4.tflite.common/Runtime/TextureResizer.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: eb64eef2833824170b7eca20db69c37a 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Packages/com.github.asus4.tflite.common/Runtime/TextureToTensor.cs: -------------------------------------------------------------------------------- 1 | using Cysharp.Threading.Tasks; 2 | using UnityEngine; 3 | 4 | namespace TensorFlowLite 5 | { 6 | /// 7 | /// Utility to convert Texture to Tensor 8 | /// 9 | public class TextureToTensor : System.IDisposable 10 | { 11 | 12 | Texture2D fetchTexture; 13 | ComputeShader compute; 14 | ComputeBuffer tensorBuffer; 15 | 16 | public Texture2D texture => fetchTexture; 17 | 18 | static readonly int InputTexture = Shader.PropertyToID("InputTexture"); 19 | static readonly int OutputFloatTensor = Shader.PropertyToID("OutputFloatTensor"); 20 | static readonly int TextureWidth = Shader.PropertyToID("TextureWidth"); 21 | static readonly int TextureHeight = Shader.PropertyToID("TextureHeight"); 22 | 23 | 24 | public TextureToTensor() 25 | { 26 | compute = Resources.Load("TextureToTensor"); 27 | } 28 | 29 | public void Dispose() 30 | { 31 | DisposeUtil.TryDispose(fetchTexture); 32 | DisposeUtil.TryDispose(tensorBuffer); 33 | } 34 | 35 | public void ToTensor(RenderTexture texture, sbyte[,,] inputs) 36 | { 37 | var pixels = FetchToTexture2D(texture).GetRawTextureData(); 38 | int width = texture.width; 39 | int height = texture.height - 1; 40 | for (int i = 0; i < pixels.Length; i++) 41 | { 42 | int y = height - i / width; 43 | int x = i % width; 44 | inputs[y, x, 0] = (sbyte)pixels[i].r; 45 | inputs[y, x, 1] = (sbyte)pixels[i].g; 46 | inputs[y, x, 2] = (sbyte)pixels[i].b; 47 | } 48 | } 49 | 50 | 51 | public void ToTensor(RenderTexture texture, float[,,] inputs) 52 | { 53 | if (texture.width % 8 != 0 || texture.height % 8 != 0) 54 | { 55 | ToTensorCPU(texture, inputs); 56 | } 57 | else 58 | { 59 | ToTensorGPU(texture, inputs); 60 | } 61 | } 62 | 63 | public void ToTensor(RenderTexture texture, out ComputeBuffer buffer) 64 | { 65 | Debug.Assert(texture.width % 8 == 0); 66 | Debug.Assert(texture.height % 8 == 0); 67 | ToTensorGPU(texture); 68 | buffer = tensorBuffer; 69 | } 70 | 71 | public void ToTensor(RenderTexture texture, float[,,] inputs, float offset, float scale) 72 | { 73 | // TODO: optimize this 74 | var pixels = FetchToTexture2D(texture).GetRawTextureData(); 75 | int width = texture.width; 76 | int height = texture.height - 1; 77 | for (int i = 0; i < pixels.Length; i++) 78 | { 79 | int y = height - i / width; 80 | int x = i % width; 81 | inputs[y, x, 0] = (pixels[i].r - offset) * scale; 82 | inputs[y, x, 1] = (pixels[i].g - offset) * scale; 83 | inputs[y, x, 2] = (pixels[i].b - offset) * scale; 84 | } 85 | } 86 | 87 | public async UniTask ToTensorAsync(RenderTexture texture, float[,,] inputs) 88 | { 89 | await UniTask.SwitchToMainThread(PlayerLoopTiming.FixedUpdate); 90 | var pixels = FetchToTexture2D(texture).GetRawTextureData(); 91 | int width = texture.width; 92 | int height = texture.height - 1; 93 | await UniTask.SwitchToThreadPool(); 94 | 95 | const float scale = 255f; 96 | for (int i = 0; i < pixels.Length; i++) 97 | { 98 | int y = height - i / width; 99 | int x = i % width; 100 | inputs[y, x, 0] = (float)(pixels[i].r) / scale; 101 | inputs[y, x, 1] = (float)(pixels[i].g) / scale; 102 | inputs[y, x, 2] = (float)(pixels[i].b) / scale; 103 | } 104 | return true; 105 | } 106 | 107 | private void ToTensorCPU(RenderTexture texture, float[,,] inputs) 108 | { 109 | var pixels = FetchToTexture2D(texture).GetRawTextureData(); 110 | 111 | int width = texture.width; 112 | int height = texture.height - 1; 113 | const float scale = 255f; 114 | for (int i = 0; i < pixels.Length; i++) 115 | { 116 | int y = height - i / width; 117 | int x = i % width; 118 | inputs[y, x, 0] = (float)(pixels[i].r) / scale; 119 | inputs[y, x, 1] = (float)(pixels[i].g) / scale; 120 | inputs[y, x, 2] = (float)(pixels[i].b) / scale; 121 | } 122 | } 123 | 124 | private void ToTensorGPU(RenderTexture texture) 125 | { 126 | int width = texture.width; 127 | int height = texture.height; 128 | 129 | if (tensorBuffer == null || tensorBuffer.count != width * height) 130 | { 131 | DisposeUtil.TryDispose(tensorBuffer); 132 | tensorBuffer = new ComputeBuffer(width * height, sizeof(float) * 3); 133 | } 134 | int kernel = compute.FindKernel("TextureToFloatTensor"); 135 | 136 | compute.SetTexture(kernel, InputTexture, texture); 137 | compute.SetBuffer(kernel, OutputFloatTensor, tensorBuffer); 138 | compute.SetInt(TextureWidth, width); 139 | compute.SetInt(TextureHeight, height); 140 | 141 | compute.Dispatch(kernel, width / 8, height / 8, 1); 142 | } 143 | 144 | private void ToTensorGPU(RenderTexture texture, float[,,] inputs) 145 | { 146 | ToTensorGPU(texture); 147 | tensorBuffer.GetData(inputs); 148 | } 149 | 150 | private Texture2D FetchToTexture2D(RenderTexture texture) 151 | { 152 | if (fetchTexture == null || !IsSameSize(fetchTexture, texture)) 153 | { 154 | // Due to GetRawTextureData() returns incorrect bytes length, we cant use liner color space options 155 | // https://fogbugz.unity3d.com/default.asp?1271542_g3prspfd30mhavcb 156 | // fetchTexture = new Texture2D(texture.width, texture.height, TextureFormat.RGB24, 0, false); 157 | fetchTexture = new Texture2D(texture.width, texture.height, TextureFormat.RGBA32, false); 158 | } 159 | var prevRT = RenderTexture.active; 160 | RenderTexture.active = texture; 161 | 162 | fetchTexture.ReadPixels(new Rect(0, 0, texture.width, texture.height), 0, 0); 163 | fetchTexture.Apply(); 164 | 165 | RenderTexture.active = prevRT; 166 | 167 | return fetchTexture; 168 | } 169 | 170 | private static bool IsSameSize(Texture a, Texture b) 171 | { 172 | return a.width == b.width && a.height == b.height; 173 | } 174 | 175 | 176 | } 177 | } 178 | -------------------------------------------------------------------------------- /Packages/com.github.asus4.tflite.common/Runtime/TextureToTensor.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 4d921394ca6904b1ead74ade609de2cd 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Packages/com.github.asus4.tflite.common/Runtime/WebCamUtil.cs: -------------------------------------------------------------------------------- 1 | using System.Linq; 2 | using UnityEngine; 3 | 4 | namespace TensorFlowLite 5 | { 6 | public static class WebCamUtil 7 | { 8 | public struct PreferSpec 9 | { 10 | public bool isFrontFacing; 11 | public WebCamKind kind; 12 | 13 | public int GetScore(in WebCamDevice device) 14 | { 15 | int score = 0; 16 | if (device.isFrontFacing == isFrontFacing) score++; 17 | if (device.kind == kind) score++; 18 | return score; 19 | } 20 | } 21 | 22 | public static readonly PreferSpec DefaultPreferSpec = new PreferSpec() 23 | { 24 | isFrontFacing = false, 25 | kind = WebCamKind.WideAngle, 26 | }; 27 | 28 | public static string FindName(PreferSpec spec = default(PreferSpec)) 29 | { 30 | var devices = WebCamTexture.devices; 31 | if (Application.isMobilePlatform) 32 | { 33 | var prefers = devices.OrderByDescending(d => spec.GetScore(d)); 34 | return prefers.First().name; 35 | } 36 | return devices.First().name; 37 | } 38 | 39 | private static readonly Matrix4x4 PUSH_MATRIX = Matrix4x4.Translate(new Vector3(0.5f, 0.5f, 0)); 40 | private static readonly Matrix4x4 POP_MATRIX = Matrix4x4.Translate(new Vector3(-0.5f, -0.5f, 0)); 41 | 42 | public static Matrix4x4 GetMatrix(float rotationDegree, bool mirrorHorizontal, bool mirrorVertical) 43 | { 44 | return 45 | PUSH_MATRIX 46 | * Matrix4x4.TRS( 47 | new Vector3(0, 0, 0), 48 | Quaternion.Euler(0, 0, rotationDegree), 49 | new Vector3( 50 | mirrorHorizontal ? -1 : 1, 51 | mirrorVertical ? -1 : 1, 52 | 1 53 | ) 54 | ) 55 | * POP_MATRIX; 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /Packages/com.github.asus4.tflite.common/Runtime/WebCamUtil.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: ed67b044e394847aaaf5e65e043c218c 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Packages/com.github.asus4.tflite.common/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "com.github.asus4.tflite.common", 3 | "displayName": "TensorFlow Lite Common", 4 | "author": "Koki Ibukuro", 5 | "description": "TensorFlow Lite Common Scripts for Unity", 6 | "keywords": [ 7 | "unity" 8 | ], 9 | "license": "SEE LICENSE IN LICENSE", 10 | "unity": "2019.3", 11 | "unityRelease": "0f1", 12 | "version": "2.4.1", 13 | "type": "library", 14 | "hideInEditor": false, 15 | "dependencies": { 16 | "com.github.asus4.tflite": "2.4.1" 17 | } 18 | } -------------------------------------------------------------------------------- /Packages/com.github.asus4.tflite.common/package.json.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 4a2581a5b6f814718ada50eebf85142b 3 | PackageManifestImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /Packages/com.github.asus4.tflite/Plugins.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 9c0ef37e2101b454298d5215987d7a5f 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Packages/com.github.asus4.tflite/Plugins/Android.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: cb799821b2df14575ad95e1ca054ebfc 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Packages/com.github.asus4.tflite/Plugins/Android/libnnapi_delegate.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alibros/blazepose-unity/cadb1e0da1004eca287e7910e6488bee6e8c7e76/Packages/com.github.asus4.tflite/Plugins/Android/libnnapi_delegate.so -------------------------------------------------------------------------------- /Packages/com.github.asus4.tflite/Plugins/Android/libnnapi_delegate.so.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 5255845a9090c4eb89e887f3e4a4f16b 3 | PluginImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | iconMap: {} 7 | executionOrder: {} 8 | defineConstraints: [] 9 | isPreloaded: 0 10 | isOverridable: 1 11 | isExplicitlyReferenced: 0 12 | validateReferences: 1 13 | platformData: 14 | - first: 15 | Any: 16 | second: 17 | enabled: 1 18 | settings: {} 19 | - first: 20 | Editor: Editor 21 | second: 22 | enabled: 0 23 | settings: 24 | DefaultValueInitialized: true 25 | userData: 26 | assetBundleName: 27 | assetBundleVariant: 28 | -------------------------------------------------------------------------------- /Packages/com.github.asus4.tflite/Plugins/Android/libtensorflowlite_c.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alibros/blazepose-unity/cadb1e0da1004eca287e7910e6488bee6e8c7e76/Packages/com.github.asus4.tflite/Plugins/Android/libtensorflowlite_c.so -------------------------------------------------------------------------------- /Packages/com.github.asus4.tflite/Plugins/Android/libtensorflowlite_c.so.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: d1092be49b69746b0be2b93c31e6626d 3 | PluginImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | iconMap: {} 7 | executionOrder: {} 8 | defineConstraints: [] 9 | isPreloaded: 0 10 | isOverridable: 1 11 | isExplicitlyReferenced: 0 12 | validateReferences: 1 13 | platformData: 14 | - first: 15 | : Any 16 | second: 17 | enabled: 0 18 | settings: 19 | Exclude Android: 0 20 | Exclude Editor: 0 21 | Exclude Linux64: 0 22 | Exclude OSXUniversal: 0 23 | Exclude WebGL: 0 24 | Exclude Win: 0 25 | Exclude Win64: 0 26 | - first: 27 | Android: Android 28 | second: 29 | enabled: 1 30 | settings: 31 | CPU: ARM64 32 | - first: 33 | Any: 34 | second: 35 | enabled: 1 36 | settings: {} 37 | - first: 38 | Editor: Editor 39 | second: 40 | enabled: 1 41 | settings: 42 | CPU: AnyCPU 43 | DefaultValueInitialized: true 44 | OS: AnyOS 45 | - first: 46 | Standalone: Linux64 47 | second: 48 | enabled: 1 49 | settings: 50 | CPU: x86_64 51 | - first: 52 | Standalone: OSXUniversal 53 | second: 54 | enabled: 1 55 | settings: 56 | CPU: x86_64 57 | - first: 58 | Standalone: Win 59 | second: 60 | enabled: 1 61 | settings: 62 | CPU: x86 63 | - first: 64 | Standalone: Win64 65 | second: 66 | enabled: 1 67 | settings: 68 | CPU: x86_64 69 | - first: 70 | WebGL: WebGL 71 | second: 72 | enabled: 1 73 | settings: {} 74 | userData: 75 | assetBundleName: 76 | assetBundleVariant: 77 | -------------------------------------------------------------------------------- /Packages/com.github.asus4.tflite/Plugins/Android/libtensorflowlite_gpu_delegate.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alibros/blazepose-unity/cadb1e0da1004eca287e7910e6488bee6e8c7e76/Packages/com.github.asus4.tflite/Plugins/Android/libtensorflowlite_gpu_delegate.so -------------------------------------------------------------------------------- /Packages/com.github.asus4.tflite/Plugins/Android/libtensorflowlite_gpu_delegate.so.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 499af344f0ce14ca0abe9fe563917e08 3 | PluginImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | iconMap: {} 7 | executionOrder: {} 8 | defineConstraints: [] 9 | isPreloaded: 0 10 | isOverridable: 1 11 | isExplicitlyReferenced: 0 12 | validateReferences: 1 13 | platformData: 14 | - first: 15 | : Any 16 | second: 17 | enabled: 0 18 | settings: 19 | Exclude Android: 0 20 | Exclude Editor: 0 21 | Exclude Linux64: 0 22 | Exclude OSXUniversal: 0 23 | Exclude WebGL: 0 24 | Exclude Win: 0 25 | Exclude Win64: 0 26 | - first: 27 | Android: Android 28 | second: 29 | enabled: 1 30 | settings: 31 | CPU: ARM64 32 | - first: 33 | Any: 34 | second: 35 | enabled: 1 36 | settings: {} 37 | - first: 38 | Editor: Editor 39 | second: 40 | enabled: 1 41 | settings: 42 | CPU: AnyCPU 43 | DefaultValueInitialized: true 44 | OS: AnyOS 45 | - first: 46 | Standalone: Linux64 47 | second: 48 | enabled: 1 49 | settings: 50 | CPU: x86_64 51 | - first: 52 | Standalone: OSXUniversal 53 | second: 54 | enabled: 1 55 | settings: 56 | CPU: x86_64 57 | - first: 58 | Standalone: Win 59 | second: 60 | enabled: 1 61 | settings: 62 | CPU: x86 63 | - first: 64 | Standalone: Win64 65 | second: 66 | enabled: 1 67 | settings: 68 | CPU: x86_64 69 | - first: 70 | WebGL: WebGL 71 | second: 72 | enabled: 1 73 | settings: {} 74 | userData: 75 | assetBundleName: 76 | assetBundleVariant: 77 | -------------------------------------------------------------------------------- /Packages/com.github.asus4.tflite/Plugins/Linux.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 70028bfb58c94998e8631fdbf6bc61bb 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Packages/com.github.asus4.tflite/Plugins/Linux/libtensorflowlite_c.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alibros/blazepose-unity/cadb1e0da1004eca287e7910e6488bee6e8c7e76/Packages/com.github.asus4.tflite/Plugins/Linux/libtensorflowlite_c.so -------------------------------------------------------------------------------- /Packages/com.github.asus4.tflite/Plugins/Linux/libtensorflowlite_c.so.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 4b20a3949f2a27a1f8a0034791386a3d 3 | PluginImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | iconMap: {} 7 | executionOrder: {} 8 | defineConstraints: [] 9 | isPreloaded: 0 10 | isOverridable: 1 11 | isExplicitlyReferenced: 0 12 | validateReferences: 1 13 | platformData: 14 | - first: 15 | Any: 16 | second: 17 | enabled: 1 18 | settings: {} 19 | - first: 20 | Editor: Editor 21 | second: 22 | enabled: 0 23 | settings: 24 | DefaultValueInitialized: true 25 | userData: 26 | assetBundleName: 27 | assetBundleVariant: 28 | -------------------------------------------------------------------------------- /Packages/com.github.asus4.tflite/Plugins/Windows.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 221088f02baa2e44c83975a1c67226d6 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Packages/com.github.asus4.tflite/Plugins/Windows/libtensorflowlite_c.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alibros/blazepose-unity/cadb1e0da1004eca287e7910e6488bee6e8c7e76/Packages/com.github.asus4.tflite/Plugins/Windows/libtensorflowlite_c.dll -------------------------------------------------------------------------------- /Packages/com.github.asus4.tflite/Plugins/Windows/libtensorflowlite_c.dll.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: cb735ff8fcb19e34dbb932872ac58172 3 | PluginImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | iconMap: {} 7 | executionOrder: {} 8 | defineConstraints: [] 9 | isPreloaded: 0 10 | isOverridable: 1 11 | isExplicitlyReferenced: 0 12 | validateReferences: 1 13 | platformData: 14 | - first: 15 | Any: 16 | second: 17 | enabled: 1 18 | settings: {} 19 | - first: 20 | Editor: Editor 21 | second: 22 | enabled: 0 23 | settings: 24 | DefaultValueInitialized: true 25 | userData: 26 | assetBundleName: 27 | assetBundleVariant: 28 | -------------------------------------------------------------------------------- /Packages/com.github.asus4.tflite/Plugins/iOS.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: c3f9979df38a34fce9b52da0de80ea28 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Packages/com.github.asus4.tflite/Plugins/iOS/TensorFlowLiteC.framework.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: ca8cd5d76c5f94e6da79dc0139de8db5 3 | folderAsset: yes 4 | PluginImporter: 5 | externalObjects: {} 6 | serializedVersion: 2 7 | iconMap: {} 8 | executionOrder: {} 9 | defineConstraints: [] 10 | isPreloaded: 0 11 | isOverridable: 1 12 | isExplicitlyReferenced: 0 13 | validateReferences: 1 14 | platformData: 15 | - first: 16 | Any: 17 | second: 18 | enabled: 1 19 | settings: {} 20 | - first: 21 | Editor: Editor 22 | second: 23 | enabled: 0 24 | settings: 25 | DefaultValueInitialized: true 26 | userData: 27 | assetBundleName: 28 | assetBundleVariant: 29 | -------------------------------------------------------------------------------- /Packages/com.github.asus4.tflite/Plugins/iOS/TensorFlowLiteC.framework/Headers.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 797e43a7e646e46ae8c40663517ac0a9 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Packages/com.github.asus4.tflite/Plugins/iOS/TensorFlowLiteC.framework/Headers/TensorFlowLiteC.h: -------------------------------------------------------------------------------- 1 | #import "c_api.h" 2 | #import "c_api_experimental.h" 3 | #import "common.h" 4 | #import "xnnpack_delegate.h" 5 | #import "c_api_types.h" 6 | -------------------------------------------------------------------------------- /Packages/com.github.asus4.tflite/Plugins/iOS/TensorFlowLiteC.framework/Headers/TensorFlowLiteC.h.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: d9786f9fd3d0d44b6ac5790f5c150351 3 | DefaultImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /Packages/com.github.asus4.tflite/Plugins/iOS/TensorFlowLiteC.framework/Headers/c_api.h.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b5c21cc59b7de4d7eacfac8acd248613 3 | DefaultImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /Packages/com.github.asus4.tflite/Plugins/iOS/TensorFlowLiteC.framework/Headers/c_api_experimental.h.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 382f41c15de63466faf175c5e7632597 3 | DefaultImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /Packages/com.github.asus4.tflite/Plugins/iOS/TensorFlowLiteC.framework/Headers/c_api_types.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2020 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | // This file declares types used by the pure C inference API defined in c_api.h, 17 | // some of which are also used in the C++ and C kernel and interpreter APIs. 18 | 19 | #ifndef TENSORFLOW_LITE_C_C_API_TYPES_H_ 20 | #define TENSORFLOW_LITE_C_C_API_TYPES_H_ 21 | 22 | #include 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | // Define TFL_CAPI_EXPORT macro to export a function properly with a shared 29 | // library. 30 | #ifdef SWIG 31 | #define TFL_CAPI_EXPORT 32 | #else 33 | #if defined(_WIN32) 34 | #ifdef TFL_COMPILE_LIBRARY 35 | #define TFL_CAPI_EXPORT __declspec(dllexport) 36 | #else 37 | #define TFL_CAPI_EXPORT __declspec(dllimport) 38 | #endif // TFL_COMPILE_LIBRARY 39 | #else 40 | #define TFL_CAPI_EXPORT __attribute__((visibility("default"))) 41 | #endif // _WIN32 42 | #endif // SWIG 43 | 44 | typedef enum TfLiteStatus { 45 | kTfLiteOk = 0, 46 | 47 | // Generally referring to an error in the runtime (i.e. interpreter) 48 | kTfLiteError = 1, 49 | 50 | // Generally referring to an error from a TfLiteDelegate itself. 51 | kTfLiteDelegateError = 2, 52 | 53 | // Generally referring to an error in applying a delegate due to 54 | // incompatibility between runtime and delegate, e.g., this error is returned 55 | // when trying to apply a TfLite delegate onto a model graph that's already 56 | // immutable. 57 | kTfLiteApplicationError = 3 58 | } TfLiteStatus; 59 | 60 | // Types supported by tensor 61 | typedef enum { 62 | kTfLiteNoType = 0, 63 | kTfLiteFloat32 = 1, 64 | kTfLiteInt32 = 2, 65 | kTfLiteUInt8 = 3, 66 | kTfLiteInt64 = 4, 67 | kTfLiteString = 5, 68 | kTfLiteBool = 6, 69 | kTfLiteInt16 = 7, 70 | kTfLiteComplex64 = 8, 71 | kTfLiteInt8 = 9, 72 | kTfLiteFloat16 = 10, 73 | kTfLiteFloat64 = 11, 74 | kTfLiteComplex128 = 12, 75 | kTfLiteUInt64 = 13, 76 | kTfLiteResource = 14, 77 | kTfLiteVariant = 15, 78 | kTfLiteUInt32 = 16, 79 | } TfLiteType; 80 | 81 | // Legacy. Will be deprecated in favor of TfLiteAffineQuantization. 82 | // If per-layer quantization is specified this field will still be populated in 83 | // addition to TfLiteAffineQuantization. 84 | // Parameters for asymmetric quantization. Quantized values can be converted 85 | // back to float using: 86 | // real_value = scale * (quantized_value - zero_point) 87 | typedef struct TfLiteQuantizationParams { 88 | float scale; 89 | int32_t zero_point; 90 | } TfLiteQuantizationParams; 91 | 92 | #ifdef __cplusplus 93 | } // extern C 94 | #endif 95 | #endif // TENSORFLOW_LITE_C_C_API_TYPES_H_ 96 | -------------------------------------------------------------------------------- /Packages/com.github.asus4.tflite/Plugins/iOS/TensorFlowLiteC.framework/Headers/c_api_types.h.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 204f9528aa1224c3d8925b37685c5101 3 | DefaultImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /Packages/com.github.asus4.tflite/Plugins/iOS/TensorFlowLiteC.framework/Headers/common.h.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 0575134812c0d4ce19c0c970805ffb26 3 | DefaultImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /Packages/com.github.asus4.tflite/Plugins/iOS/TensorFlowLiteC.framework/Headers/metal_delegate.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2019 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | #ifndef TENSORFLOW_LITE_DELEGATES_GPU_METAL_DELEGATE_H_ 17 | #define TENSORFLOW_LITE_DELEGATES_GPU_METAL_DELEGATE_H_ 18 | 19 | #ifdef SWIG 20 | #define TFL_CAPI_EXPORT 21 | #else 22 | #if defined(_WIN32) 23 | #ifdef TFL_COMPILE_LIBRARY 24 | #define TFL_CAPI_EXPORT __declspec(dllexport) 25 | #else 26 | #define TFL_CAPI_EXPORT __declspec(dllimport) 27 | #endif // TFL_COMPILE_LIBRARY 28 | #else 29 | #define TFL_CAPI_EXPORT __attribute__((visibility("default"))) 30 | #endif // _WIN32 31 | #endif // SWIG 32 | 33 | #ifdef __cplusplus 34 | extern "C" { 35 | #else 36 | // For "C" 'bool' is not built-in type. 37 | #include 38 | #endif // __cplusplus 39 | 40 | typedef struct TfLiteDelegate TfLiteDelegate; 41 | 42 | typedef enum { 43 | // waitUntilCompleted 44 | TFLGpuDelegateWaitTypePassive, 45 | // Minimize latency. It uses active spinning instead of mutex and consumes 46 | // additional CPU resources. 47 | TFLGpuDelegateWaitTypeActive, 48 | // Useful when the output is used with GPU pipeline then or if external 49 | // command encoder is set. 50 | TFLGpuDelegateWaitTypeDoNotWait, 51 | // Tries to avoid GPU sleep mode. 52 | TFLGpuDelegateWaitTypeAggressive, 53 | } TFLGpuDelegateWaitType; 54 | 55 | // Creates a new delegate instance that need to be destroyed with 56 | // DeleteFlowDelegate when delegate is no longer used by tflite. 57 | typedef struct { 58 | // Allows to quantify tensors, downcast values, process in float16 etc. 59 | bool allow_precision_loss; 60 | TFLGpuDelegateWaitType wait_type; 61 | } TFLGpuDelegateOptions; 62 | 63 | // Creates a new delegate instance that need to be destroyed with 64 | // `TFLDeleteTfLiteGpuDelegate` when delegate is no longer used by TFLite. 65 | // When `options` is set to `nullptr`, the following default values are used: 66 | // .precision_loss_allowed = false, 67 | // .wait_type = kPassive, 68 | TFL_CAPI_EXPORT extern TfLiteDelegate* TFLGpuDelegateCreate( 69 | const TFLGpuDelegateOptions* options); 70 | 71 | // Destroys a delegate created with `TFLGpuDelegateCreate` call. 72 | TFL_CAPI_EXPORT extern void TFLGpuDelegateDelete(TfLiteDelegate* delegate); 73 | 74 | #ifdef __cplusplus 75 | } // extern "C" 76 | #endif // __cplusplus 77 | 78 | #endif // TENSORFLOW_LITE_DELEGATES_GPU_METAL_DELEGATE_H_ 79 | -------------------------------------------------------------------------------- /Packages/com.github.asus4.tflite/Plugins/iOS/TensorFlowLiteC.framework/Headers/metal_delegate.h.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b95695ea35ebb49038ba662a2f167fc2 3 | DefaultImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /Packages/com.github.asus4.tflite/Plugins/iOS/TensorFlowLiteC.framework/Headers/xnnpack_delegate.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2020 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | #ifndef TENSORFLOW_LITE_DELEGATES_XNNPACK_XNNPACK_DELEGATE_H_ 17 | #define TENSORFLOW_LITE_DELEGATES_XNNPACK_XNNPACK_DELEGATE_H_ 18 | 19 | #include "common.h" 20 | 21 | #ifdef __cplusplus 22 | extern "C" { 23 | #endif // __cplusplus 24 | 25 | typedef struct { 26 | // Number of threads to use in the thread pool. 27 | // 0 or negative value means no thread pool used. 28 | int32_t num_threads; 29 | } TfLiteXNNPackDelegateOptions; 30 | 31 | // Returns a structure with the default XNNPack delegate options. 32 | TfLiteXNNPackDelegateOptions TfLiteXNNPackDelegateOptionsDefault(); 33 | 34 | // Creates a new delegate instance that need to be destroyed with 35 | // `TfLiteXNNPackDelegateDelete` when delegate is no longer used by TFLite. 36 | // When `options` is set to `nullptr`, the following default values are used: 37 | TfLiteDelegate* TfLiteXNNPackDelegateCreate( 38 | const TfLiteXNNPackDelegateOptions* options); 39 | 40 | // Returns the pthreadpool_t object used for parallelization in XNNPACK. 41 | // Can return NULL if the XNNPack delegate is single-threaded. 42 | // 43 | // WARNING: This API is experimental and subject to change. 44 | void* TfLiteXNNPackDelegateGetThreadPool(TfLiteDelegate* delegate); 45 | 46 | // Destroys a delegate created with `TfLiteXNNPackDelegateCreate` call. 47 | void TfLiteXNNPackDelegateDelete(TfLiteDelegate* delegate); 48 | 49 | #ifdef __cplusplus 50 | } 51 | #endif // __cplusplus 52 | 53 | #endif // TENSORFLOW_LITE_DELEGATES_XNNPACK_XNNPACK_DELEGATE_H_ 54 | -------------------------------------------------------------------------------- /Packages/com.github.asus4.tflite/Plugins/iOS/TensorFlowLiteC.framework/Headers/xnnpack_delegate.h.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 08edf0390cbfa416b9cefdcb3c1cbfbe 3 | DefaultImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /Packages/com.github.asus4.tflite/Plugins/iOS/TensorFlowLiteC.framework/Modules.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: ffe974cd5b67447da8cd308861ae9f7b 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Packages/com.github.asus4.tflite/Plugins/iOS/TensorFlowLiteC.framework/Modules/module.modulemap: -------------------------------------------------------------------------------- 1 | framework module TensorFlowLiteC { 2 | umbrella header "TensorFlowLiteC.h" 3 | export * 4 | module * { export * } 5 | } 6 | -------------------------------------------------------------------------------- /Packages/com.github.asus4.tflite/Plugins/iOS/TensorFlowLiteC.framework/Modules/module.modulemap.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: d2d071fd46ed84b2899542899c6b8438 3 | DefaultImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /Packages/com.github.asus4.tflite/Plugins/iOS/TensorFlowLiteC.framework/TensorFlowLiteC: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alibros/blazepose-unity/cadb1e0da1004eca287e7910e6488bee6e8c7e76/Packages/com.github.asus4.tflite/Plugins/iOS/TensorFlowLiteC.framework/TensorFlowLiteC -------------------------------------------------------------------------------- /Packages/com.github.asus4.tflite/Plugins/iOS/TensorFlowLiteC.framework/TensorFlowLiteC.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: f1aab5b967bcb4ae9ae11bf42c162e55 3 | DefaultImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /Packages/com.github.asus4.tflite/Plugins/iOS/TensorFlowLiteCMetal.framework.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 466c272a40c93479ebdbfd0676ff0b9c 3 | folderAsset: yes 4 | PluginImporter: 5 | externalObjects: {} 6 | serializedVersion: 2 7 | iconMap: {} 8 | executionOrder: {} 9 | defineConstraints: [] 10 | isPreloaded: 0 11 | isOverridable: 1 12 | isExplicitlyReferenced: 0 13 | validateReferences: 1 14 | platformData: 15 | - first: 16 | Any: 17 | second: 18 | enabled: 1 19 | settings: {} 20 | - first: 21 | Editor: Editor 22 | second: 23 | enabled: 0 24 | settings: 25 | DefaultValueInitialized: true 26 | userData: 27 | assetBundleName: 28 | assetBundleVariant: 29 | -------------------------------------------------------------------------------- /Packages/com.github.asus4.tflite/Plugins/iOS/TensorFlowLiteCMetal.framework/Headers.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 0118a916be3774a8c954d26f3a019eb6 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Packages/com.github.asus4.tflite/Plugins/iOS/TensorFlowLiteCMetal.framework/Headers/TensorFlowLiteCMetal.h: -------------------------------------------------------------------------------- 1 | #import "metal_delegate.h" 2 | -------------------------------------------------------------------------------- /Packages/com.github.asus4.tflite/Plugins/iOS/TensorFlowLiteCMetal.framework/Headers/TensorFlowLiteCMetal.h.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 97ea20c24985c46f980e8f4760503709 3 | DefaultImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /Packages/com.github.asus4.tflite/Plugins/iOS/TensorFlowLiteCMetal.framework/Headers/metal_delegate.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2019 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | #ifndef TENSORFLOW_LITE_DELEGATES_GPU_METAL_DELEGATE_H_ 17 | #define TENSORFLOW_LITE_DELEGATES_GPU_METAL_DELEGATE_H_ 18 | 19 | #include "TensorFlowLiteC/common.h" 20 | #import 21 | 22 | #ifdef __cplusplus 23 | extern "C" { 24 | #else 25 | // For "C" 'bool' is not built-in type. 26 | #include 27 | #endif // __cplusplus 28 | 29 | typedef struct TfLiteDelegate TfLiteDelegate; 30 | 31 | typedef enum { 32 | // waitUntilCompleted 33 | TFLGpuDelegateWaitTypePassive, 34 | // Minimize latency. It uses active spinning instead of mutex and consumes 35 | // additional CPU resources. 36 | TFLGpuDelegateWaitTypeActive, 37 | // Useful when the output is used with GPU pipeline then or if external 38 | // command encoder is set. 39 | TFLGpuDelegateWaitTypeDoNotWait, 40 | // Tries to avoid GPU sleep mode. 41 | TFLGpuDelegateWaitTypeAggressive, 42 | } TFLGpuDelegateWaitType; 43 | 44 | // Creates a new delegate instance that need to be destroyed with 45 | // DeleteFlowDelegate when delegate is no longer used by tflite. 46 | typedef struct { 47 | // Allows to quantify tensors, downcast values, process in float16 etc. 48 | bool allow_precision_loss; 49 | TFLGpuDelegateWaitType wait_type; 50 | // Allows execution of integer quantized models 51 | bool enable_quantization; 52 | } TFLGpuDelegateOptions; 53 | 54 | // Populates TFLGpuDelegateOptions as follows: 55 | // allow_precision_loss = false; 56 | // wait_type = TFLGpuDelegateWaitType::TFLGpuDelegateWaitTypePassive; 57 | // enable_quantization = true; 58 | TFL_CAPI_EXPORT extern TFLGpuDelegateOptions TFLGpuDelegateOptionsDefault(void); 59 | 60 | // Creates a new delegate instance that need to be destroyed with 61 | // `TFLDeleteTfLiteGpuDelegate` when delegate is no longer used by TFLite. 62 | // When `options` is set to `nullptr`, the following default values are used: 63 | // .precision_loss_allowed = false, 64 | // .wait_type = kPassive, 65 | TFL_CAPI_EXPORT extern TfLiteDelegate* TFLGpuDelegateCreate( 66 | const TFLGpuDelegateOptions* options); 67 | 68 | // Destroys a delegate created with `TFLGpuDelegateCreate` call. 69 | TFL_CAPI_EXPORT extern void TFLGpuDelegateDelete(TfLiteDelegate* delegate); 70 | 71 | // Binds Metal buffer to an input or an output tensor in the initialized 72 | // delegate. Bound buffer should have sufficient storage to accommodate all 73 | // elements of a tensor. For quantized model, the buffer is bound to internal 74 | // dequantized float32 tensor. 75 | // Returns non-zero on success, or zero otherwise. 76 | // 77 | // *** Must be called *after* `Interpreter::ModifyGraphWithDelegate`. *** 78 | TFL_CAPI_EXPORT extern bool TFLGpuDelegateBindMetalBufferToTensor(TfLiteDelegate* delegate, 79 | int tensor_index, 80 | id metal_buffer); 81 | 82 | #ifdef __cplusplus 83 | } // extern "C" 84 | #endif // __cplusplus 85 | 86 | #endif // TENSORFLOW_LITE_DELEGATES_GPU_METAL_DELEGATE_H_ 87 | -------------------------------------------------------------------------------- /Packages/com.github.asus4.tflite/Plugins/iOS/TensorFlowLiteCMetal.framework/Headers/metal_delegate.h.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: a1478b626bb0e4456a32b44ffd1dd99b 3 | DefaultImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /Packages/com.github.asus4.tflite/Plugins/iOS/TensorFlowLiteCMetal.framework/Modules.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 22768ff622b1244418a4bb9a30a56638 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Packages/com.github.asus4.tflite/Plugins/iOS/TensorFlowLiteCMetal.framework/Modules/module.modulemap: -------------------------------------------------------------------------------- 1 | framework module TensorFlowLiteCMetal { 2 | umbrella header "TensorFlowLiteCMetal.h" 3 | export * 4 | module * { export * } 5 | link framework "Metal" 6 | } 7 | -------------------------------------------------------------------------------- /Packages/com.github.asus4.tflite/Plugins/iOS/TensorFlowLiteCMetal.framework/Modules/module.modulemap.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: c8048e9c88616428797a277d6dc8e68e 3 | DefaultImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /Packages/com.github.asus4.tflite/Plugins/iOS/TensorFlowLiteCMetal.framework/TensorFlowLiteCMetal: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alibros/blazepose-unity/cadb1e0da1004eca287e7910e6488bee6e8c7e76/Packages/com.github.asus4.tflite/Plugins/iOS/TensorFlowLiteCMetal.framework/TensorFlowLiteCMetal -------------------------------------------------------------------------------- /Packages/com.github.asus4.tflite/Plugins/iOS/TensorFlowLiteCMetal.framework/TensorFlowLiteCMetal.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: e2c05cfde74214591a191f617dec6a08 3 | DefaultImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /Packages/com.github.asus4.tflite/Plugins/macOS.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 6d3e91b6120b646b1803b547a765c33a 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Packages/com.github.asus4.tflite/Plugins/macOS/libtensorflowlite_c.dylib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alibros/blazepose-unity/cadb1e0da1004eca287e7910e6488bee6e8c7e76/Packages/com.github.asus4.tflite/Plugins/macOS/libtensorflowlite_c.dylib -------------------------------------------------------------------------------- /Packages/com.github.asus4.tflite/Plugins/macOS/libtensorflowlite_c.dylib.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 442d9457e46e740e9a62275c2b1ead75 3 | PluginImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | iconMap: {} 7 | executionOrder: {} 8 | defineConstraints: [] 9 | isPreloaded: 0 10 | isOverridable: 1 11 | isExplicitlyReferenced: 0 12 | validateReferences: 1 13 | platformData: 14 | - first: 15 | Any: 16 | second: 17 | enabled: 0 18 | settings: {} 19 | - first: 20 | Editor: Editor 21 | second: 22 | enabled: 1 23 | settings: 24 | DefaultValueInitialized: true 25 | - first: 26 | Standalone: OSXUniversal 27 | second: 28 | enabled: 1 29 | settings: {} 30 | userData: 31 | assetBundleName: 32 | assetBundleVariant: 33 | -------------------------------------------------------------------------------- /Packages/com.github.asus4.tflite/Plugins/macOS/libtensorflowlite_metal_delegate.dylib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alibros/blazepose-unity/cadb1e0da1004eca287e7910e6488bee6e8c7e76/Packages/com.github.asus4.tflite/Plugins/macOS/libtensorflowlite_metal_delegate.dylib -------------------------------------------------------------------------------- /Packages/com.github.asus4.tflite/Plugins/macOS/libtensorflowlite_metal_delegate.dylib.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 4ad24ac515db142ba8d25bc2983eb04f 3 | PluginImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | iconMap: {} 7 | executionOrder: {} 8 | defineConstraints: [] 9 | isPreloaded: 0 10 | isOverridable: 1 11 | isExplicitlyReferenced: 0 12 | validateReferences: 1 13 | platformData: 14 | - first: 15 | Any: 16 | second: 17 | enabled: 0 18 | settings: {} 19 | - first: 20 | Editor: Editor 21 | second: 22 | enabled: 1 23 | settings: 24 | DefaultValueInitialized: true 25 | - first: 26 | Standalone: OSXUniversal 27 | second: 28 | enabled: 1 29 | settings: {} 30 | userData: 31 | assetBundleName: 32 | assetBundleVariant: 33 | -------------------------------------------------------------------------------- /Packages/com.github.asus4.tflite/Plugins/tflite_unity_helper.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | 5 | extern "C" { 6 | 7 | const char* UnityTFLiteStringFormat(const char *format, va_list argsOriginal) { 8 | char buffer[512]; 9 | va_list args; 10 | va_copy(args, argsOriginal); 11 | int length = vsprintf(buffer, format, args); 12 | va_end(args); 13 | 14 | // copy string 15 | char* msg = (char*)malloc(length + 1); 16 | strcpy(msg, buffer); 17 | // msg is dalloced in Unity 18 | return msg; 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /Packages/com.github.asus4.tflite/Plugins/tflite_unity_helper.cpp.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b57ba724a24b946eb92394be4ed3a8aa 3 | PluginImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | iconMap: {} 7 | executionOrder: {} 8 | defineConstraints: [] 9 | isPreloaded: 0 10 | isOverridable: 1 11 | isExplicitlyReferenced: 0 12 | validateReferences: 1 13 | platformData: 14 | - first: 15 | Any: 16 | second: 17 | enabled: 1 18 | settings: {} 19 | - first: 20 | Editor: Editor 21 | second: 22 | enabled: 0 23 | settings: 24 | DefaultValueInitialized: true 25 | userData: 26 | assetBundleName: 27 | assetBundleVariant: 28 | -------------------------------------------------------------------------------- /Packages/com.github.asus4.tflite/Runtime.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: e42ddb0c6f64040cfb9f2ba7cc062960 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Packages/com.github.asus4.tflite/Runtime/BuiltinOps.cs: -------------------------------------------------------------------------------- 1 | /* Copyright 2018 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | namespace TensorFlowLite 17 | { 18 | /// 19 | /// tensorflow/lite/builtin_ops.h 20 | /// 21 | public enum BuiltinOperator 22 | { 23 | Add = 0, 24 | AveragePool2d = 1, 25 | Concatenation = 2, 26 | Conv2d = 3, 27 | DepthwiseConv2d = 4, 28 | DepthToSpace = 5, 29 | Dequantize = 6, 30 | EmbeddingLookup = 7, 31 | Floor = 8, 32 | FullyConnected = 9, 33 | HashtableLookup = 10, 34 | L2Normalization = 11, 35 | L2Pool2d = 12, 36 | LocalResponseNormalization = 13, 37 | Logistic = 14, 38 | LshProjection = 15, 39 | Lstm = 16, 40 | MaxPool2d = 17, 41 | Mul = 18, 42 | Relu = 19, 43 | ReluN1To1 = 20, 44 | Relu6 = 21, 45 | Reshape = 22, 46 | ResizeBilinear = 23, 47 | Rnn = 24, 48 | Softmax = 25, 49 | SpaceToDepth = 26, 50 | Svdf = 27, 51 | Tanh = 28, 52 | ConcatEmbeddings = 29, 53 | SkipGram = 30, 54 | Call = 31, 55 | Custom = 32, 56 | EmbeddingLookupSparse = 33, 57 | Pad = 34, 58 | UnidirectionalSequenceRnn = 35, 59 | Gather = 36, 60 | BatchToSpaceNd = 37, 61 | SpaceToBatchNd = 38, 62 | Transpose = 39, 63 | Mean = 40, 64 | Sub = 41, 65 | Div = 42, 66 | Squeeze = 43, 67 | UnidirectionalSequenceLstm = 44, 68 | StridedSlice = 45, 69 | BidirectionalSequenceRnn = 46, 70 | Exp = 47, 71 | TopkV2 = 48, 72 | Split = 49, 73 | LogSoftmax = 50, 74 | Delegate = 51, 75 | BidirectionalSequenceLstm = 52, 76 | Cast = 53, 77 | Prelu = 54, 78 | Maximum = 55, 79 | ArgMax = 56, 80 | Minimum = 57, 81 | Less = 58, 82 | Neg = 59, 83 | Padv2 = 60, 84 | Greater = 61, 85 | GreaterEqual = 62, 86 | LessEqual = 63, 87 | Select = 64, 88 | Slice = 65, 89 | Sin = 66, 90 | TransposeConv = 67, 91 | SparseToDense = 68, 92 | Tile = 69, 93 | ExpandDims = 70, 94 | Equal = 71, 95 | NotEqual = 72, 96 | Log = 73, 97 | Sum = 74, 98 | Sqrt = 75, 99 | Rsqrt = 76, 100 | Shape = 77, 101 | Pow = 78, 102 | ArgMin = 79, 103 | FakeQuant = 80, 104 | ReduceProd = 81, 105 | ReduceMax = 82, 106 | Pack = 83, 107 | LogicalOr = 84, 108 | OneHot = 85, 109 | LogicalAnd = 86, 110 | LogicalNot = 87, 111 | Unpack = 88, 112 | ReduceMin = 89, 113 | FloorDiv = 90, 114 | ReduceAny = 91, 115 | Square = 92, 116 | ZerosLike = 93, 117 | Fill = 94, 118 | FloorMod = 95, 119 | Range = 96, 120 | ResizeNearestNeighbor = 97, 121 | LeakyRelu = 98, 122 | SquaredDifference = 99, 123 | MirrorPad = 100, 124 | Abs = 101, 125 | SplitV = 102, 126 | Unique = 103, 127 | Ceil = 104, 128 | ReverseV2 = 105, 129 | AddN = 106, 130 | GatherNd = 107, 131 | Cos = 108, 132 | Where = 109, 133 | Rank = 110, 134 | Elu = 111, 135 | ReverseSequence = 112, 136 | MatrixDiag = 113, 137 | Quantize = 114, 138 | MatrixSetDiag = 115, 139 | Round = 116, 140 | HardSwish = 117, 141 | If = 118, 142 | While = 119, 143 | NonMaxSuppressionV4 = 120, 144 | NonMaxSuppressionV5 = 121, 145 | ScatterNd = 122, 146 | SelectV2 = 123, 147 | Densify = 124, 148 | SegmentSum = 125, 149 | BatchMatmul = 126, 150 | } 151 | } 152 | -------------------------------------------------------------------------------- /Packages/com.github.asus4.tflite/Runtime/BuiltinOps.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 7d63ad5869d2745ec95fa0c5a83007cd 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Packages/com.github.asus4.tflite/Runtime/ErrorReporter.cs: -------------------------------------------------------------------------------- 1 | /* Copyright 2018 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | using System; 17 | using System.Runtime.InteropServices; 18 | using Debug = UnityEngine.Debug; 19 | using TfLiteInterpreterOptions = System.IntPtr; 20 | 21 | namespace TensorFlowLite 22 | { 23 | internal static class ErrorReporter 24 | { 25 | // void (*reporter)(void* user_data, const char* format, va_list args), 26 | [UnmanagedFunctionPointer(CallingConvention.Cdecl, SetLastError = true)] 27 | private delegate void ErrorReporterDelegate(IntPtr userData, string format, IntPtr argsPtrs); 28 | 29 | internal static void ConfigureReporter(TfLiteInterpreterOptions options) 30 | { 31 | TfLiteInterpreterOptionsSetErrorReporter(options, OnErrorReporter, IntPtr.Zero); 32 | } 33 | 34 | [AOT.MonoPInvokeCallback(typeof(ErrorReporterDelegate))] 35 | private static void OnErrorReporter(IntPtr userData, string format, IntPtr vaList) 36 | { 37 | // Marshalling va_list as args. 38 | // refs: 39 | // https://github.com/dotnet/runtime/issues/9316 40 | // https://github.com/jeremyVignelles/va-list-interop-demo 41 | 42 | string report; 43 | #if UNITY_EDITOR_OSX || UNITY_STANDALONE_OSX 44 | int formatLength = printf(format, vaList); 45 | IntPtr buffer = Marshal.AllocHGlobal(formatLength); 46 | sprintf(buffer, format, vaList); 47 | report = Marshal.PtrToStringAnsi(buffer); 48 | Marshal.FreeHGlobal(buffer); 49 | #elif UNITY_ANDROID && !UNITY_EDITOR 50 | report = UnityTFLiteStringFormat(format, vaList); 51 | #else 52 | // TODO: Support arglist for other platforms 53 | report = format; 54 | #endif 55 | // Debug.LogWarning($"raw format: {format}"); 56 | Debug.LogWarning($"TFLite Warning: {report}"); 57 | } 58 | 59 | #region Externs 60 | 61 | private const string TensorFlowLibrary = Interpreter.TensorFlowLibrary; 62 | 63 | [DllImport(TensorFlowLibrary, CallingConvention = CallingConvention.Cdecl)] 64 | private static extern void TfLiteInterpreterOptionsSetErrorReporter( 65 | TfLiteInterpreterOptions options, 66 | ErrorReporterDelegate errorReporter, 67 | IntPtr user_data); 68 | 69 | #if UNITY_EDITOR_OSX || UNITY_STANDALONE_OSX 70 | private const string LibCLibrary = "libc"; 71 | 72 | [DllImport(LibCLibrary, CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)] 73 | private extern static int printf( 74 | [In][MarshalAs(UnmanagedType.LPStr)] string format, 75 | IntPtr args); 76 | 77 | [DllImport(LibCLibrary, CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)] 78 | private extern static int sprintf( 79 | IntPtr buffer, 80 | [In][MarshalAs(UnmanagedType.LPStr)] string format, 81 | IntPtr args); 82 | #endif // UNITY_EDITOR_OSX || UNITY_STANDALONE_OSX 83 | 84 | #if UNITY_ANDROID && !UNITY_EDITOR 85 | private const string HelperLibrary = "__Internal"; 86 | 87 | [DllImport(HelperLibrary, CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)] 88 | private extern static string UnityTFLiteStringFormat(string format, IntPtr vaList); 89 | #endif 90 | 91 | #endregion // Externs 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /Packages/com.github.asus4.tflite/Runtime/ErrorReporter.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 2131ffc20c4b74ee9985afea9070a31f 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Packages/com.github.asus4.tflite/Runtime/GlDelegate.cs: -------------------------------------------------------------------------------- 1 | /* Copyright 2018 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | 17 | #if UNITY_ANDROID && !UNITY_EDITOR 18 | 19 | using System.Runtime.InteropServices; 20 | using UnityEngine; 21 | using TfLiteDelegate = System.IntPtr; 22 | 23 | namespace TensorFlowLite 24 | { 25 | public class GlDelegate : IBindableDelegate 26 | { 27 | public enum ObjectType 28 | { 29 | FASTEST = 0, 30 | TEXTURE = 1, 31 | BUFFER = 2, 32 | } 33 | 34 | /// 35 | /// The Mirror of TfLiteGlCompileOptions 36 | /// 37 | [StructLayout(LayoutKind.Sequential)] 38 | public struct CompileOptions 39 | { 40 | public int precisionLossAllowed; 41 | public int preferredGlObjectType; 42 | public int dynamicBatchEnabled; 43 | public int inlineParameters; 44 | } 45 | 46 | /// 47 | /// The Mirror of TfLiteGpuDelegateOptions 48 | /// 49 | [StructLayout(LayoutKind.Sequential)] 50 | public struct Options 51 | { 52 | unsafe byte* metadata; 53 | public CompileOptions compileOptions; 54 | }; 55 | 56 | public TfLiteDelegate Delegate { get; private set; } 57 | 58 | public static Options DefaultOptions => TfLiteGpuDelegateOptionsDefault(); 59 | 60 | public GlDelegate(Options options) 61 | { 62 | Delegate = TfLiteGpuDelegateCreate(ref options); 63 | } 64 | 65 | public GlDelegate() 66 | { 67 | Options options = DefaultOptions; 68 | Delegate = TfLiteGpuDelegateCreate(ref options); 69 | } 70 | 71 | public void Dispose() 72 | { 73 | TfLiteGpuDelegateDelete(Delegate); 74 | Delegate = TfLiteDelegate.Zero; 75 | } 76 | 77 | public bool BindBufferToInputTensor(Interpreter interpreter, int index, ComputeBuffer buffer) 78 | { 79 | int tensorIndex = interpreter.GetInputTensorIndex(index); 80 | return BindBufferToTensor(tensorIndex, buffer); 81 | } 82 | 83 | public bool BindBufferToOutputTensor(Interpreter interpreter, int index, ComputeBuffer buffer) 84 | { 85 | int tensorIndex = interpreter.GetOutputTensorIndex(index); 86 | return BindBufferToTensor(tensorIndex, buffer); 87 | } 88 | 89 | private bool BindBufferToTensor(int tensorIndex, ComputeBuffer buffer) 90 | { 91 | Debug.Assert(buffer.IsValid()); 92 | Debug.Assert(Delegate != TfLiteDelegate.Zero); 93 | uint bufferID = (uint)buffer.GetNativeBufferPtr().ToInt32(); 94 | var status = TfLiteGpuDelegateBindBufferToTensor(Delegate, bufferID, tensorIndex); 95 | return status == Interpreter.Status.Ok; 96 | } 97 | 98 | #region Externs 99 | private const string TensorFlowLibraryGPU = "libtensorflowlite_gpu_gl"; 100 | 101 | [DllImport(TensorFlowLibraryGPU)] 102 | private static extern unsafe Options TfLiteGpuDelegateOptionsDefault(); 103 | 104 | [DllImport(TensorFlowLibraryGPU)] 105 | private static extern unsafe TfLiteDelegate TfLiteGpuDelegateCreate(ref Options options); 106 | 107 | [DllImport(TensorFlowLibraryGPU)] 108 | private static extern unsafe void TfLiteGpuDelegateDelete(TfLiteDelegate gpuDelegate); 109 | 110 | [DllImport(TensorFlowLibraryGPU)] 111 | private static extern unsafe Interpreter.Status TfLiteGpuDelegateBindBufferToTensor( 112 | TfLiteDelegate gpuDelegate, uint buffer, int tensorIndex); 113 | #endregion // Externs 114 | } 115 | } 116 | #endif // UNITY_ANDROID && !UNITY_EDITOR 117 | 118 | -------------------------------------------------------------------------------- /Packages/com.github.asus4.tflite/Runtime/GlDelegate.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 197fff13586b34b5084e8b31a62a5b30 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Packages/com.github.asus4.tflite/Runtime/GpuDelegateV2.cs: -------------------------------------------------------------------------------- 1 | /* Copyright 2018 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | #if UNITY_ANDROID && !UNITY_EDITOR 17 | 18 | using System.Runtime.InteropServices; 19 | using UnityEngine; 20 | using TfLiteDelegate = System.IntPtr; 21 | 22 | namespace TensorFlowLite 23 | { 24 | public class GpuDelegateV2 : IBindableDelegate 25 | { 26 | 27 | /// 28 | /// TfLiteGpuInferenceUsage 29 | /// Encapsulated compilation/runtime tradeoffs. 30 | /// 31 | public enum Usage 32 | { 33 | // Delegate will be used only once, therefore, bootstrap/init time should 34 | // be taken into account. 35 | FastSingleAnswer = 0, 36 | 37 | // Prefer maximizing the throughput. Same delegate will be used repeatedly on 38 | // multiple inputs. 39 | SustainedSpeed = 1, 40 | } 41 | 42 | /// 43 | /// TfLiteGpuInferencePriority 44 | /// 45 | public enum InferencePriority 46 | { 47 | Auto = 0, 48 | MaxPrecision = 1, 49 | MinLatency = 2, 50 | MinMemoryUsage = 3, 51 | } 52 | 53 | /// 54 | /// TfLiteGpuExperimentalFlags 55 | /// 56 | [System.Flags] 57 | public enum ExperimentalFlags 58 | { 59 | None = 0, 60 | // Enables inference on quantized models with the delegate. 61 | // NOTE: This is enabled in TfLiteGpuDelegateOptionsV2Default. 62 | EnableQuant = 1 << 0, 63 | // Enforces execution with the provided backend. 64 | ClOnly = 1 << 1, 65 | GlOnly = 1 << 2 66 | } 67 | 68 | /// 69 | /// the Mirror of TfLiteGpuDelegateOptionsV2 70 | /// 71 | [StructLayout(LayoutKind.Sequential)] 72 | public struct Options 73 | { 74 | public int isPrecisionLossAllowed; 75 | public int inferencePreference; 76 | public int inferencePriority1; 77 | public int inferencePriority2; 78 | public int inferencePriority3; 79 | public long experimentalFlags; 80 | public int maxDelegatedPartitions; 81 | }; 82 | 83 | public TfLiteDelegate Delegate { get; private set; } 84 | 85 | public static Options DefaultOptions => TfLiteGpuDelegateOptionsV2Default(); 86 | 87 | public GpuDelegateV2() 88 | { 89 | Options options = DefaultOptions; 90 | Delegate = TfLiteGpuDelegateV2Create(ref options); 91 | } 92 | 93 | public GpuDelegateV2(Options options) 94 | { 95 | Delegate = TfLiteGpuDelegateV2Create(ref options); 96 | } 97 | 98 | public void Dispose() 99 | { 100 | TfLiteGpuDelegateV2Delete(Delegate); 101 | Delegate = TfLiteDelegate.Zero; 102 | } 103 | 104 | public bool BindBufferToInputTensor(Interpreter interpreter, int index, ComputeBuffer buffer) 105 | { 106 | uint bufferID = (uint)buffer.GetNativeBufferPtr().ToInt32(); 107 | var status = TfLiteGpuDelegateV2BindInputBuffer(Delegate, index, bufferID); 108 | return status == Interpreter.Status.Ok; 109 | } 110 | 111 | public bool BindBufferToOutputTensor(Interpreter interpreter, int index, ComputeBuffer buffer) 112 | { 113 | uint bufferID = (uint)buffer.GetNativeBufferPtr().ToInt32(); 114 | var status = TfLiteGpuDelegateV2BindOutputBuffer(Delegate, index, bufferID); 115 | return status == Interpreter.Status.Ok; 116 | } 117 | 118 | #region Externs 119 | private const string TensorFlowLibraryGPU = "libtensorflowlite_gpu_delegate"; 120 | 121 | [DllImport(TensorFlowLibraryGPU)] 122 | private static extern unsafe Options TfLiteGpuDelegateOptionsV2Default(); 123 | 124 | [DllImport(TensorFlowLibraryGPU)] 125 | private static extern unsafe TfLiteDelegate TfLiteGpuDelegateV2Create(ref Options options); 126 | 127 | [DllImport(TensorFlowLibraryGPU)] 128 | private static extern unsafe void TfLiteGpuDelegateV2Delete(TfLiteDelegate gpuDelegate); 129 | 130 | [DllImport(TensorFlowLibraryGPU)] 131 | private static extern unsafe Interpreter.Status TfLiteGpuDelegateBindBufferToTensor( 132 | TfLiteDelegate gpuDelegate, uint buffer, int tensor_index); 133 | 134 | [DllImport(TensorFlowLibraryGPU)] 135 | private static extern unsafe Interpreter.Status TfLiteGpuDelegateV2BindInputBuffer( 136 | TfLiteDelegate gpuDelegatee, int index, uint buffer); 137 | 138 | [DllImport(TensorFlowLibraryGPU)] 139 | private static extern unsafe Interpreter.Status TfLiteGpuDelegateV2BindOutputBuffer( 140 | TfLiteDelegate gpuDelegate, int index, uint buffer); 141 | 142 | #endregion // Externs 143 | } 144 | } 145 | #endif // UNITY_ANDROID && !UNITY_EDITOR 146 | 147 | -------------------------------------------------------------------------------- /Packages/com.github.asus4.tflite/Runtime/GpuDelegateV2.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 3c8d4ab074827471481250ca2f13cf24 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Packages/com.github.asus4.tflite/Runtime/IGpuDelegate.cs: -------------------------------------------------------------------------------- 1 | /* Copyright 2018 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | using System; 17 | using UnityEngine; 18 | using TfLiteDelegate = System.IntPtr; 19 | 20 | namespace TensorFlowLite 21 | { 22 | public interface IGpuDelegate : IDisposable 23 | { 24 | TfLiteDelegate Delegate { get; } 25 | } 26 | 27 | public interface IBindableDelegate : IGpuDelegate 28 | { 29 | bool BindBufferToInputTensor(Interpreter interpreter, int index, ComputeBuffer buffer); 30 | bool BindBufferToOutputTensor(Interpreter interpreter, int index, ComputeBuffer buffer); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Packages/com.github.asus4.tflite/Runtime/IGpuDelegate.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 2fcda07d0d4c6450ea8fea752db057ef 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Packages/com.github.asus4.tflite/Runtime/Interpreter.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 0bbaf59e6ac914ed1b28174fb9008a09 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Packages/com.github.asus4.tflite/Runtime/InterpreterExperimental.cs: -------------------------------------------------------------------------------- 1 | /* Copyright 2018 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | using System; 16 | using System.Runtime.InteropServices; 17 | using Status = TensorFlowLite.Interpreter.Status; 18 | using TfLiteContext = System.IntPtr; 19 | using TfLiteDelegate = System.IntPtr; 20 | using TfLiteInterpreter = System.IntPtr; 21 | using TfLiteInterpreterOptions = System.IntPtr; 22 | using TfLiteModel = System.IntPtr; 23 | using TfLiteNode = System.IntPtr; 24 | using TfLiteRegistration = System.IntPtr; 25 | using TfLiteTensor = System.IntPtr; 26 | 27 | namespace TensorFlowLite 28 | { 29 | [StructLayout(LayoutKind.Sequential)] 30 | public struct Registration 31 | { 32 | [UnmanagedFunctionPointer(CallingConvention.Cdecl)] 33 | public delegate void InitDelegate(TfLiteContext context, IntPtr buffer, UInt64 length); 34 | [UnmanagedFunctionPointer(CallingConvention.Cdecl)] 35 | public delegate void FreeDelegate(TfLiteContext context, IntPtr buffer); 36 | [UnmanagedFunctionPointer(CallingConvention.Cdecl)] 37 | public delegate Interpreter.Status PrepareDelegate(TfLiteContext context, TfLiteNode node); 38 | [UnmanagedFunctionPointer(CallingConvention.Cdecl)] 39 | public delegate Interpreter.Status InvokeDelegate(TfLiteContext context, TfLiteNode node); 40 | [UnmanagedFunctionPointer(CallingConvention.Cdecl)] 41 | public delegate string ProfilingStringDelegate(TfLiteContext context, TfLiteNode node); 42 | 43 | public InitDelegate initDelegate; 44 | public FreeDelegate freeDelegate; 45 | public PrepareDelegate prepareDelegate; 46 | public InvokeDelegate invokeDelegate; 47 | public ProfilingStringDelegate profilingStringDelegate; 48 | public Int32 builtinCode; 49 | public string customName; 50 | public int version; 51 | } 52 | 53 | /// 54 | /// The bridge for c_api_experimental.h 55 | /// 56 | public static class InterpreterExperimental 57 | { 58 | public static void AddCustomOp(this Interpreter interpreter, string name, Registration registration) 59 | { 60 | throw new System.NotImplementedException(); 61 | // TfLiteInterpreterOptionsAddCustomOp(interpreter, "HOGE"); 62 | } 63 | 64 | public static void SetAllowBufferHandleOutput(this Interpreter interpreter, bool allowBufferHandleOutput) 65 | { 66 | TfLiteSetAllowBufferHandleOutput(interpreter.InterpreterPointer, allowBufferHandleOutput); 67 | } 68 | 69 | public static Status ModifyGraphWithDelegate(this Interpreter interpreter, IGpuDelegate gpuDelegate) 70 | { 71 | return TfLiteInterpreterModifyGraphWithDelegate(interpreter.InterpreterPointer, gpuDelegate.Delegate); 72 | } 73 | 74 | public static int GetInputTensorIndex(this Interpreter interpreter, int index) 75 | { 76 | return TfLiteInterpreterGetInputTensorIndex(interpreter.InterpreterPointer, index); 77 | } 78 | 79 | public static int GetOutputTensorIndex(this Interpreter interpreter, int index) 80 | { 81 | return TfLiteInterpreterGetOutputTensorIndex(interpreter.InterpreterPointer, index); 82 | } 83 | 84 | private const string TensorFlowLibrary = Interpreter.TensorFlowLibrary; 85 | 86 | [DllImport(TensorFlowLibrary)] 87 | private static extern Interpreter.Status TfLiteInterpreterResetVariableTensors(TfLiteInterpreter interpreter); 88 | 89 | [DllImport(TensorFlowLibrary)] 90 | private static extern void TfLiteInterpreterOptionsAddBuiltinOp( 91 | TfLiteInterpreterOptions options, 92 | BuiltinOperator op, 93 | TfLiteRegistration registration, 94 | UInt32 min_version, UInt32 max_version); 95 | 96 | [DllImport(TensorFlowLibrary)] 97 | private static extern void TfLiteInterpreterOptionsAddCustomOp( 98 | TfLiteInterpreterOptions options, 99 | string name, 100 | TfLiteRegistration registration, 101 | UInt32 min_version, UInt32 max_version); 102 | 103 | [DllImport(TensorFlowLibrary)] 104 | internal static extern void TfLiteInterpreterOptionsSetUseNNAPI(TfLiteInterpreterOptions options, bool enable); 105 | 106 | [DllImport(TensorFlowLibrary)] 107 | internal static extern void TfLiteSetAllowBufferHandleOutput( 108 | TfLiteInterpreter interpreter, 109 | bool allow_buffer_handle_output); 110 | 111 | [DllImport(TensorFlowLibrary)] 112 | internal static extern Status TfLiteInterpreterModifyGraphWithDelegate( 113 | TfLiteInterpreter interpreter, TfLiteDelegate gpuDelegate); 114 | 115 | [DllImport(TensorFlowLibrary)] 116 | internal static extern int TfLiteInterpreterGetInputTensorIndex( 117 | TfLiteInterpreter interpreter, int input_index); 118 | 119 | [DllImport(TensorFlowLibrary)] 120 | internal static extern int TfLiteInterpreterGetOutputTensorIndex( 121 | TfLiteInterpreter interpreter, int output_index); 122 | } 123 | } 124 | -------------------------------------------------------------------------------- /Packages/com.github.asus4.tflite/Runtime/InterpreterExperimental.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 138e6769d7f524a289d001ce703b19de 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Packages/com.github.asus4.tflite/Runtime/InterpreterOptions.cs: -------------------------------------------------------------------------------- 1 | /* Copyright 2018 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | using System; 17 | using System.Collections.Generic; 18 | using System.Runtime.InteropServices; 19 | using TfLiteDelegate = System.IntPtr; 20 | using TfLiteInterpreterOptions = System.IntPtr; 21 | 22 | namespace TensorFlowLite 23 | { 24 | public class InterpreterOptions : IDisposable 25 | { 26 | // void (*reporter)(void* user_data, const char* format, va_list args), 27 | [UnmanagedFunctionPointer(CallingConvention.Cdecl, SetLastError = true)] 28 | private delegate void ErrorReporterDelegate(IntPtr userData, string format, IntPtr argsPtrs); 29 | 30 | internal TfLiteInterpreterOptions nativePtr; 31 | 32 | private List delegates; 33 | 34 | private int _threads; 35 | public int threads 36 | { 37 | get => _threads; 38 | set 39 | { 40 | _threads = value; 41 | TfLiteInterpreterOptionsSetNumThreads(nativePtr, value); 42 | } 43 | } 44 | 45 | private bool _useNNAPI; 46 | public bool useNNAPI 47 | { 48 | get => _useNNAPI; 49 | set 50 | { 51 | _useNNAPI = value; 52 | #if UNITY_ANDROID && !UNITY_EDITOR 53 | InterpreterExperimental.TfLiteInterpreterOptionsSetUseNNAPI(nativePtr, value); 54 | #endif // UNITY_ANDROID && !UNITY_EDITOR 55 | } 56 | } 57 | 58 | public InterpreterOptions() 59 | { 60 | nativePtr = TfLiteInterpreterOptionsCreate(); 61 | delegates = new List(); 62 | 63 | ErrorReporter.ConfigureReporter(nativePtr); 64 | } 65 | 66 | public void Dispose() 67 | { 68 | if (nativePtr != IntPtr.Zero) 69 | { 70 | TfLiteInterpreterOptionsDelete(nativePtr); 71 | } 72 | foreach (var gpuDelegate in delegates) 73 | { 74 | gpuDelegate.Dispose(); 75 | } 76 | delegates.Clear(); 77 | } 78 | 79 | public void AddGpuDelegate(IGpuDelegate gpuDelegate) 80 | { 81 | if (gpuDelegate == null) return; 82 | TfLiteInterpreterOptionsAddDelegate(nativePtr, gpuDelegate.Delegate); 83 | delegates.Add(gpuDelegate); 84 | } 85 | 86 | public void AddGpuDelegate() 87 | { 88 | AddGpuDelegate(CreateGpuDelegate()); 89 | } 90 | 91 | #pragma warning disable CS0162 // Unreachable code detected 92 | private static IGpuDelegate CreateGpuDelegate() 93 | { 94 | #if UNITY_ANDROID && !UNITY_EDITOR 95 | return new GpuDelegateV2(); 96 | #elif UNITY_IOS || UNITY_EDITOR_OSX || UNITY_STANDALONE_OSX 97 | return new MetalDelegate(new MetalDelegate.Options() 98 | { 99 | allowPrecisionLoss = false, 100 | waitType = MetalDelegate.WaitType.Passive, 101 | enableQuantization = true, 102 | }); 103 | #endif 104 | UnityEngine.Debug.LogWarning("GPU Delegate is not supported on this platform"); 105 | return null; 106 | } 107 | #pragma warning restore CS0162 // Unreachable code detected 108 | 109 | 110 | #region Externs 111 | private const string TensorFlowLibrary = Interpreter.TensorFlowLibrary; 112 | 113 | [DllImport(TensorFlowLibrary)] 114 | private static extern unsafe TfLiteInterpreterOptions TfLiteInterpreterOptionsCreate(); 115 | 116 | [DllImport(TensorFlowLibrary)] 117 | private static extern unsafe void TfLiteInterpreterOptionsDelete(TfLiteInterpreterOptions options); 118 | 119 | [DllImport(TensorFlowLibrary)] 120 | private static extern unsafe void TfLiteInterpreterOptionsSetNumThreads( 121 | TfLiteInterpreterOptions options, 122 | int num_threads 123 | ); 124 | 125 | [DllImport(TensorFlowLibrary)] 126 | private static extern unsafe void TfLiteInterpreterOptionsAddDelegate( 127 | TfLiteInterpreterOptions options, 128 | TfLiteDelegate _delegate); 129 | 130 | #endregion // Externs 131 | } 132 | } 133 | -------------------------------------------------------------------------------- /Packages/com.github.asus4.tflite/Runtime/InterpreterOptions.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: d2467018592ac4923a438f162fcfa782 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Packages/com.github.asus4.tflite/Runtime/MetalDelegate.cs: -------------------------------------------------------------------------------- 1 | /* Copyright 2018 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | using System.Runtime.InteropServices; 17 | using UnityEngine; 18 | using Debug = UnityEngine.Debug; 19 | using MTLBuffer = System.IntPtr; 20 | using TfLiteDelegate = System.IntPtr; 21 | 22 | namespace TensorFlowLite 23 | { 24 | #if UNITY_IOS || UNITY_EDITOR_OSX || UNITY_STANDALONE_OSX 25 | /// 26 | /// Metal GPU Delegate 27 | /// Available on iOS or macOS 28 | /// 29 | public class MetalDelegate : IBindableDelegate 30 | { 31 | public enum WaitType 32 | { 33 | Passive = 0, 34 | Active = 1, 35 | DoNotWait = 2, 36 | Aggressive = 3, 37 | } 38 | 39 | [StructLayout(LayoutKind.Sequential)] 40 | public struct Options 41 | { 42 | public bool allowPrecisionLoss; 43 | public WaitType waitType; 44 | public bool enableQuantization; 45 | } 46 | 47 | public TfLiteDelegate Delegate { get; private set; } 48 | 49 | public MetalDelegate(Options options) 50 | { 51 | Delegate = TFLGpuDelegateCreate(ref options); 52 | } 53 | 54 | public void Dispose() 55 | { 56 | TFLGpuDelegateDelete(Delegate); 57 | Delegate = TfLiteDelegate.Zero; 58 | } 59 | 60 | public bool BindBufferToInputTensor(Interpreter interpreter, int index, ComputeBuffer buffer) 61 | { 62 | int tensorIndex = interpreter.GetInputTensorIndex(index); 63 | return BindBufferToTensor(tensorIndex, buffer); 64 | } 65 | 66 | public bool BindBufferToOutputTensor(Interpreter interpreter, int index, ComputeBuffer buffer) 67 | { 68 | int tensorIndex = interpreter.GetOutputTensorIndex(index); 69 | return BindBufferToTensor(tensorIndex, buffer); 70 | } 71 | 72 | private bool BindBufferToTensor(int tensorIndex, ComputeBuffer buffer) 73 | { 74 | Debug.Assert(buffer.IsValid()); 75 | Debug.Assert(Delegate != TfLiteDelegate.Zero); 76 | return TFLGpuDelegateBindMetalBufferToTensor(Delegate, tensorIndex, buffer.GetNativeBufferPtr()); 77 | } 78 | 79 | #region Externs 80 | 81 | #if UNITY_IOS && !UNITY_EDITOR 82 | private const string TensorFlowLibraryGPU = "__Internal"; 83 | #else 84 | private const string TensorFlowLibraryGPU = "libtensorflowlite_metal_delegate"; 85 | #endif // UNITY_IOS && !UNITY_EDITOR 86 | 87 | [DllImport(TensorFlowLibraryGPU)] 88 | private static extern unsafe TfLiteDelegate TFLGpuDelegateCreate(ref Options delegateOptions); 89 | 90 | [DllImport(TensorFlowLibraryGPU)] 91 | private static extern unsafe void TFLGpuDelegateDelete(TfLiteDelegate gpuDelegate); 92 | 93 | [DllImport(TensorFlowLibraryGPU)] 94 | private static extern bool TFLGpuDelegateBindMetalBufferToTensor(TfLiteDelegate gpuDelegate, int tensorIndex, MTLBuffer metalBuffer); 95 | #endregion 96 | } 97 | #endif // UNITY_IOS || UNITY_EDITOR_OSX || UNITY_STANDALONE_OSX 98 | } 99 | -------------------------------------------------------------------------------- /Packages/com.github.asus4.tflite/Runtime/MetalDelegate.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 2006aa2bc9228444eb5808de82c979e4 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Packages/com.github.asus4.tflite/Runtime/TensorFlowLite.asmdef: -------------------------------------------------------------------------------- 1 | { 2 | "name": "TensorFlowLite", 3 | "references": [ 4 | "GUID:d8b63aba1907145bea998dd612889d6b" 5 | ], 6 | "includePlatforms": [], 7 | "excludePlatforms": [], 8 | "allowUnsafeCode": true, 9 | "overrideReferences": false, 10 | "precompiledReferences": [], 11 | "autoReferenced": true, 12 | "defineConstraints": [], 13 | "versionDefines": [], 14 | "noEngineReferences": false 15 | } -------------------------------------------------------------------------------- /Packages/com.github.asus4.tflite/Runtime/TensorFlowLite.asmdef.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 6e1d47a1424c040aca79d8b6a2710888 3 | AssemblyDefinitionImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /Packages/com.github.asus4.tflite/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "com.github.asus4.tflite", 3 | "displayName": "TensorFlow Lite", 4 | "author": "Koki Ibukuro", 5 | "description": "TensorFlow Lite Plugin for Unity", 6 | "keywords": [ 7 | "unity" 8 | ], 9 | "license": "SEE LICENSE IN LICENSE", 10 | "unity": "2019.3", 11 | "unityRelease": "0f1", 12 | "version": "2.4.1", 13 | "type": "library", 14 | "hideInEditor": false 15 | } -------------------------------------------------------------------------------- /Packages/com.github.asus4.tflite/package.json.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: d4e054aead13541cb9ec6d9c099adce1 3 | PackageManifestImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /Packages/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "dependencies": { 3 | "com.cysharp.unitask": "https://github.com/Cysharp/UniTask.git?path=src/UniTask/Assets/Plugins/UniTask#2.2.5", 4 | "com.github.asus4.tflite": "2.4.0", 5 | "com.unity.2d.sprite": "1.0.0", 6 | "com.unity.ext.nunit": "1.0.6", 7 | "com.unity.ide.visualstudio": "2.0.11", 8 | "com.unity.ide.vscode": "1.2.3", 9 | "com.unity.mathematics": "1.2.1", 10 | "com.unity.test-framework": "1.1.27", 11 | "com.unity.toolchain.macos-x86_64-linux-x86_64": "0.1.21-preview", 12 | "com.unity.ugui": "1.0.0", 13 | "com.unity.modules.ai": "1.0.0", 14 | "com.unity.modules.androidjni": "1.0.0", 15 | "com.unity.modules.animation": "1.0.0", 16 | "com.unity.modules.assetbundle": "1.0.0", 17 | "com.unity.modules.audio": "1.0.0", 18 | "com.unity.modules.cloth": "1.0.0", 19 | "com.unity.modules.director": "1.0.0", 20 | "com.unity.modules.imageconversion": "1.0.0", 21 | "com.unity.modules.imgui": "1.0.0", 22 | "com.unity.modules.jsonserialize": "1.0.0", 23 | "com.unity.modules.particlesystem": "1.0.0", 24 | "com.unity.modules.physics": "1.0.0", 25 | "com.unity.modules.physics2d": "1.0.0", 26 | "com.unity.modules.screencapture": "1.0.0", 27 | "com.unity.modules.terrain": "1.0.0", 28 | "com.unity.modules.terrainphysics": "1.0.0", 29 | "com.unity.modules.tilemap": "1.0.0", 30 | "com.unity.modules.ui": "1.0.0", 31 | "com.unity.modules.uielements": "1.0.0", 32 | "com.unity.modules.umbra": "1.0.0", 33 | "com.unity.modules.unityanalytics": "1.0.0", 34 | "com.unity.modules.unitywebrequest": "1.0.0", 35 | "com.unity.modules.unitywebrequestassetbundle": "1.0.0", 36 | "com.unity.modules.unitywebrequestaudio": "1.0.0", 37 | "com.unity.modules.unitywebrequesttexture": "1.0.0", 38 | "com.unity.modules.unitywebrequestwww": "1.0.0", 39 | "com.unity.modules.vehicles": "1.0.0", 40 | "com.unity.modules.video": "1.0.0", 41 | "com.unity.modules.vr": "1.0.0", 42 | "com.unity.modules.wind": "1.0.0", 43 | "com.unity.modules.xr": "1.0.0" 44 | }, 45 | "scopedRegistries": [ 46 | { 47 | "name": "package.openupm.com", 48 | "url": "https://package.openupm.com", 49 | "scopes": [ 50 | "com.github.asus4.tflite", 51 | "com.openupm" 52 | ] 53 | }, 54 | { 55 | "name": "TFIte", 56 | "url": "https://github.com/asus4/tf-lite-unity-sample.git?path=/Packages/com.github.asus4.tflite", 57 | "scopes": [ 58 | "app" 59 | ] 60 | } 61 | ] 62 | } 63 | -------------------------------------------------------------------------------- /ProjectSettings/AudioManager.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!11 &1 4 | AudioManager: 5 | m_ObjectHideFlags: 0 6 | serializedVersion: 2 7 | m_Volume: 1 8 | Rolloff Scale: 1 9 | Doppler Factor: 1 10 | Default Speaker Mode: 2 11 | m_SampleRate: 0 12 | m_DSPBufferSize: 1024 13 | m_VirtualVoiceCount: 512 14 | m_RealVoiceCount: 32 15 | m_SpatializerPlugin: 16 | m_AmbisonicDecoderPlugin: 17 | m_DisableAudio: 0 18 | m_VirtualizeEffects: 1 19 | m_RequestedDSPBufferSize: 1024 20 | -------------------------------------------------------------------------------- /ProjectSettings/ClusterInputManager.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!236 &1 4 | ClusterInputManager: 5 | m_ObjectHideFlags: 0 6 | m_Inputs: [] 7 | -------------------------------------------------------------------------------- /ProjectSettings/DynamicsManager.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!55 &1 4 | PhysicsManager: 5 | m_ObjectHideFlags: 0 6 | serializedVersion: 11 7 | m_Gravity: {x: 0, y: -9.81, z: 0} 8 | m_DefaultMaterial: {fileID: 0} 9 | m_BounceThreshold: 2 10 | m_SleepThreshold: 0.005 11 | m_DefaultContactOffset: 0.01 12 | m_DefaultSolverIterations: 6 13 | m_DefaultSolverVelocityIterations: 1 14 | m_QueriesHitBackfaces: 0 15 | m_QueriesHitTriggers: 1 16 | m_EnableAdaptiveForce: 0 17 | m_ClothInterCollisionDistance: 0 18 | m_ClothInterCollisionStiffness: 0 19 | m_ContactsGeneration: 1 20 | m_LayerCollisionMatrix: ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff 21 | m_AutoSimulation: 1 22 | m_AutoSyncTransforms: 0 23 | m_ReuseCollisionCallbacks: 1 24 | m_ClothInterCollisionSettingsToggle: 0 25 | m_ContactPairsMode: 0 26 | m_BroadphaseType: 0 27 | m_WorldBounds: 28 | m_Center: {x: 0, y: 0, z: 0} 29 | m_Extent: {x: 250, y: 250, z: 250} 30 | m_WorldSubdivisions: 8 31 | m_FrictionType: 0 32 | m_EnableEnhancedDeterminism: 0 33 | m_EnableUnifiedHeightmaps: 1 34 | m_DefaultMaxAngluarSpeed: 7 35 | -------------------------------------------------------------------------------- /ProjectSettings/EditorBuildSettings.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!1045 &1 4 | EditorBuildSettings: 5 | m_ObjectHideFlags: 0 6 | serializedVersion: 2 7 | m_Scenes: 8 | - enabled: 0 9 | path: 10 | guid: 00000000000000000000000000000000 11 | - enabled: 0 12 | path: 13 | guid: 00000000000000000000000000000000 14 | - enabled: 0 15 | path: 16 | guid: 00000000000000000000000000000000 17 | - enabled: 0 18 | path: 19 | guid: 00000000000000000000000000000000 20 | - enabled: 0 21 | path: 22 | guid: 00000000000000000000000000000000 23 | - enabled: 0 24 | path: 25 | guid: 00000000000000000000000000000000 26 | - enabled: 0 27 | path: 28 | guid: 00000000000000000000000000000000 29 | - enabled: 1 30 | path: Assets/Scenes/BlazePose/BlazePose.unity 31 | guid: 3abf2ff7d3acd4eda8d5014c1830c433 32 | - enabled: 0 33 | path: 34 | guid: 00000000000000000000000000000000 35 | - enabled: 0 36 | path: 37 | guid: 00000000000000000000000000000000 38 | - enabled: 0 39 | path: 40 | guid: 00000000000000000000000000000000 41 | - enabled: 0 42 | path: 43 | guid: 00000000000000000000000000000000 44 | m_configObjects: {} 45 | -------------------------------------------------------------------------------- /ProjectSettings/EditorSettings.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!159 &1 4 | EditorSettings: 5 | m_ObjectHideFlags: 0 6 | serializedVersion: 9 7 | m_ExternalVersionControlSupport: Hidden Meta Files 8 | m_SerializationMode: 2 9 | m_LineEndingsForNewScripts: 2 10 | m_DefaultBehaviorMode: 0 11 | m_PrefabRegularEnvironment: {fileID: 0} 12 | m_PrefabUIEnvironment: {fileID: 0} 13 | m_SpritePackerMode: 0 14 | m_SpritePackerPaddingPower: 1 15 | m_EtcTextureCompressorBehavior: 1 16 | m_EtcTextureFastCompressor: 1 17 | m_EtcTextureNormalCompressor: 2 18 | m_EtcTextureBestCompressor: 4 19 | m_ProjectGenerationIncludedExtensions: txt;xml;fnt;cd;asmdef;rsp;asmref 20 | m_ProjectGenerationRootNamespace: 21 | m_CollabEditorSettings: 22 | inProgressEnabled: 1 23 | m_EnableTextureStreamingInEditMode: 1 24 | m_EnableTextureStreamingInPlayMode: 1 25 | m_AsyncShaderCompilation: 1 26 | m_EnterPlayModeOptionsEnabled: 1 27 | m_EnterPlayModeOptions: 3 28 | m_ShowLightmapResolutionOverlay: 1 29 | m_UseLegacyProbeSampleCount: 1 30 | m_AssetPipelineMode: 1 31 | m_CacheServerMode: 0 32 | m_CacheServerEndpoint: 33 | m_CacheServerNamespacePrefix: default 34 | m_CacheServerEnableDownload: 1 35 | m_CacheServerEnableUpload: 1 36 | -------------------------------------------------------------------------------- /ProjectSettings/GraphicsSettings.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!30 &1 4 | GraphicsSettings: 5 | m_ObjectHideFlags: 0 6 | serializedVersion: 13 7 | m_Deferred: 8 | m_Mode: 1 9 | m_Shader: {fileID: 69, guid: 0000000000000000f000000000000000, type: 0} 10 | m_DeferredReflections: 11 | m_Mode: 1 12 | m_Shader: {fileID: 74, guid: 0000000000000000f000000000000000, type: 0} 13 | m_ScreenSpaceShadows: 14 | m_Mode: 1 15 | m_Shader: {fileID: 64, guid: 0000000000000000f000000000000000, type: 0} 16 | m_LegacyDeferred: 17 | m_Mode: 1 18 | m_Shader: {fileID: 63, guid: 0000000000000000f000000000000000, type: 0} 19 | m_DepthNormals: 20 | m_Mode: 1 21 | m_Shader: {fileID: 62, guid: 0000000000000000f000000000000000, type: 0} 22 | m_MotionVectors: 23 | m_Mode: 1 24 | m_Shader: {fileID: 75, guid: 0000000000000000f000000000000000, type: 0} 25 | m_LightHalo: 26 | m_Mode: 1 27 | m_Shader: {fileID: 105, guid: 0000000000000000f000000000000000, type: 0} 28 | m_LensFlare: 29 | m_Mode: 1 30 | m_Shader: {fileID: 102, guid: 0000000000000000f000000000000000, type: 0} 31 | m_AlwaysIncludedShaders: 32 | - {fileID: 7, guid: 0000000000000000f000000000000000, type: 0} 33 | - {fileID: 15104, guid: 0000000000000000f000000000000000, type: 0} 34 | - {fileID: 15105, guid: 0000000000000000f000000000000000, type: 0} 35 | - {fileID: 15106, guid: 0000000000000000f000000000000000, type: 0} 36 | - {fileID: 10753, guid: 0000000000000000f000000000000000, type: 0} 37 | - {fileID: 10770, guid: 0000000000000000f000000000000000, type: 0} 38 | - {fileID: 16000, guid: 0000000000000000f000000000000000, type: 0} 39 | - {fileID: 16001, guid: 0000000000000000f000000000000000, type: 0} 40 | - {fileID: 17000, guid: 0000000000000000f000000000000000, type: 0} 41 | - {fileID: 16003, guid: 0000000000000000f000000000000000, type: 0} 42 | m_PreloadedShaders: [] 43 | m_SpritesDefaultMaterial: {fileID: 10754, guid: 0000000000000000f000000000000000, 44 | type: 0} 45 | m_CustomRenderPipeline: {fileID: 0} 46 | m_TransparencySortMode: 0 47 | m_TransparencySortAxis: {x: 0, y: 0, z: 1} 48 | m_DefaultRenderingPath: 1 49 | m_DefaultMobileRenderingPath: 1 50 | m_TierSettings: [] 51 | m_LightmapStripping: 0 52 | m_FogStripping: 0 53 | m_InstancingStripping: 0 54 | m_LightmapKeepPlain: 1 55 | m_LightmapKeepDirCombined: 1 56 | m_LightmapKeepDynamicPlain: 1 57 | m_LightmapKeepDynamicDirCombined: 1 58 | m_LightmapKeepShadowMask: 1 59 | m_LightmapKeepSubtractive: 1 60 | m_FogKeepLinear: 1 61 | m_FogKeepExp: 1 62 | m_FogKeepExp2: 1 63 | m_AlbedoSwatchInfos: [] 64 | m_LightsUseLinearIntensity: 0 65 | m_LightsUseColorTemperature: 0 66 | m_LogWhenShaderIsCompiled: 0 67 | m_AllowEnlightenSupportForUpgradedProject: 1 68 | -------------------------------------------------------------------------------- /ProjectSettings/InputManager.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!13 &1 4 | InputManager: 5 | m_ObjectHideFlags: 0 6 | serializedVersion: 2 7 | m_Axes: 8 | - serializedVersion: 3 9 | m_Name: Horizontal 10 | descriptiveName: 11 | descriptiveNegativeName: 12 | negativeButton: left 13 | positiveButton: right 14 | altNegativeButton: a 15 | altPositiveButton: d 16 | gravity: 3 17 | dead: 0.001 18 | sensitivity: 3 19 | snap: 1 20 | invert: 0 21 | type: 0 22 | axis: 0 23 | joyNum: 0 24 | - serializedVersion: 3 25 | m_Name: Vertical 26 | descriptiveName: 27 | descriptiveNegativeName: 28 | negativeButton: down 29 | positiveButton: up 30 | altNegativeButton: s 31 | altPositiveButton: w 32 | gravity: 3 33 | dead: 0.001 34 | sensitivity: 3 35 | snap: 1 36 | invert: 0 37 | type: 0 38 | axis: 0 39 | joyNum: 0 40 | - serializedVersion: 3 41 | m_Name: Fire1 42 | descriptiveName: 43 | descriptiveNegativeName: 44 | negativeButton: 45 | positiveButton: left ctrl 46 | altNegativeButton: 47 | altPositiveButton: mouse 0 48 | gravity: 1000 49 | dead: 0.001 50 | sensitivity: 1000 51 | snap: 0 52 | invert: 0 53 | type: 0 54 | axis: 0 55 | joyNum: 0 56 | - serializedVersion: 3 57 | m_Name: Fire2 58 | descriptiveName: 59 | descriptiveNegativeName: 60 | negativeButton: 61 | positiveButton: left alt 62 | altNegativeButton: 63 | altPositiveButton: mouse 1 64 | gravity: 1000 65 | dead: 0.001 66 | sensitivity: 1000 67 | snap: 0 68 | invert: 0 69 | type: 0 70 | axis: 0 71 | joyNum: 0 72 | - serializedVersion: 3 73 | m_Name: Fire3 74 | descriptiveName: 75 | descriptiveNegativeName: 76 | negativeButton: 77 | positiveButton: left shift 78 | altNegativeButton: 79 | altPositiveButton: mouse 2 80 | gravity: 1000 81 | dead: 0.001 82 | sensitivity: 1000 83 | snap: 0 84 | invert: 0 85 | type: 0 86 | axis: 0 87 | joyNum: 0 88 | - serializedVersion: 3 89 | m_Name: Jump 90 | descriptiveName: 91 | descriptiveNegativeName: 92 | negativeButton: 93 | positiveButton: space 94 | altNegativeButton: 95 | altPositiveButton: 96 | gravity: 1000 97 | dead: 0.001 98 | sensitivity: 1000 99 | snap: 0 100 | invert: 0 101 | type: 0 102 | axis: 0 103 | joyNum: 0 104 | - serializedVersion: 3 105 | m_Name: Mouse X 106 | descriptiveName: 107 | descriptiveNegativeName: 108 | negativeButton: 109 | positiveButton: 110 | altNegativeButton: 111 | altPositiveButton: 112 | gravity: 0 113 | dead: 0 114 | sensitivity: 0.1 115 | snap: 0 116 | invert: 0 117 | type: 1 118 | axis: 0 119 | joyNum: 0 120 | - serializedVersion: 3 121 | m_Name: Mouse Y 122 | descriptiveName: 123 | descriptiveNegativeName: 124 | negativeButton: 125 | positiveButton: 126 | altNegativeButton: 127 | altPositiveButton: 128 | gravity: 0 129 | dead: 0 130 | sensitivity: 0.1 131 | snap: 0 132 | invert: 0 133 | type: 1 134 | axis: 1 135 | joyNum: 0 136 | - serializedVersion: 3 137 | m_Name: Mouse ScrollWheel 138 | descriptiveName: 139 | descriptiveNegativeName: 140 | negativeButton: 141 | positiveButton: 142 | altNegativeButton: 143 | altPositiveButton: 144 | gravity: 0 145 | dead: 0 146 | sensitivity: 0.1 147 | snap: 0 148 | invert: 0 149 | type: 1 150 | axis: 2 151 | joyNum: 0 152 | - serializedVersion: 3 153 | m_Name: Horizontal 154 | descriptiveName: 155 | descriptiveNegativeName: 156 | negativeButton: 157 | positiveButton: 158 | altNegativeButton: 159 | altPositiveButton: 160 | gravity: 0 161 | dead: 0.19 162 | sensitivity: 1 163 | snap: 0 164 | invert: 0 165 | type: 2 166 | axis: 0 167 | joyNum: 0 168 | - serializedVersion: 3 169 | m_Name: Vertical 170 | descriptiveName: 171 | descriptiveNegativeName: 172 | negativeButton: 173 | positiveButton: 174 | altNegativeButton: 175 | altPositiveButton: 176 | gravity: 0 177 | dead: 0.19 178 | sensitivity: 1 179 | snap: 0 180 | invert: 1 181 | type: 2 182 | axis: 1 183 | joyNum: 0 184 | - serializedVersion: 3 185 | m_Name: Fire1 186 | descriptiveName: 187 | descriptiveNegativeName: 188 | negativeButton: 189 | positiveButton: joystick button 0 190 | altNegativeButton: 191 | altPositiveButton: 192 | gravity: 1000 193 | dead: 0.001 194 | sensitivity: 1000 195 | snap: 0 196 | invert: 0 197 | type: 0 198 | axis: 0 199 | joyNum: 0 200 | - serializedVersion: 3 201 | m_Name: Fire2 202 | descriptiveName: 203 | descriptiveNegativeName: 204 | negativeButton: 205 | positiveButton: joystick button 1 206 | altNegativeButton: 207 | altPositiveButton: 208 | gravity: 1000 209 | dead: 0.001 210 | sensitivity: 1000 211 | snap: 0 212 | invert: 0 213 | type: 0 214 | axis: 0 215 | joyNum: 0 216 | - serializedVersion: 3 217 | m_Name: Fire3 218 | descriptiveName: 219 | descriptiveNegativeName: 220 | negativeButton: 221 | positiveButton: joystick button 2 222 | altNegativeButton: 223 | altPositiveButton: 224 | gravity: 1000 225 | dead: 0.001 226 | sensitivity: 1000 227 | snap: 0 228 | invert: 0 229 | type: 0 230 | axis: 0 231 | joyNum: 0 232 | - serializedVersion: 3 233 | m_Name: Jump 234 | descriptiveName: 235 | descriptiveNegativeName: 236 | negativeButton: 237 | positiveButton: joystick button 3 238 | altNegativeButton: 239 | altPositiveButton: 240 | gravity: 1000 241 | dead: 0.001 242 | sensitivity: 1000 243 | snap: 0 244 | invert: 0 245 | type: 0 246 | axis: 0 247 | joyNum: 0 248 | - serializedVersion: 3 249 | m_Name: Submit 250 | descriptiveName: 251 | descriptiveNegativeName: 252 | negativeButton: 253 | positiveButton: return 254 | altNegativeButton: 255 | altPositiveButton: joystick button 0 256 | gravity: 1000 257 | dead: 0.001 258 | sensitivity: 1000 259 | snap: 0 260 | invert: 0 261 | type: 0 262 | axis: 0 263 | joyNum: 0 264 | - serializedVersion: 3 265 | m_Name: Submit 266 | descriptiveName: 267 | descriptiveNegativeName: 268 | negativeButton: 269 | positiveButton: enter 270 | altNegativeButton: 271 | altPositiveButton: space 272 | gravity: 1000 273 | dead: 0.001 274 | sensitivity: 1000 275 | snap: 0 276 | invert: 0 277 | type: 0 278 | axis: 0 279 | joyNum: 0 280 | - serializedVersion: 3 281 | m_Name: Cancel 282 | descriptiveName: 283 | descriptiveNegativeName: 284 | negativeButton: 285 | positiveButton: escape 286 | altNegativeButton: 287 | altPositiveButton: joystick button 1 288 | gravity: 1000 289 | dead: 0.001 290 | sensitivity: 1000 291 | snap: 0 292 | invert: 0 293 | type: 0 294 | axis: 0 295 | joyNum: 0 296 | -------------------------------------------------------------------------------- /ProjectSettings/NavMeshAreas.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!126 &1 4 | NavMeshProjectSettings: 5 | m_ObjectHideFlags: 0 6 | serializedVersion: 2 7 | areas: 8 | - name: Walkable 9 | cost: 1 10 | - name: Not Walkable 11 | cost: 1 12 | - name: Jump 13 | cost: 2 14 | - name: 15 | cost: 1 16 | - name: 17 | cost: 1 18 | - name: 19 | cost: 1 20 | - name: 21 | cost: 1 22 | - name: 23 | cost: 1 24 | - name: 25 | cost: 1 26 | - name: 27 | cost: 1 28 | - name: 29 | cost: 1 30 | - name: 31 | cost: 1 32 | - name: 33 | cost: 1 34 | - name: 35 | cost: 1 36 | - name: 37 | cost: 1 38 | - name: 39 | cost: 1 40 | - name: 41 | cost: 1 42 | - name: 43 | cost: 1 44 | - name: 45 | cost: 1 46 | - name: 47 | cost: 1 48 | - name: 49 | cost: 1 50 | - name: 51 | cost: 1 52 | - name: 53 | cost: 1 54 | - name: 55 | cost: 1 56 | - name: 57 | cost: 1 58 | - name: 59 | cost: 1 60 | - name: 61 | cost: 1 62 | - name: 63 | cost: 1 64 | - name: 65 | cost: 1 66 | - name: 67 | cost: 1 68 | - name: 69 | cost: 1 70 | - name: 71 | cost: 1 72 | m_LastAgentTypeID: -887442657 73 | m_Settings: 74 | - serializedVersion: 2 75 | agentTypeID: 0 76 | agentRadius: 0.5 77 | agentHeight: 2 78 | agentSlope: 45 79 | agentClimb: 0.75 80 | ledgeDropHeight: 0 81 | maxJumpAcrossDistance: 0 82 | minRegionArea: 2 83 | manualCellSize: 0 84 | cellSize: 0.16666667 85 | manualTileSize: 0 86 | tileSize: 256 87 | accuratePlacement: 0 88 | debug: 89 | m_Flags: 0 90 | m_SettingNames: 91 | - Humanoid 92 | -------------------------------------------------------------------------------- /ProjectSettings/PackageManagerSettings.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!114 &1 4 | MonoBehaviour: 5 | m_ObjectHideFlags: 61 6 | m_CorrespondingSourceObject: {fileID: 0} 7 | m_PrefabInstance: {fileID: 0} 8 | m_PrefabAsset: {fileID: 0} 9 | m_GameObject: {fileID: 0} 10 | m_Enabled: 1 11 | m_EditorHideFlags: 0 12 | m_Script: {fileID: 13964, guid: 0000000000000000e000000000000000, type: 0} 13 | m_Name: 14 | m_EditorClassIdentifier: 15 | m_ScopedRegistriesSettingsExpanded: 1 16 | oneTimeWarningShown: 0 17 | m_Registries: 18 | - m_Id: main 19 | m_Name: 20 | m_Url: https://packages.unity.com 21 | m_Scopes: [] 22 | m_IsDefault: 1 23 | - m_Id: scoped:package.openupm.com 24 | m_Name: package.openupm.com 25 | m_Url: https://package.openupm.com 26 | m_Scopes: 27 | - com.github.asus4.tflite 28 | - com.openupm 29 | m_IsDefault: 0 30 | - m_Id: scoped:TFIte 31 | m_Name: TFIte 32 | m_Url: https://github.com/asus4/tf-lite-unity-sample.git?path=/Packages/com.github.asus4.tflite 33 | m_Scopes: 34 | - app 35 | m_IsDefault: 0 36 | m_UserSelectedRegistryName: TFIte 37 | m_UserAddingNewScopedRegistry: 0 38 | m_RegistryInfoDraft: 39 | m_ErrorMessage: 40 | m_Original: 41 | m_Id: scoped:TFIte 42 | m_Name: TFIte 43 | m_Url: https://github.com/asus4/tf-lite-unity-sample.git?path=/Packages/com.github.asus4.tflite 44 | m_Scopes: 45 | - app 46 | m_IsDefault: 0 47 | m_Modified: 0 48 | m_Name: TFIte 49 | m_Url: https://github.com/asus4/tf-lite-unity-sample.git?path=/Packages/com.github.asus4.tflite 50 | m_Scopes: 51 | - app 52 | m_SelectedScopeIndex: 0 53 | -------------------------------------------------------------------------------- /ProjectSettings/Physics2DSettings.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!19 &1 4 | Physics2DSettings: 5 | m_ObjectHideFlags: 0 6 | serializedVersion: 4 7 | m_Gravity: {x: 0, y: -9.81} 8 | m_DefaultMaterial: {fileID: 0} 9 | m_VelocityIterations: 8 10 | m_PositionIterations: 3 11 | m_VelocityThreshold: 1 12 | m_MaxLinearCorrection: 0.2 13 | m_MaxAngularCorrection: 8 14 | m_MaxTranslationSpeed: 100 15 | m_MaxRotationSpeed: 360 16 | m_BaumgarteScale: 0.2 17 | m_BaumgarteTimeOfImpactScale: 0.75 18 | m_TimeToSleep: 0.5 19 | m_LinearSleepTolerance: 0.01 20 | m_AngularSleepTolerance: 2 21 | m_DefaultContactOffset: 0.01 22 | m_JobOptions: 23 | serializedVersion: 2 24 | useMultithreading: 0 25 | useConsistencySorting: 0 26 | m_InterpolationPosesPerJob: 100 27 | m_NewContactsPerJob: 30 28 | m_CollideContactsPerJob: 100 29 | m_ClearFlagsPerJob: 200 30 | m_ClearBodyForcesPerJob: 200 31 | m_SyncDiscreteFixturesPerJob: 50 32 | m_SyncContinuousFixturesPerJob: 50 33 | m_FindNearestContactsPerJob: 100 34 | m_UpdateTriggerContactsPerJob: 100 35 | m_IslandSolverCostThreshold: 100 36 | m_IslandSolverBodyCostScale: 1 37 | m_IslandSolverContactCostScale: 10 38 | m_IslandSolverJointCostScale: 10 39 | m_IslandSolverBodiesPerJob: 50 40 | m_IslandSolverContactsPerJob: 50 41 | m_AutoSimulation: 1 42 | m_QueriesHitTriggers: 1 43 | m_QueriesStartInColliders: 1 44 | m_CallbacksOnDisable: 1 45 | m_ReuseCollisionCallbacks: 1 46 | m_AutoSyncTransforms: 0 47 | m_AlwaysShowColliders: 0 48 | m_ShowColliderSleep: 1 49 | m_ShowColliderContacts: 0 50 | m_ShowColliderAABB: 0 51 | m_ContactArrowScale: 0.2 52 | m_ColliderAwakeColor: {r: 0.5686275, g: 0.95686275, b: 0.54509807, a: 0.7529412} 53 | m_ColliderAsleepColor: {r: 0.5686275, g: 0.95686275, b: 0.54509807, a: 0.36078432} 54 | m_ColliderContactColor: {r: 1, g: 0, b: 1, a: 0.6862745} 55 | m_ColliderAABBColor: {r: 1, g: 1, b: 0, a: 0.2509804} 56 | m_LayerCollisionMatrix: ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff 57 | -------------------------------------------------------------------------------- /ProjectSettings/PresetManager.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!1386491679 &1 4 | PresetManager: 5 | m_ObjectHideFlags: 0 6 | serializedVersion: 2 7 | m_DefaultPresets: {} 8 | -------------------------------------------------------------------------------- /ProjectSettings/ProjectVersion.txt: -------------------------------------------------------------------------------- 1 | m_EditorVersion: 2019.4.20f1 2 | m_EditorVersionWithRevision: 2019.4.20f1 (6dd1c08eedfa) 3 | -------------------------------------------------------------------------------- /ProjectSettings/QualitySettings.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!47 &1 4 | QualitySettings: 5 | m_ObjectHideFlags: 0 6 | serializedVersion: 5 7 | m_CurrentQuality: 5 8 | m_QualitySettings: 9 | - serializedVersion: 2 10 | name: Very Low 11 | pixelLightCount: 0 12 | shadows: 0 13 | shadowResolution: 0 14 | shadowProjection: 1 15 | shadowCascades: 1 16 | shadowDistance: 15 17 | shadowNearPlaneOffset: 3 18 | shadowCascade2Split: 0.33333334 19 | shadowCascade4Split: {x: 0.06666667, y: 0.2, z: 0.46666667} 20 | shadowmaskMode: 0 21 | blendWeights: 1 22 | textureQuality: 1 23 | anisotropicTextures: 0 24 | antiAliasing: 0 25 | softParticles: 0 26 | softVegetation: 0 27 | realtimeReflectionProbes: 0 28 | billboardsFaceCameraPosition: 0 29 | vSyncCount: 0 30 | lodBias: 0.3 31 | maximumLODLevel: 0 32 | streamingMipmapsActive: 0 33 | streamingMipmapsAddAllCameras: 1 34 | streamingMipmapsMemoryBudget: 512 35 | streamingMipmapsRenderersPerFrame: 512 36 | streamingMipmapsMaxLevelReduction: 2 37 | streamingMipmapsMaxFileIORequests: 1024 38 | particleRaycastBudget: 4 39 | asyncUploadTimeSlice: 2 40 | asyncUploadBufferSize: 16 41 | asyncUploadPersistentBuffer: 1 42 | resolutionScalingFixedDPIFactor: 1 43 | excludedTargetPlatforms: [] 44 | - serializedVersion: 2 45 | name: Low 46 | pixelLightCount: 0 47 | shadows: 0 48 | shadowResolution: 0 49 | shadowProjection: 1 50 | shadowCascades: 1 51 | shadowDistance: 20 52 | shadowNearPlaneOffset: 3 53 | shadowCascade2Split: 0.33333334 54 | shadowCascade4Split: {x: 0.06666667, y: 0.2, z: 0.46666667} 55 | shadowmaskMode: 0 56 | blendWeights: 2 57 | textureQuality: 0 58 | anisotropicTextures: 0 59 | antiAliasing: 0 60 | softParticles: 0 61 | softVegetation: 0 62 | realtimeReflectionProbes: 0 63 | billboardsFaceCameraPosition: 0 64 | vSyncCount: 0 65 | lodBias: 0.4 66 | maximumLODLevel: 0 67 | streamingMipmapsActive: 0 68 | streamingMipmapsAddAllCameras: 1 69 | streamingMipmapsMemoryBudget: 512 70 | streamingMipmapsRenderersPerFrame: 512 71 | streamingMipmapsMaxLevelReduction: 2 72 | streamingMipmapsMaxFileIORequests: 1024 73 | particleRaycastBudget: 16 74 | asyncUploadTimeSlice: 2 75 | asyncUploadBufferSize: 16 76 | asyncUploadPersistentBuffer: 1 77 | resolutionScalingFixedDPIFactor: 1 78 | excludedTargetPlatforms: [] 79 | - serializedVersion: 2 80 | name: Medium 81 | pixelLightCount: 1 82 | shadows: 1 83 | shadowResolution: 0 84 | shadowProjection: 1 85 | shadowCascades: 1 86 | shadowDistance: 20 87 | shadowNearPlaneOffset: 3 88 | shadowCascade2Split: 0.33333334 89 | shadowCascade4Split: {x: 0.06666667, y: 0.2, z: 0.46666667} 90 | shadowmaskMode: 0 91 | blendWeights: 2 92 | textureQuality: 0 93 | anisotropicTextures: 1 94 | antiAliasing: 0 95 | softParticles: 0 96 | softVegetation: 0 97 | realtimeReflectionProbes: 0 98 | billboardsFaceCameraPosition: 0 99 | vSyncCount: 1 100 | lodBias: 0.7 101 | maximumLODLevel: 0 102 | streamingMipmapsActive: 0 103 | streamingMipmapsAddAllCameras: 1 104 | streamingMipmapsMemoryBudget: 512 105 | streamingMipmapsRenderersPerFrame: 512 106 | streamingMipmapsMaxLevelReduction: 2 107 | streamingMipmapsMaxFileIORequests: 1024 108 | particleRaycastBudget: 64 109 | asyncUploadTimeSlice: 2 110 | asyncUploadBufferSize: 16 111 | asyncUploadPersistentBuffer: 1 112 | resolutionScalingFixedDPIFactor: 1 113 | excludedTargetPlatforms: [] 114 | - serializedVersion: 2 115 | name: High 116 | pixelLightCount: 2 117 | shadows: 2 118 | shadowResolution: 1 119 | shadowProjection: 1 120 | shadowCascades: 2 121 | shadowDistance: 40 122 | shadowNearPlaneOffset: 3 123 | shadowCascade2Split: 0.33333334 124 | shadowCascade4Split: {x: 0.06666667, y: 0.2, z: 0.46666667} 125 | shadowmaskMode: 1 126 | blendWeights: 2 127 | textureQuality: 0 128 | anisotropicTextures: 1 129 | antiAliasing: 0 130 | softParticles: 0 131 | softVegetation: 1 132 | realtimeReflectionProbes: 1 133 | billboardsFaceCameraPosition: 1 134 | vSyncCount: 1 135 | lodBias: 1 136 | maximumLODLevel: 0 137 | streamingMipmapsActive: 0 138 | streamingMipmapsAddAllCameras: 1 139 | streamingMipmapsMemoryBudget: 512 140 | streamingMipmapsRenderersPerFrame: 512 141 | streamingMipmapsMaxLevelReduction: 2 142 | streamingMipmapsMaxFileIORequests: 1024 143 | particleRaycastBudget: 256 144 | asyncUploadTimeSlice: 2 145 | asyncUploadBufferSize: 16 146 | asyncUploadPersistentBuffer: 1 147 | resolutionScalingFixedDPIFactor: 1 148 | excludedTargetPlatforms: [] 149 | - serializedVersion: 2 150 | name: Very High 151 | pixelLightCount: 3 152 | shadows: 2 153 | shadowResolution: 2 154 | shadowProjection: 1 155 | shadowCascades: 2 156 | shadowDistance: 70 157 | shadowNearPlaneOffset: 3 158 | shadowCascade2Split: 0.33333334 159 | shadowCascade4Split: {x: 0.06666667, y: 0.2, z: 0.46666667} 160 | shadowmaskMode: 1 161 | blendWeights: 4 162 | textureQuality: 0 163 | anisotropicTextures: 2 164 | antiAliasing: 2 165 | softParticles: 1 166 | softVegetation: 1 167 | realtimeReflectionProbes: 1 168 | billboardsFaceCameraPosition: 1 169 | vSyncCount: 1 170 | lodBias: 1.5 171 | maximumLODLevel: 0 172 | streamingMipmapsActive: 0 173 | streamingMipmapsAddAllCameras: 1 174 | streamingMipmapsMemoryBudget: 512 175 | streamingMipmapsRenderersPerFrame: 512 176 | streamingMipmapsMaxLevelReduction: 2 177 | streamingMipmapsMaxFileIORequests: 1024 178 | particleRaycastBudget: 1024 179 | asyncUploadTimeSlice: 2 180 | asyncUploadBufferSize: 16 181 | asyncUploadPersistentBuffer: 1 182 | resolutionScalingFixedDPIFactor: 1 183 | excludedTargetPlatforms: [] 184 | - serializedVersion: 2 185 | name: Ultra 186 | pixelLightCount: 4 187 | shadows: 2 188 | shadowResolution: 2 189 | shadowProjection: 1 190 | shadowCascades: 4 191 | shadowDistance: 150 192 | shadowNearPlaneOffset: 3 193 | shadowCascade2Split: 0.33333334 194 | shadowCascade4Split: {x: 0.06666667, y: 0.2, z: 0.46666667} 195 | shadowmaskMode: 1 196 | blendWeights: 4 197 | textureQuality: 0 198 | anisotropicTextures: 2 199 | antiAliasing: 2 200 | softParticles: 1 201 | softVegetation: 1 202 | realtimeReflectionProbes: 1 203 | billboardsFaceCameraPosition: 1 204 | vSyncCount: 1 205 | lodBias: 2 206 | maximumLODLevel: 0 207 | streamingMipmapsActive: 0 208 | streamingMipmapsAddAllCameras: 1 209 | streamingMipmapsMemoryBudget: 512 210 | streamingMipmapsRenderersPerFrame: 512 211 | streamingMipmapsMaxLevelReduction: 2 212 | streamingMipmapsMaxFileIORequests: 1024 213 | particleRaycastBudget: 4096 214 | asyncUploadTimeSlice: 2 215 | asyncUploadBufferSize: 16 216 | asyncUploadPersistentBuffer: 1 217 | resolutionScalingFixedDPIFactor: 1 218 | excludedTargetPlatforms: [] 219 | m_PerPlatformDefaultQuality: 220 | Android: 2 221 | Lumin: 5 222 | Nintendo 3DS: 5 223 | Nintendo Switch: 5 224 | PS4: 5 225 | PSP2: 2 226 | Standalone: 5 227 | WebGL: 3 228 | Windows Store Apps: 5 229 | XboxOne: 5 230 | iPhone: 2 231 | tvOS: 2 232 | -------------------------------------------------------------------------------- /ProjectSettings/TagManager.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!78 &1 4 | TagManager: 5 | serializedVersion: 2 6 | tags: [] 7 | layers: 8 | - Default 9 | - TransparentFX 10 | - Ignore Raycast 11 | - 12 | - Water 13 | - UI 14 | - 15 | - 16 | - 17 | - 18 | - 19 | - 20 | - 21 | - 22 | - 23 | - 24 | - 25 | - 26 | - 27 | - 28 | - 29 | - 30 | - 31 | - 32 | - 33 | - 34 | - 35 | - 36 | - 37 | - 38 | - 39 | - 40 | m_SortingLayers: 41 | - name: Default 42 | uniqueID: 0 43 | locked: 0 44 | -------------------------------------------------------------------------------- /ProjectSettings/TimeManager.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!5 &1 4 | TimeManager: 5 | m_ObjectHideFlags: 0 6 | Fixed Timestep: 0.02 7 | Maximum Allowed Timestep: 0.33333334 8 | m_TimeScale: 1 9 | Maximum Particle Timestep: 0.03 10 | -------------------------------------------------------------------------------- /ProjectSettings/UnityConnectSettings.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!310 &1 4 | UnityConnectSettings: 5 | m_ObjectHideFlags: 0 6 | serializedVersion: 1 7 | m_Enabled: 0 8 | m_TestMode: 0 9 | m_EventOldUrl: https://api.uca.cloud.unity3d.com/v1/events 10 | m_EventUrl: https://cdp.cloud.unity3d.com/v1/events 11 | m_ConfigUrl: https://config.uca.cloud.unity3d.com 12 | m_TestInitMode: 0 13 | CrashReportingSettings: 14 | m_EventUrl: https://perf-events.cloud.unity3d.com 15 | m_Enabled: 0 16 | m_LogBufferSize: 10 17 | m_CaptureEditorExceptions: 1 18 | UnityPurchasingSettings: 19 | m_Enabled: 0 20 | m_TestMode: 0 21 | UnityAnalyticsSettings: 22 | m_Enabled: 0 23 | m_TestMode: 0 24 | m_InitializeOnStartup: 1 25 | UnityAdsSettings: 26 | m_Enabled: 0 27 | m_InitializeOnStartup: 1 28 | m_TestMode: 0 29 | m_IosGameId: 30 | m_AndroidGameId: 31 | m_GameIds: {} 32 | m_GameId: 33 | PerformanceReportingSettings: 34 | m_Enabled: 0 35 | -------------------------------------------------------------------------------- /ProjectSettings/VFXManager.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!937362698 &1 4 | VFXManager: 5 | m_ObjectHideFlags: 0 6 | m_IndirectShader: {fileID: 0} 7 | m_CopyBufferShader: {fileID: 0} 8 | m_SortShader: {fileID: 0} 9 | m_StripUpdateShader: {fileID: 0} 10 | m_RenderPipeSettingsPath: 11 | m_FixedTimeStep: 0.016666668 12 | m_MaxDeltaTime: 0.05 13 | -------------------------------------------------------------------------------- /ProjectSettings/VersionControlSettings.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!890905787 &1 4 | VersionControlSettings: 5 | m_ObjectHideFlags: 0 6 | m_Mode: Visible Meta Files 7 | m_CollabEditorSettings: 8 | inProgressEnabled: 1 9 | -------------------------------------------------------------------------------- /ProjectSettings/XRSettings.asset: -------------------------------------------------------------------------------- 1 | { 2 | "m_SettingKeys": [ 3 | "VR Device Disabled", 4 | "VR Device User Alert" 5 | ], 6 | "m_SettingValues": [ 7 | "False", 8 | "False" 9 | ] 10 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # blazepose-unity 2 | this project is based on [tf-lite-unity-sample](https://github.com/asus4/tf-lite-unity-sample) 3 | 4 | In the sample scene you'll find a game object named `BlazePose` that has the main script attached to it. 5 | The `Custom Camera Name` field is used to specify a camera name - leave this blank for it to pick up the default camera. 6 | 7 | If you want to use the tablet you can tick `Use Front Facing Camera` if you want to use the front facing camera. 8 | 9 | The script will give you access to all body landmarks being tracked in real time using `worldJoints` and to get you started I've already extracted left and right hand positions as game objects `leftHand` and `rightHand` . 10 | 11 | 12 | For debugging you can tick `DrawSitckFigure` for it to show the blue outline (as with the video I shared above) or enable the `Canvas` game object to see the actual camera feed. 13 | -------------------------------------------------------------------------------- /build_tflite.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | import argparse 4 | import os 5 | import platform 6 | import shlex 7 | import subprocess 8 | 9 | PLUGIN_PATH=f'{os.getcwd()}/Packages/com.github.asus4.tflite/Plugins' 10 | TENSORFLOW_PATH='' 11 | 12 | def run_cmd(cmd): 13 | print(cmd) 14 | args = shlex.split(cmd) 15 | subprocess.call(args, cwd=TENSORFLOW_PATH) 16 | 17 | def copy(from_tf, to_unity): 18 | subprocess.call(['cp', '-vf', f'{TENSORFLOW_PATH}/{from_tf}', f'{PLUGIN_PATH}/{to_unity}']) 19 | 20 | def unzip(from_tf, to_unity): 21 | subprocess.call(['unzip', '-o', f'{TENSORFLOW_PATH}/{from_tf}', '-d' f'{PLUGIN_PATH}/{to_unity}']) 22 | 23 | def patch(file_path, target_str, patched_str): 24 | with open(file_path, 'r', encoding='utf-8') as file: 25 | source = file.read() 26 | source = source.replace(target_str, patched_str) 27 | with open(file_path, 'w', encoding='utf-8') as file: 28 | file.write(source) 29 | 30 | def build_mac(enable_xnnpack = False): 31 | # Main 32 | option_xnnpack = 'true' if enable_xnnpack else 'false' 33 | run_cmd(f'bazel build --config=macos -c opt --define tflite_with_xnnpack={option_xnnpack} tensorflow/lite/c:tensorflowlite_c') 34 | copy('bazel-bin/tensorflow/lite/c/libtensorflowlite_c.dylib', 'macOS/libtensorflowlite_c.dylib') 35 | 36 | # Metal Delegate 37 | # v2.3.0 or later, Need to apply the following patch to build metal delegate 38 | # For further info 39 | # https://github.com/tensorflow/tensorflow/issues/41039#issuecomment-664701908 40 | cpuinfo_file = f'{TENSORFLOW_PATH}/third_party/cpuinfo/BUILD.bazel' 41 | original = '"cpu": "darwin",' 42 | patched = '"cpu": "darwin_x86_64",' 43 | patch(cpuinfo_file, original, patched) 44 | # Build Metal Delegate 45 | run_cmd('bazel build --config=macos -c opt --copt -Os --copt -DTFLITE_GPU_BINARY_RELEASE --copt -fvisibility=default --linkopt -s --strip always --apple_platform_type=macos //tensorflow/lite/delegates/gpu:tensorflow_lite_gpu_dylib') 46 | copy('bazel-bin/tensorflow/lite/delegates/gpu/tensorflow_lite_gpu_dylib.dylib', 'macOS/libtensorflowlite_metal_delegate.dylib') 47 | # Restore it 48 | patch(cpuinfo_file, patched, original) 49 | 50 | def build_windows(enable_xnnpack = False): 51 | # Main 52 | option_xnnpack = 'true' if enable_xnnpack else 'false' 53 | run_cmd(f'bazel build -c opt --define tflite_with_xnnpack={option_xnnpack} tensorflow/lite/c:tensorflowlite_c') 54 | copy('bazel-bin/tensorflow/lite/c/tensorflowlite_c.dll', 'Windows/libtensorflowlite_c.dll') 55 | # TODO GPU Delegate 56 | 57 | def build_linux(): 58 | # Testd on Ubuntu 18.04.5 LTS 59 | # Main 60 | run_cmd('bazel build -c opt --cxxopt=--std=c++11 tensorflow/lite/c:tensorflowlite_c') 61 | copy('bazel-bin/tensorflow/lite/c/libtensorflowlite_c.so', 'Linux/libtensorflowlite_c.so') 62 | # TODO GPU Delegate 63 | 64 | def build_ios(): 65 | # Main 66 | run_cmd('bazel build --config=ios_fat -c opt //tensorflow/lite/ios:TensorFlowLiteC_framework') 67 | unzip('bazel-bin/tensorflow/lite/ios/TensorFlowLiteC_framework.zip', 'iOS') 68 | # Metal Delegate 69 | run_cmd('bazel build -c opt --config=ios_fat //tensorflow/lite/ios:TensorFlowLiteCMetal_framework') 70 | unzip('bazel-bin/tensorflow/lite/ios/TensorFlowLiteCMetal_framework.zip', 'iOS') 71 | # CoreML Delegate 72 | # run_cmd('bazel build -c opt --config=ios_fat //tensorflow/lite/ios:TensorFlowLiteCCoreML_framework') 73 | # unzip('bazel-bin/tensorflow/lite/ios/TensorFlowLiteCCoreML_framework.zip', 'iOS') 74 | # SelectOps Delegate 75 | # run_cmd('bazel build -c opt --config=ios --ios_multi_cpus=armv7,arm64,x86_64 //tensorflow/lite/ios:TensorFlowLiteSelectTfOps_framework') 76 | # unzip('bazel-bin/tensorflow/lite/ios/TensorFlowLiteSelectTfOps_framework.zip', 'iOS') 77 | 78 | def build_android(enable_xnnpack = False): 79 | # Main 80 | option_xnnpack = 'true' if enable_xnnpack else 'false' 81 | run_cmd(f'bazel build -c opt --config=android_arm64 --define tflite_with_xnnpack={option_xnnpack} //tensorflow/lite/c:libtensorflowlite_c.so') 82 | copy('bazel-bin/tensorflow/lite/c/libtensorflowlite_c.so', 'Android') 83 | # GPU Delegate 84 | run_cmd('bazel build -c opt --config=android_arm64 --copt -Os --copt -DTFLITE_GPU_BINARY_RELEASE --copt -fvisibility=hidden --linkopt -s --strip always //tensorflow/lite/delegates/gpu:libtensorflowlite_gpu_delegate.so') 85 | copy('bazel-bin/tensorflow/lite/delegates/gpu/libtensorflowlite_gpu_delegate.so', 'Android') 86 | # GL Delegate 87 | run_cmd('bazel build -c opt --config=android_arm64 --copt -Os --copt -DTFLITE_GPU_BINARY_RELEASE --copt -fvisibility=hidden --linkopt -s --strip always //tensorflow/lite/delegates/gpu:libtensorflowlite_gpu_gl.so') 88 | copy('bazel-bin/tensorflow/lite/delegates/gpu/libtensorflowlite_gpu_gl.so', 'Android') 89 | 90 | # NNAPI Delegate 91 | # run_cmd('bazel build -c opt --config=android_arm64 //tensorflow/lite/delegates/nnapi:nnapi_delegate') 92 | # copy('bazel-bin/tensorflow/lite/delegates/nnapi/libnnapi_delegate.so', 'Android') 93 | 94 | if __name__ == '__main__': 95 | parser = argparse.ArgumentParser(description = 'Update TensorFlow Lite libraries for Unity') 96 | parser.add_argument('--tfpath', default = '../tensorflow', type = str, 97 | help = 'The path of the TensorFlow repository') 98 | parser.add_argument('-macos', action = "store_true", default = False, 99 | help = 'Build macOS') 100 | parser.add_argument('-windows', action = "store_true", default = False, 101 | help = 'Build Windows') 102 | parser.add_argument('-linux', action = "store_true", default = False, 103 | help = 'Build Linux') 104 | parser.add_argument('-ios', action = "store_true", default = False, 105 | help = 'Build iOS') 106 | parser.add_argument('-android', action = "store_true", default = False, 107 | help = 'Build Android') 108 | parser.add_argument('-xnnpack', action = "store_true", default = False, 109 | help = 'Build with XNNPACK') 110 | 111 | args = parser.parse_args() 112 | TENSORFLOW_PATH = os.path.abspath(args.tfpath) 113 | 114 | platform_name = platform.system() 115 | 116 | if args.macos: 117 | assert platform_name == 'Darwin', f'-macos not suppoted on the platfrom: {platform_name}' 118 | print('Build macOS') 119 | build_mac(args.xnnpack) 120 | 121 | if args.windows: 122 | assert platform_name == 'Windows', f'-windows not suppoted on the platfrom: {platform_name}' 123 | print('Build Windows') 124 | build_windows(args.xnnpack) 125 | 126 | if args.linux: 127 | assert platform_name == 'Linux', f'-linux not suppoted on the platfrom: {platform_name}' 128 | print('Build Linux') 129 | build_linux() 130 | 131 | if args.ios: 132 | assert platform_name == 'Darwin', f'-ios not suppoted on the platfrom: {platform_name}' 133 | # Need to set iOS build option in ./configure 134 | print('Build iOS') 135 | build_ios() 136 | 137 | if args.android: 138 | # Need to set Android build option in ./configure 139 | print('Build Android') 140 | build_android(args.xnnpack) 141 | --------------------------------------------------------------------------------