2020幎ã«ã¯ãã¢ãã€ã«ãã©ãããã©ãŒã ã§ã®æ©æ¢°åŠç¿ã¯ãã¯ãé©åœçã§ã¯ãããŸãããã¹ããŒãæ©èœã®ã¢ããªã±ãŒã·ã§ã³ãžã®çµ±åã¯ãæšæºçãªæ¹æ³ã«ãªã£ãŠããŸãã
幞ããªããšã«ãããã¯Appleãé©æ°çãªãã¯ãããžãŒã®éçºããããããšãæå³ãããã®ã§ã¯ãããŸããã
ãã®æçš¿ã§ã¯ãAppleãšã³ã·ã¹ãã ã«ãããCoreMLãã©ãããã©ãŒã ããã³ãã®ä»ã®AIããã³ãã·ã³åŠç¿ãã¯ãããžãŒã«é¢ãããã¥ãŒã¹ãç°¡åã«å ±æããŸãã
ã³ã¢ML
æšå¹ŽãCoreMLãã©ãããã©ãŒã ã¯ã¡ãžã£ãŒã¢ããããŒããåãåããŸãããä»å¹Žã¯ãç¶æ³ã¯ã¯ããã«æ§ããã«ãªããŸãããããã€ãã®æ°ããã¿ã€ãã®ã¬ã€ã€ãŒãè¿œå ãããæå·åã¢ãã«ããµããŒããããã¢ãã«ã®æŽæ°ãCloudKitã«æçš¿ã§ããããã«ãªããŸããã
ããŒãžã§ã³çªå·ãåé€ããããšã決å®ãããããã§ããæšå¹Žã®æŽæ°åŸããã©ãããã©ãŒã ã¯Core ML 3ãšããŠç¥ãããããã«ãªããŸããããçŸåšã¯ããŒãžã§ã³çªå·ãªãã§CoreMLãšããååã䜿çšããŠããŸãããã ããcoremltoolsããã±ãŒãžã¯ããŒãžã§ã³4ã«æŽæ°ãããŠããŸãã
泚ãmlmodelã®å éšä»æ§ã¯ããŒãžã§ã³5ã«ãªããŸãããããã¯ãæ°ããã¢ãã«ããCoreMLv5ããšããååã§Netronã«è¡šç€ºãããããšãæå³ããŸãã
CoreMLã®æ°ããã¬ã€ã€ãŒã¿ã€ã
次ã®ã¬ã€ã€ãŒãè¿œå ãããŸããã
Convolution3DLayer, Pooling3DLayer, GlobalPooling3DLayer
: â Vision ( Core ML - , ).OneHotLayer
: .ClampedReLULayer
: ReLU ( ReLU6).- ArgSortLayer: . . , GatherLayer, argsort.
CumSumLayer
: .SliceBySizeLayer
ïŒCoreMLã§ã¯ãã§ã«ããã€ãã®ã¿ã€ãã®åå²ã¬ã€ã€ãŒãå©çšå¯èœã§ãããã®ã¬ã€ã€ãŒã䜿çšãããšãããŒãã£ã·ã§ã³ã®éå§å ã®ã€ã³ããã¯ã¹ãå«ããã³ãœã«ãæž¡ãããšãã§ããŸããåæã«ãã»ã¯ã¿ãŒãµã€ãºã¯åžžã«åºå®ããããŸãŸã§ãã
ãããã®ã¿ã€ãã®ã¬ã€ã€ãŒã¯ãããŒãžã§ã³5以éãã€ãŸãiOS14ããã³macOS11.0以éã§äœ¿çšã§ããŸãã
ãã1ã€ã®äŸ¿å©ãªæ¡åŒµæ©èœïŒæ¬¡ã®ã¬ã€ã€ãŒã®8ãããéååæäœïŒ
InnerProductLayer
BatchedMatMulLayer
Core MLã®ä»¥åã®ããŒãžã§ã³ã§ã¯ãéã¿ã¯éååãããŠããŸããããã¢ãã«ãããŒãããåŸãæµ®åå°æ°ç¹åœ¢åŒã«å€æãããŸãããæ°æ©èœ
int8DynamicQuantize
ã«ãããéã¿ã8ãããã®æŽæ°å€ãšããŠä¿åããæŽæ°ã䜿çšããŠå®éã®èšç®ãå®è¡ããããšãã§ããŸãã
INT8ã䜿çšããèšç®ã¯ãæµ®åå°æ°ç¹æŒç®ãããã¯ããã«é«éã§ããããã¯CPUã«ããã€ãã®å©ç¹ãæäŸããŸããããããŒãã£ã³ã°ãã€ã³ãæäœãGPUã«ãšã£ãŠéåžžã«å¹ççã§ãããããGPUã®ããã©ãŒãã³ã¹ãåäžãããã©ããã¯äžæã§ãããããããNeural Engineã®å°æ¥ã®ã¢ããããŒãã§ã¯ãINT8æäœã®çµã¿èŸŒã¿ãµããŒããå®è£ ãããäºå®ã§ãïŒçµå±ã®ãšãããAppleã¯æè¿Xnor.aiãè²·åããŸãã...ïŒã
CPUåŽã§ã¯ãCore MLã¯32ãããã§ã¯ãªã16ãããã®ãããŒãã£ã³ã°ãã€ã³ãã䜿çšã§ããããã«ãªããŸããïŒA11 Bionic以éïŒããããªãSwiftã§ã®æ°å€èšç®ã®æ¢çŽ¢ãã§èª¬æããããã«ãFloat16ã¯Swiftã®ãã¡ãŒã¹ãã¯ã©ã¹ã®ããŒã¿ã¿ã€ãã«ãªããŸããã 16ããããããŒãã£ã³ã°ãã€ã³ãæäœã®ãã€ãã£ããµããŒãã«ãããCoreMLã¯é床ã2åã«ããããšãã§ããŸãã
泚ã Core MLã§ã¯ãFloat16ããŒã¿ã¿ã€ãã¯GPUãšNeural Engineã§ãã§ã«äœ¿çšãããŠãããããCPUã§äœ¿çšããå Žåã«ã®ã¿éããé¡èã«ãªããŸãã
ãã®ä»ã®ïŒãã€ããŒãªïŒå€æŽïŒ
UpsampleLayer
. BILINEAR ( align-corners). , , .-
ReorganizeDataLayerParams
PIXEL_SHUFFLE. , . , . -
SliceStaticLayer
SliceDynamicLayer
squeezeMasks, . -
TileLayer
, .
ããã€ã¹ã§ã®ããŒã«ã«åŠç¿ã«é¢ããŠã¯å€æŽã¯ãªãããã§ããããã§ããå®å šã«æ¥ç¶ãããç³ã¿èŸŒã¿ã¬ã€ã€ãŒã®ã¿ããµããŒããããŸãã
MLParameterKey
CoreML.frameworkã®ã¯ã©ã¹ã«ãRMSpropãªããã£ãã€ã¶ã®æ§æãã©ã¡ãŒã¿ãå«ãŸããããã«ãªããŸãããããã®æ¡åŒµæ©èœã¯ãŸã NeuralNetwork.protoã«å«ãŸããŠããŸãããããããã次ã®ããŒã¿çã§è¿œå ãããã§ãããã
次ã®ã¢ãã«ã®æ°ããçš®é¡ããããŠããè¿œå ïŒ
VisionFeaturePrint.Object
-ç©äœèªèçšã«æé©åãããç¹åŸŽæœåºéšãã
SerializedModel
..ããããäœã®ããã«ããã®ãæ£ç¢ºã«ã¯ããããŸãããããã¯ãéå
¬éãã®å®çŸ©ã§ããããéç¥ãŸãã¯è²¬ä»»ãªãã«å€æŽãããå¯èœæ§ããããŸããããã¶ãããã¯ãAppleãç¬èªã®ã¢ãã«åœ¢åŒãmlmodelã«åã蟌ãæ¹æ³ã§ããïŒ
ã¢ãã«ã®æŽæ°ãCloudKitã«æçš¿ãã
ãã®æ°ããCoreMLã³ã³ããŒãã³ãã䜿çšãããšãã¢ããªã±ãŒã·ã§ã³ãšã¯å¥ã«ã¢ãã«ãæŽæ°ã§ããŸãã
ã¢ããªã±ãŒã·ã§ã³å šäœãæŽæ°ãã代ããã«ããããã€ãããã€ã³ã¹ã¿ã³ã¹ã«æ°ããããŒãžã§ã³ã®mlmodelãããŒãããã ãã§æžã¿ãŸããæ£çŽãªãšããããã®ã¢ã€ãã¢ã¯æ°ãããã®ã§ã¯ãªããäžéšã®ãµãŒãããŒãã£ãã³ããŒã¯ãã§ã«å¯Ÿå¿ããSDKãéçºããŠããŸãããã®äžããã®ãããªããã±ãŒãžãèªåã§äœæããããšã¯é£ãããããŸããããã®å Žåã®Appleã®ãœãªã¥ãŒã·ã§ã³ã®å©ç¹ã¯ãAppleCloudã§ã¢ãã«ããã¹ãã§ããããšã§ãã
ã¢ããªã±ãŒã·ã§ã³ã¯è€æ°ã®ã¢ãã«ãæã€ããšãã§ãããããã¢ãã«ã®ã³ã¬ã¯ã·ã§ã³ã®æ°ããæŠå¿µã«ãããã¢ãã«ã1ã€ã®ããã±ãŒãžã«ãŸãšããŠãã¢ããªã±ãŒã·ã§ã³ããã¹ãŠã®ã¢ãã«ãåæã«æŽæ°ã§ããããã«ããããšãã§ããŸãããã®ãããªã³ã¬ã¯ã·ã§ã³ã¯ãCloudKitããã·ã¥ããŒãã䜿çšããŠäœæã§ããŸãã
ã¢ããªã±ãŒã·ã§ã³ã¯ã¯ã©ã¹ã䜿çšããŠãã¢ãã«ã®æŽæ°ãããŠã³ããŒãããã³ç®¡çããŸã
MLModelCollection
ãWWDCã®ãããªã¯ããã®ã¿ã¹ã¯ãéæããããã«ã³ãŒãã¹ããããã瀺ããŠããŸãã
å±éããã³ã¢MLã¢ãã«ãæºåããããã«ãXcodeã§[ã¢ãã«ã¢ãŒã«ã€ãã®äœæ]ãã¿ã³ã䜿çšã§ããããã«ãªããŸããããããã¯ãªãã¯ãããšã.mlarchiveãã¡ã€ã«ã«æžã蟌ãŸããŸãããã®ããŒãžã§ã³ã®ã¢ãã«ã¯ãCloudKitããã·ã¥ããŒãã«éä¿¡ããŠãããã¢ãã«ã³ã¬ã¯ã·ã§ã³ã«è¿œå ã§ããŸãïŒmlarchiveã¯ãmlmodelcãã©ã«ããŒã®å 容ãè¿œå ãããéåžžã®ZIPã¢ãŒã«ã€ãã®ããã«èŠããŸãïŒã
ããŸããŸãªã¢ãã«ã®ã³ã¬ã¯ã·ã§ã³ãããŸããŸãªãŠãŒã¶ãŒã«å±éã§ãããšéåžžã«äŸ¿å©ã§ããããšãã°ãiPhoneã«ã¡ã©ã¯iPadã«ã¡ã©ãšã¯ç°ãªããããã¢ãã«ã®2ã€ã®ããŒãžã§ã³ãäœæãã1ã€ãiPhoneãŠãŒã¶ãŒã«ããã1ã€ãiPadãŠãŒã¶ãŒã«éä¿¡ããå¿ èŠãããå ŽåããããŸãã
ããŸããŸãªã¯ã©ã¹ã®ããã€ã¹ïŒiPhoneãiPadãTVãWatchïŒãããŸããŸãªãªãã¬ãŒãã£ã³ã°ã·ã¹ãã ãšãã®ããŒãžã§ã³ãå°åã³ãŒããèšèªã³ãŒããããã³ã¢ããªã±ãŒã·ã§ã³ããŒãžã§ã³ã®ã«ã¹ã¿ãã€ãºã«ãŒã«ãå®çŸ©ã§ããŸãã
ä»ã®åºæºã«åºã¥ããŠãŠãŒã¶ãŒãã°ã«ãŒãã«åå²ããã¡ã«ããºã ã¯ãªãããã§ããããšãã°ãã¢ãã«ã®æŽæ°ã®A / Bãã¹ãããç¹å®ã®ããã€ã¹ã¿ã€ãïŒiPhone X以åïŒã®ãã¥ãŒãã³ã°ãªã©ã§ãããã ããããã¯ãç°ãªãååã§ã³ã¬ã¯ã·ã§ã³ãäœæããããæ瀺çã«èŠæ±ããããšã«ãããæåã§è¡ãããšãã§ããŸãã
MLModelCollection
å®è¡æã«æå®ãããååã§é©åãªã³ã¬ã¯ã·ã§ã³ãæäŸããŸãã
ã¢ãã«ã®æ°ããããŒãžã§ã³ã®å±éã¯å¿ ãããé«éã§ã¯ãããŸãããããæç¹ã§ãã¢ããªã±ãŒã·ã§ã³ã¯æ°ããå©çšå¯èœãªã¢ãã«ãæ€åºãããããèªåçã«ããŠã³ããŒãããŠã¢ããªã±ãŒã·ã§ã³ã®ãã¹ãç°å¢ã«é 眮ããŸãããã ãããããã©ãã§ã©ã®ããã«çºçããããå€æããæ©èœã¯ãããŸãããããšãã°ãé»è©±ã䜿çšããŠããªããšãã«ãCoreMLãããã¯ã°ã©ãŠã³ãã§ããŠã³ããŒãã§ããŸãã
ãã®ããããã¹ãŠã®å Žåã«ãããŠããã©ãŒã«ããã¯ãšããŠçµã¿èŸŒã¿ã¢ãã«ãã¢ããªã«è¿œå ããããšããå§ãããŸããããšãã°ãiPhoneãšiPadã®äž¡æ¹ããµããŒãããæ±çšã¢ãã«ã§ãã
ãã®äŸ¿å©ãªãœãªã¥ãŒã·ã§ã³ã«ããããŠãŒã¶ãŒã¯ã»ã«ããã¹ãã£ã³ã°ã¢ãã«ã«ã€ããŠå¿é ããå¿ èŠããªããªããŸãããã¢ããªã±ãŒã·ã§ã³ã§CloudKitã䜿çšãããŠããããšã«æ³šæããŠãã ãããç§ãç解ããŠããããã«ãã¢ãã«ã³ã¬ã¯ã·ã§ã³ã¯åèšã¹ãã¬ãŒãžã¯ã©ãŒã¿ã«ã«ãŠã³ããããã¢ãã«ããŒãã¯ãããã¯ãŒã¯ãã©ãã£ãã¯ã¯ã©ãŒã¿ã«ã«ãŠã³ããããŸãã
åç §ïŒ
- ã¢ãã«ã®å±éãšã³ã¢MLã®ä¿è·ïŒWWDCãããªïŒ
- ã¢ãã«ã®ã³ã¬ã¯ã·ã§ã³ã®äœæãšå±é
- æ¡åŒµã¢ãã«ã³ã¬ã¯ã·ã§ã³ã®ååŸ
泚ãCloudKitã䜿çšããæ°ããæŽæ°æ©èœã¯ãæ®å¿µãªããããŒã«ã«ã¢ãã«ã®ããŒãœãã©ã€ãºãšçµã¿åãããã®ãéåžžã«å°é£ã§ããããŒãœãã©ã€ãºãããã¢ãã«ã«ãã£ãŠåŸãããç¥èãæ°ããã¢ãã«ã«è»¢éããããäœããã®æ¹æ³ã§ããããçµã¿åããããããç°¡åãªæ¹æ³ã¯ãããŸããã
ã¢ãã«ã®æå·å
ãããŸã§ãæ»æè ã¯Core MLã¢ãã«ãç°¡åã«çãã§ãç¬èªã®ã¢ããªã±ãŒã·ã§ã³ã«çµ±åããããšãã§ããŸãããiOS 14 / macOS 11.0以éãCore MLã¯ã¢ãã«ã®èªåæå·åãšåŸ©å·åããµããŒãããæ»æè ã«ããmlmodelcãã©ã«ããŒãžã®ã¢ã¯ã»ã¹ãå¶éããŸããæå·åã¯ãCloudKitãä»ããŠããŸãã¯åå¥ã«ãæ°ããå±éæ©èœãšçµã¿åãããŠäœ¿çšââã§ããŸãã
Xcodeã¯ãå ã®mlmodelã§ã¯ãªããã³ã³ãã€ã«ãããã¢ãã«ïŒmlmodelcïŒãæå·åããŸããã¢ãã«ã¯åžžã«ãŠãŒã¶ãŒã®ããã€ã¹ã§æå·åãããŸãããŸããã¢ããªã±ãŒã·ã§ã³ãã¢ãã«ã®ã€ã³ã¹ã¿ã³ã¹ãäœæããå Žåã«ã®ã¿ãCoreMLã¯ãããèªåçã«åŸ©å·åããŸããã¢ãã«ã®åŸ©å·åãããããŒãžã§ã³ã¯ã¡ã¢ãªã«ã®ã¿ååšãããã¡ã€ã«ãšããŠä¿åãããŸããã
ãŸããæå·åããŒãå¿ èŠã§ããè¯ããã¥ãŒã¹ã¯ããã®ããŒãèªåã§ç®¡çããå¿ èŠããªãããšã§ãã [æå·åããŒã®äœæ]ãã¿ã³ãCoreMLXcodeã¢ãã«ãã¥ãŒã¢ã§äœ¿çšã§ããããã«ãªããŸããïŒæå·åããŒãäœæããŸãïŒããã®ãã¿ã³ãã¯ãªãã¯ãããšãXcodeã¯æ°ããæå·åããŒãçæãããããAppleéçºããŒã ã¢ã«ãŠã³ãã«é¢é£ä»ããŸãã蚌ææžã®çœ²åèŠæ±ãç©çã¢ã¯ã»ã¹ããŒãåŠçããå¿ èŠã¯ãããŸããã
ãã®æé ã«ãããæ°ãã.mlmodelkeyãã¡ã€ã«ãäœæãããŸããããŒã¯AppleãµãŒããŒã«ä¿åãããŸãããXcodeã§ã¢ãã«ãæå·åããããã®ããŒã«ã«ã³ããŒãååŸããŸãããã®æå·åããŒãã¢ããªã±ãŒã·ã§ã³ã«åã蟌ãå¿ èŠã¯ãããŸãããç¹ã«ãåã蟌ãå¿ èŠããªãããã§ãã
Core MLã¢ãã«ãæå·åãã
--encrypt YourModel.mlmodelkey
ããã«ããã®ã¢ãã«ã®ã³ã³ãã€ã©ãã©ã°ãè¿œå ã§ããŸãããŸããCloudKitã䜿çšããŠã¢ãã«ãå±éããå Žåã¯ãã¢ãã«ã¢ãŒã«ã€ããäœæãããšãã«æå·åããŒãæå®ããå¿
èŠããããŸãã
ã¢ããªã±ãŒã·ã§ã³ãã¢ãã«ãã€ã³ã¹ã¿ã³ã¹åããåŸã«ã¢ãã«ã埩å·åããã«ã¯ãCoreMLããããã¯ãŒã¯çµç±ã§Appleã®ãµãŒããŒããæå·åããŒãååŸããå¿ èŠããããŸãããã¡ãããããã«ã¯ãããã¯ãŒã¯æ¥ç¶ãå¿ èŠã§ãã Core MLã¯ãã¢ãã«ãåããŠäœ¿çšãããšãã«ã®ã¿ãã®æé ãå®è¡ããŸãã
ãããã¯ãŒã¯æ¥ç¶ããªããæå·åããŒããŸã ããŒããããŠããªãå Žåãã¢ããªã±ãŒã·ã§ã³ã¯CoreMLã¢ãã«ãã€ã³ã¹ã¿ã³ã¹åã§ããŸããããã®ãããæ°ããé¢æ°ã䜿çšããããšããå§ãããŸã
YourModel.load()
ãããã«ã¯ãããŠã³ããŒããšã©ãŒã«å¿çã§ããæçµãã³ãã©ãŒãå«ãŸããŠããŸããããšãã°ããšã©ãŒã³ãŒãmodelKeyFetch
ã¯ãCoreMLãAppleãµãŒããŒããæå·åããŒãããŠã³ããŒãã§ããªãã£ãããšã瀺ããŠããŸãã
ããã¯ã誰ããç¹èš±æè¡ãçãããšãå¿é ããŠããå Žåã«éåžžã«äŸ¿å©ãªæ©èœã§ããããã«ãã¢ããªã±ãŒã·ã§ã³ãžã®çµ±åãç°¡åã§ãã
åç §ïŒ
- ã¢ãã«ã®å±éãšã³ã¢MLã®ä¿è·ïŒWWDCãããªïŒ
- ã¢ãã«æå·åããŒã®çæ
- ã¢ããªã±ãŒã·ã§ã³ã§ã¢ãã«ãæå·åãã
泚ããã®éçºè ãã©ãŒã©ã ã®æçš¿ã§æäŸãããŠããæ å ±ã«ãããšãæå·åãããã¢ãã«ã¯ããŒã«ã«ã®ããŒãœãã©ã€ãºããµããŒãããŠããŸãããåççã«èãããŸãã
CoreML.framework
CoreMLã¢ãã«ãæäœããããã®iOSAPIã¯ããã»ã©å€æŽãããŠããŸãããããã§ããããã€ãèå³æ·±ãç¹ã«æ³šæããããšæããŸãã
ããã§ã®å¯äžã®æ°ããã¯ã©ã¹ã¯
MLModelCollection
ãCloudKitã§å±éããããšãç®çãšããã¯ã©ã¹ã§ãã
ãã§ã«ãåç¥ã®ããã«ãmlmodelãã¡ã€ã«ããããžã§ã¯ãã«è¿œå ãããšãXcodeã¯ãã¢ãã«ã®æäœã容æã«ããã¯ã©ã¹ãå«ãSwiftãŸãã¯Objective-CãœãŒã¹ãã¡ã€ã«ãèªåçã«çæããŸãããããã®çæãããã¯ã©ã¹ã«ããã€ãã®å€æŽããããŸãã
-
init()
. ,let model = YourModel()
.YourModel(configuration:)
YourModel.load()
, (, ). - ,
CVPixelBuffer
YourModelInput
,CGImage
URL-, PNG- JPG-, . ,cropAndScale
cropRect
. , , .
MLModelããã¥ã¡ã³ãã«æ°ããèŠå ããã
ãŸãã1ã€ã®ã¹ã¬ãããŸãã¯1ã€ã®éä¿¡ãã¥ãŒã§ã®ã¿MLModelã€ã³ã¹ã¿ã³ã¹ã䜿çšããŠãã ããããããè¡ãã«ã¯ãã¢ãã«ãžã®ã¡ãœããåŒã³åºããã·ãªã¢ã«åããããã¹ã¬ããããã³ãã£ã¹ããããã¥ãŒããšã«ã¢ãã«ã®åå¥ã®ã€ã³ã¹ã¿ã³ã¹ãäœæããŸãã
ãã£ããã¿ãŸããã MLModelå ã§ã¯ããªã¯ãšã¹ãã®åŠçã«ã·ãŒã±ã³ã·ã£ã«ãã¥ãŒã䜿çšãããŠããããã«èŠããŸããããééã£ãŠããããäœããå€æŽãããŠããå¯èœæ§ããããŸãããããã«ãããå°æ¥çã«ã¯ãã®æšå¥šäºé ã«åºå·ããã®ãæåã§ããå®è£ ãããæ°ããåæåå
MLMultiArray
init(concatenating:axis:dataType:)
ãæ¢åã®è€æ°ã®ãã«ãã¢ã¬ã€ãçµã¿åãããŠæ°ãããã«ãã¢ã¬ã€ãäœæããŸããçµåãå®è¡ãããæå®ããã軞ãé€ããŠããããã¯ãã¹ãŠåã圢ç¶ã§ããå¿
èŠããããŸãããã®æ©èœã¯ãCreate MLã®æ°ããã¢ã¯ã·ã§ã³åé¡ã¢ãã«ã®ããã«ããããªããŒã¿ããäºæž¬ãè¡ãããã«ç¹å¥ã«è¿œå ãããããã§ãã䟿å©ïŒ
泚ãåæ
MLMultiArrayDataType
ã«éçããããã£.float
ãšãå«ãŸããããã«ãªããŸãã.float64
ããã®åæã«ã¯ãã§ã«ããããã£.float32
ãšãå«ãŸããŠãããããããããäœã®ããã«ããã®ãæ£ç¢ºã«ã¯ããããŸãã.double
ãããŒã¿ãã°ïŒ
Xcodeã¢ãã«ãã¥ãŒã¢
Xcodeã¯ãã¯ã©ã¹ã©ãã«ãè¿œå ãããã«ã¹ã¿ã ã¡ã¿ããŒã¿ãªã©ãã¢ãã«ã«é¢ããããå€ãã®æ å ±ã衚瀺ããããã«ãªããŸããããŸããã¢ãã«å ã®ã¬ã€ã€ãŒã®ã¿ã€ãã«é¢ããçµ±èšã衚瀺ãããŸãã
ããã¯ãã¢ããªã±ãŒã·ã§ã³ãå®è¡ããã«ãã¹ãã¢ãŒãã§ã¢ãã«ã«å€æŽãå ããããšãã§ãã䟿å©ãªã©ã€ããã¥ãŒã¢ã§ããç»åããããªããŸãã¯ããã¹ãããã®ãã¬ãã¥ãŒãŠã£ã³ããŠã«ãã©ãã°ããŠãã¢ãã«ã®äºæž¬ãããã«è¡šç€ºã§ããŸããçŽ æŽãããã¢ããããŒãã§ãïŒ
ããã«ãã€ã³ã¿ã©ã¯ãã£ãç°å¢ã§CoreMLã¢ãã«ã䜿çšã§ããããã«ãªããŸãããXcodeã¯ããã®ããã®ã¯ã©ã¹ãèªåçã«çæããŸããããã¯éåžžã©ããã«äœ¿çšã§ããŸããããã¯ãã¢ãã«ãã¢ããªã±ãŒã·ã§ã³ã«è¿œå ããåã«ãã¢ãã«ãã€ã³ã¿ã©ã¯ãã£ãã«ãã¹ããããã1ã€ã®æ¹æ³ã§ãã
coremltools 4
Create MLã䜿çšãããšãåçŽãªãããžã§ã¯ãçšã«ç¬èªã®ã¢ãã«ãäœæãããšäŸ¿å©ã§ããããã¬ãŒãã³ã°ã«ã¯TensorFlowãšPyTorchãããäžè¬çã«äœ¿çšãããŸãã Core MLã§ãã®ãããªã¢ãã«ã䜿çšããã«ã¯ãæåã«ã¢ãã«ãmlmodel圢åŒã«å€æããå¿ èŠããããŸããããã¯ãcoremltoolsããŒã«ããã¯ã¹ã䜿çšãããç®çã§ãã
çŽ æŽããããã¥ãŒã¹ïŒããã¥ã¡ã³ãã¯ã¯ããã«åªããŠããŸããããç解ããŠããããšããå§ãããŸããããã¥ã¡ã³ããéå»ã«åžžã«ææ°ã§ãããšã¯éããªãã£ãããããŠãŒã¶ãŒããã¥ã¢ã«ãå®æçã«æŽæ°ãããããšãé¡ã£ãŠããŸãã
泚ãæ®å¿µãªããããµã³ãã«ã®JupyterããŒãããã¯ã¯ãªããªããŸããããããã¯çŸåšãŠãŒã¶ãŒããã¥ã¢ã«ã«å«ãŸããŠããŸãããããŒãããã¯ãšããŠã¯å«ãŸããŠããŸãããã¢ãã«ãå€æããæ¹æ³ãåçã«å€åããŸãã
..ã以åã«äœ¿çšãããŠãããã¥ãŒã©ã«ãããã¯ãŒã¯ã³ã³ããŒã¿ã¯å€ããããæ°ãããããæè»ãªããŒãžã§ã³ã«çœ®ãæããããŸããã
çŸåšå©çšå¯èœãªã³ã³ããŒã¿ãŒã«ã¯ã次ã®3ã€ã®ã¿ã€ãããããŸãã
- TensorFlowïŒ1.xãš2.xã®äž¡æ¹ïŒãtf.kerasãPyTorchçšã®ææ°ã®ã³ã³ããŒã¿ãŒããããã®ã³ã³ããŒã¿ãŒã¯ãã¹ãŠåããã¯ãããžãŒã«åºã¥ããŠãããããããäžéã¢ãã«èšèªïŒMILïŒã䜿çšããŸãããã®ãããªã¢ãã«ã«ã¯ãtfcoremlãŸãã¯onnx-coremlã䜿çšããå¿ èŠããªããªããŸããã
- Keras 1.xãCaffeãONNXãã¥ãŒã©ã«ãããã¯ãŒã¯çšã®å€ãã³ã³ããŒã¿ãŒãããããã«å°çšã®ã³ã³ããŒã¿ãŒãçšæãããŠããŸãããããã®ãããªãéçºã¯äžæ¢ãããŠãããå°æ¥çã«ã¯ä¿®æ£ã®ã¿ãèšç»ãããŠããŸããPyTorchã¢ãã«ã®å€æã«ONNXã䜿çšããããšã¯æšå¥šãããªããªããŸããã
- scikit-learnãXGBoostãªã©ã®éãã¥ãŒã©ã«ãããã¯ãŒã¯ã¢ãã«çšã®ã³ã³ããŒã¿ãŒã
æ°ããçµ±äžå€æAPIã䜿çšããŠãTensorFlow 1.xã2.xãPyTorchããŸãã¯tf.kerasã¢ãã«ãå€æããŸããããã¯æ¬¡ã®ããã«é©çšãããŸãïŒ
import coremltools as ct
class_labels = [ "cat", "dog" ]
image_input = ct.ImageType(shape=(1, 224, 224, 3),
bias=[-1, -1, -1],
scale=2/255.)
model = ct.convert(
keras_model,
inputs=[ image_input ],
classifier_config=ct.ClassifierConfig(class_labels)
)
model.save("YourModel.mlmodel")
ãã®é¢æ°
ct.convert()
ã¯ãã¢ãã«ãã¡ã€ã«ããã§ãã¯ããŠãã®åœ¢åŒã決å®ããé©åãªã³ã³ããŒã¿ãŒãèªåçã«éžæããŸããåŒæ°ã¯ä»¥åã«äœ¿çšããããã®ãšã¯å°ãç°ãªããŸããååŠçåŒæ°ã¯ãªããžã§ã¯ãã䜿çšããŠæž¡ããImageType
ãåé¡åã©ãã«ã¯ãªããžã§ã¯ãã䜿çšããŠæž¡ãClassifierConfig
ããŸãã
æ°ããå€æAPIã¯ãã¢ãã«ãäžéè¡šçŸïŒããããïŒã«å€æããŸããMILãçŸåšãTensorFlow 1.xãMILã«ãTensorFlow 2.xãMILïŒtf.kerasãå«ãïŒã«ãPyTorchãMILã«å€æããããã®ã³ã³ããŒã¿ãŒãå©çšå¯èœã§ããæ°ãã深局åŠç¿ãã©ãããã©ãŒã ã人æ°ãåããšãMILãžã®ç¬èªã®ã³ã³ããŒã¿ãŒãåãåããŸãã
ã¢ãã«ãMIL圢åŒã«å€æããåŸãäžè¬çãªã«ãŒã«ã«åŸã£ãŠæé©åã§ããŸããããšãã°ãäžèŠãªæäœãåé€ããããããã€ãã®ç°ãªãã¬ã€ã€ãŒãçµã¿åããããã§ããŸãã次ã«ãã¢ãã«ãMILããmlmodel圢åŒã«å€æãããŸãã
ããããã¹ãŠã«ã€ããŠã¯ãŸã 詳ãã調ã¹ãŠããŸããããæ°ããã¢ãããŒãã«ãããcoremtools4ã以åãããå¹ççãªmlmodelãã¡ã€ã«ãäœæã§ããããã«ãªãããšãæåŸ ããŠããŸããç¹ã«TF2.xã°ã©ãã®å Žåã¯ããã§ãã
MILã§ã¯ãã³ã³ããŒã¿ãŒããŸã åââæããŠããªãã¬ã€ã€ãŒãåŠçã§ããæ©èœãç¹ã«æ°ã«å ¥ã£ãŠããŸããã¢ãã«ã«CoreMLã§çŽæ¥ãµããŒããããŠããªãã¬ã€ã€ãŒãå«ãŸããŠããå Žåã¯ããããªãã¯ã¹ä¹ç®ããã®ä»ã®ç®è¡æŒç®ãªã©ã®ããåçŽãªMILæŒç®ã«ã¢ãã«ãåå²ããå¿ èŠãããå ŽåããããŸãã
ãã®åŸãã³ã³ããŒã¿ãŒã¯ããã®ã¿ã€ãã®ãã¹ãŠã®ã¬ã€ã€ãŒã«å¯ŸããŠããããããè€åæäœãã䜿çšã§ããããã«ãªããŸããããã¯ãå¯èœã§ãããã«ã¹ã¿ã ã¬ã€ã€ãŒã䜿çšããŠãµããŒããããŠããªãæäœãè¿œå ãããããã¯ããã«ç°¡åã§ããããã¥ã¡ã³ãã¯ããã®ãããªè€åæäœã䜿çšããè¯ãäŸãæäŸããŸãã
åç §ïŒ
- Core ML ConvertersïŒWWDCãããªïŒã䜿çšããŠããã€ã¹ã§ã¢ãã«ãååŸãã
- Coremltoolsããã¥ã¡ã³ã
æ©æ¢°åŠç¿ã䜿çšããä»ã®Appleãã©ãããã©ãŒã
iOSããã³macOSSDKã®ä»ã®ããã€ãã®é«ã¬ãã«ãã¬ãŒã ã¯ãŒã¯ãããã·ã³åŠç¿ã¿ã¹ã¯ã«äœ¿çšãããŸãããã®åéã®æ°æ©èœãèŠãŠã¿ãŸãããã
ããžã§ã³
Visionã³ã³ãã¥ãŒã¿ãŒããžã§ã³ãã©ãããã©ãŒã ã¯ãå€ãã®æ°æ©èœãåããŠããŸãã
Visionãã©ãããã©ãŒã ã¯ãé¡ãç¹åŸŽçãªæ©èœãããã³äººäœãèªèããããã®ã¢ãã«ããã§ã«äœ¿çšããŠããŸããæ°ããããŒãžã§ã³ã§ã¯ã次ã®æ©èœãè¿œå ãããŠããŸãã
æã®äœçœ®èªèïŒ
VNDetectHumanHandPoseRequest
ïŒè€æ°äººã®ããŒãº
èªèïŒïŒ AppleãOSã«ããŒãºèªèæ©èœãçµã¿èŸŒãã ããšã¯çŽ æŽãããããšã§ããããã€ãã®ãªãŒãã³ãœãŒã¹ã¢ãã«ã¯ãã®æ©èœããµããŒãããŠããŸããããããã¯å¹ççãŸãã¯é«éã«ã¯ã»ã©é ãã§ããåçšãœãªã¥ãŒã·ã§ã³ã¯é«äŸ¡ã§ããé«å質ã®ããŒãºèªèããŒã«ãç¡æã§å©çšã§ããããã«ãªããŸããïŒ çŸåšãéæ¢ç»åã衚瀺ããã®ãšã¯å¯Ÿç §çã«ãããå€ãã®æ³šæãæãããŠããŸã
VNDetectHumanBodyPoseRequest
ãªãã©ã€ã³ãšãªã¢ã«ã¿ã€ã ã®äž¡æ¹ã§ã®ãããªé²ç»äžã®ãªããžã§ã¯ãã®èªèã䟿å®äžã
CMSampleBuffer
ãªã¯ãšã¹ããã³ãã©ãŒã䜿çšããŠã«ã¡ã©ããçŽæ¥ãªããžã§ã¯ãã䜿çšã§ããŸãã
ãŸãã
VNImageBasedRequest
ãµãã¯ã©ã¹ãã¯ã©ã¹VNStatefulRequest
ã«è¿œå ãããŸããããã®ãµãã¯ã©ã¹ã¯ãç®çã®ãªããžã§ã¯ãã®æ€åºãè¿
éã«ç¢ºèªãã圹å²ãæãããŸããæšæºã¯ã©ã¹ãšã¯ç°ãªããVNImageBasedRequest
è€æ°ã®ãã¬ãŒã ã«ãŸãããã¹ããŒããã«ã¯ãšãªãåå©çšããŸãããã®ãªã¯ãšã¹ãã¯ããããªã®Nãã¬ãŒã ããšã«åæãå®è¡ããŸãã
æ€çŽ¢ãªããžã§ã¯ããèŠã€ãããšããªããžã§ã¯ããå«ãæçµãã³ãã©ãŒãåŒã³åºãããŸã
VNObservation
ããã®ãã³ãã©ãŒã«ã¯timeRange
ããããªã§ã®èŠ³æž¬ã®éå§æå»ãšåæ¢æå»ã瀺ãããããã£ããããŸãã
ã¯ã©ã¹ã¯çŽæ¥
VNStatefulRequest
䜿çšãããŸãããããã¯æœè±¡åºæ¬ã¯ã©ã¹ã§ãããçŸåšVNDetectTrajectoriesRequest
ããã¹èªèã®ç®çã§ã¯ãšãªã«ãã£ãŠã®ã¿ãµãã¯ã©ã¹åãããŠããŸããããã«ãããããŒã«ãæããã蹎ã£ãããããšããªã©ãæŸç©ç·ç¶ã®ãã¹ã«æ²¿ã£ãŠç§»åãã圢ç¶ãèªèã§ããŸãïŒããã¯çŸæç¹ã§å¯äžã®çµã¿èŸŒã¿ã®ãããªé¢é£ã¿ã¹ã¯ã®ããã§ãïŒã
ãªãã©ã€ã³ãããªåæã®å Žåã
VNVideoProcessor.
ãã®ãªããžã§ã¯ãã䜿çšã§ããŸããããŒã«ã«ãããªã«UââRLãè¿œå ããNãã¬ãŒã ãŸãã¯Nç§ããšã«1ã€ä»¥äžã®VisionèŠæ±ãè¡ããŸãã
ãããªé²ç»ãåæããããã®æãéèŠãªåŸæ¥ã®ã³ã³ãã¥ãŒã¿ãŒããžã§ã³æè¡ã®1ã€ã¯ãå ã®æµãã§ãã..ã
VNGenerateOpticalFlowRequest
åãã¯ã»ã«ã1ã€ã®ãã¬ãŒã ããå¥ã®ãã¬ãŒã ã«ç§»åããæ¹åãèšç®ããã¯ãšãªãVisionã§å©çšã§ããããã«ãªããŸããïŒé«å¯åºŠã®å
ã®æµãïŒããã®çµæãVNPixelBufferObservation
åãã¯ã»ã«ã2ã€ã®32ããããŸãã¯16ãããã®æµ®åå°æ°ç¹å€ã«å¯Ÿå¿ããæ°ããç»åãå«ããªããžã§ã¯ããäœæãããŸãã
ããã«ãç»åå ã®ãªããžã§ã¯ã
VNDetectContoursRequest
ã®èŒªéãèªèããããã®æ°ããã¯ãšãªãè¿œå ãããŸããããã®ãããªãã¹ã¯ããã¯ãã«ãã¹ãšããŠè¿ãããŸããVNGeometryUtils
èªèããã茪éãããã«åŠçããããã®è£å©ããŒã«ãæäŸããŸããããšãã°ãåºæ¬çãªå¹ŸäœåŠç圢ç¶ã«åçŽåããŸãã
ãããŠãVisionã®æåŸã®é©æ°ã¯ãçµã¿èŸŒã¿ã®æ©èœæœåºæ©èœVisionFeaturePrintã®æ°ããããŒãžã§ã³ã§ãã IOSã¯ãã§ã«ãããã¯ãå®è£ ããŠããŸãVisionFeaturePrint.Sceneãããã¯ãç»ååé¡åã®äœæã«ç¹ã«äŸ¿å©ã§ããããã«ãæ°ããVisionFeaturePrint.Objectã¢ãã«ãå©çšå¯èœã«ãªããŸãããããã¯ããªããžã§ã¯ãèªèã§äœ¿çšãããæ©èœã匷調衚瀺ããããã«æé©åãããŠããŸãã
ãã®ã¢ãã«ã¯299x299ã®å ¥åç»åããµããŒããããããã圢ç¶ïŒ288ã35ã35ïŒãšïŒ768ã17ã17ïŒã®2ã€ã®ãã«ãã¢ã¬ã€ãè¿ããŸããããã¯ãŸã æ確ãªå¶éãã¬ãŒã ã¯ãŒã¯ã§ã¯ãªãããçã®ãæ©èœã®ã¿ã§ããæ¬æ Œçãªãªããžã§ã¯ãèªèãè¡ãã«ã¯ããããã®æ©èœãå¢çããã¯ã¹ãšã¯ã©ã¹ã©ãã«ã«å€æããããžãã¯ãè¿œå ããå¿ èŠããããŸãããã¬ãŒãã³ã°è»¢éã䜿çšããŠãªããžã§ã¯ãèªèããŒã«ããã¬ãŒãã³ã°ããŠããå ŽåãCreateMLã¯ãã®ã¿ã¹ã¯ãå®è¡ããŸãã
åç §ïŒ
- Computer Vision APIã®èª¿æ»ïŒWWDCãããªïŒ
- ããžã§ã³ã§äœãšæã®ããŒãºãæ€åºããïŒWWDCãããªïŒ
- ActionïŒVisionã¢ããªãæ¢çŽ¢ããïŒWWDCãããªïŒ
èªç¶èšèªåŠç
èªç¶èšèªåŠçã¿ã¹ã¯ã«ã¯ãNaturalLanguageãã©ãããã©ãŒã ã䜿çšã§ããŸãã圌女ã¯CreateMLã§ãã¬ãŒãã³ã°ãããã¢ãã«ãç©æ¥µçã«äœ¿çšããŠããŸãã
ä»å¹Žè¿œå ãããæ°æ©èœã¯ã»ãšãã©ãããŸããã
NLTagger
ãããŠNLModel
ä»ãè€æ°ã®ã¿ã°ãèŠã€ããŠããããã®æå¹æ§ãäºæž¬ããŸãã以åã¯ãã¿ã°ã®æå¹æ§ã¯ãåŸç¹ããããã€ã³ãã®æ°ã«ãã£ãŠã®ã¿æ±ºå®ãããŠããŸããã- æç« ãæ¿å
¥ããã以åã¯åèªã®æ¿å
¥ã䜿çšã§ããŸããããçŸåš
NLEmbedding
ã¯å šæããµããŒãããŠããŸãã
ã»ã³ãã³ã¹ãæ¿å ¥ããå Žåãçµã¿èŸŒã¿ã®ãã¥ãŒã©ã«ãããã¯ãŒã¯ã䜿çšããŠã»ã³ãã³ã¹å šäœã512次å ã®ãã¯ãã«ã«ãšã³ã³ãŒãããŸããããã«ãããæã§åèªã䜿çšãããŠããã³ã³ããã¹ããååŸã§ããŸãïŒåèªã®æ¿å ¥ã¯ãã®æ©èœããµããŒãããŠããŸããïŒã
åç §ïŒ
- Natural LanguageïŒWWDCãããªïŒã§ã¢ããªãããã¹ããŒãã«
é³å£°ãšé³å£°ã®åæ
ãã®é åã«å€æŽã¯ãããŸããã§ããã
ã¢ãã«ãã¬ãŒãã³ã°
Apple APIã䜿çšãããã¬ãŒãã³ã°ã¢ãã«ã¯ãiOS11.3ããã³MetalPerformanceShadersãã©ãããã©ãŒã ã§æåã«å©çšå¯èœã«ãªããŸãããéå»æ°å¹Žéã§ãå€ãã®æ°ãããã¬ãŒãã³ã°APIãè¿œå ãããä»å¹ŽãäŸå€ã§ã¯ãããŸããã§ãããç§ã®èšç®ã«ãããšãiOSããã³macOSãã©ãããã©ãŒã ã§ãã¥ãŒã©ã«ãããã¯ãŒã¯ããã¬ãŒãã³ã°ããããã®7ã€ã®ç°ãªãAPIããããŸãã
çŸåšã次ã®Apple APIã䜿çšããŠãiOSããã³macOSã§ãã·ã³åŠç¿ã¢ãã«ïŒç¹ã«ãã¥ãŒã©ã«ãããã¯ãŒã¯ïŒããã¬ãŒãã³ã°ã§ããŸãã
- CoreMLã§ã®ããŒã«ã«åŠç¿ã
- MLã®äœæïŒãã®ã€ã³ã¿ãŒãã§ã€ã¹ã¯ã¢ããªã±ãŒã·ã§ã³ãšããŠç¥ãããŠãããããããŸããããmacOSã§å©çšã§ãããã©ãããã©ãŒã ã§ããããŸãã
- Metal Performance ShadersïŒGPUã§ã®æšè«ãšãã¬ãŒãã³ã°ã®ããã®APIãå®éããããã¯2ã€ã®ç°ãªãAPIã§ãããMetalãåããŠäœ¿çšããå Žåã¯äœ¿çšããã®ãéåžžã«å°é£ã§ããããã«ããããã®ã¬ã¬ã·ãŒAPIã«åã£ãŠä»£ããããã«èŠããæ°ããMetal Performance ShadersGraphãã¬ãŒã ã¯ãŒã¯ãå©çšã§ããŸãã
- BNNSïŒAccelerateãã©ãããã©ãŒã ã®äžéšã以åã¯ãBNNSã§äœ¿çšã§ããã®ã¯æšè«ã«ãŒãã³ã®ã¿ã§ããããä»å¹Žã¯ãã¬ãŒãã³ã°ãµããŒããè¿œå ãããŸããã
- ML ComputeïŒéåžžã«ææã«èŠããæ ¹æ¬çã«æ°ãããã©ãããã©ãŒã ã
- Turi CreateïŒããã¯å®éã«ã¯CreateMLã®PythonããŒãžã§ã³ã§ãããã©ãããã©ãŒã ã®ãµããŒãã¯ãŸã çµäºããŠããŸããããæè¿ããã®äœæè ã¯ãããå¿ããŠããŸãã
ãããã®APIã®é©æ°ã詳ããèŠãŠã¿ãŸãããã
CoreMLã§ã®ããŒã«ã«åŠç¿
å®éãããã§ã¯å€§ããªå€æŽã¯ãããŸãããããã«ããã€ãã®ã¬ã€ã€ãŒã¿ã€ãã«æŽæ°ãµããŒããè¿œå ãããŠããå¯èœæ§ããããŸãããããã«é¢ããããã¥ã¡ã³ãã¯ãŸã èŠãŠããŸããã
å°æ¥ã®ããŒã¿çã§æåŸ ãããéèŠãªé©æ°ã®1ã€ã¯ãRMSpropãªããã£ãã€ã¶ãŒã§ããçŸåšã®ããŒã¿çã«ã¯å«ãŸããŠããŸããã
MLãäœæãã
Create MLãã©ãããã©ãŒã ã¯ãåœåmacOSã§ã®ã¿å©çšå¯èœã§ããã Swift Playgroundã§å®è¡ã§ããããããããæ°è¡ã®ã³ãŒãã§ã¢ãã«ããã¬ãŒãã³ã°ã§ããŸãã
æšå¹ŽãCreate MLã¯ããªãéå®ãããã¢ããªã±ãŒã·ã§ã³ã«å€æãããŸããããä»å¹Žã¯å€§å¹ ãªæ¹åãèŠãããããšãå¬ããæããŸããããã¯èšã£ãŠããCreate MLã¯ãã³ãŒãããã€ã³ãããåŒãç¶ã䜿çšã§ãããã©ãããã©ãŒã ã®ãŸãŸã§ããå®éããã®ã¢ããªã±ãŒã·ã§ã³ã¯ããã©ãããã©ãŒã ãæäœããããã®äŸ¿å©ãªã°ã©ãã£ã«ã«ã€ã³ã¿ãŒãã§ã€ã¹ã«ãããŸããã
以åã®ããŒãžã§ã³ã®CreateMLã§ã¯ãã¢ãã«ã1åã ããã¬ãŒãã³ã°ã§ããŸãããäœããå€æŽããã«ã¯ãæåããåãã¬ãŒãã³ã°ããå¿ èŠããããããã«ã¯å€ãã®æéãããããŸããã
Xcode12ã®æ°ããããŒãžã§ã³ã§ã¯ãã¬ãŒãã³ã°ãäžæåæ¢ããŠåŸã§åéããã¢ãã«ã®ãã§ãã¯ãã€ã³ãïŒã¹ãããã·ã§ããïŒãä¿åããŠãã¢ãã«ã®ãã¬ãŒãã³ã°çµæã®ãã¬ãã¥ãŒã衚瀺ããŸããçŸåšãåŠç¿ããã»ã¹ã管çããããã®ããŒã«ãå€§å¹ ã«å¢ããŠããŸããä»åã®ã¢ããããŒãã§ãCreate MLã¯æ¬åœã«äŸ¿å©ã§ãïŒ
CreateML.frameworkãã©ãããã©ãŒã ã§ã¯ããã¬ãŒãã³ã°ã»ãã·ã§ã³ã®èšå®ãã¢ãã«ãã¬ãŒã¯ãã€ã³ãã®åŠçãªã©ãæ°ããAPIãå©çšã§ããŸããã»ãšãã©ã®äººã¯Create MLã¢ããªã±ãŒã·ã§ã³ã䜿çšããã ãã ãšæããŸããããã®æ©èœããã©ãããã©ãŒã ã§å©çšã§ããããã«ãªã£ãããšã¯ãã°ãããããšã§ãã
æ°ããCreateMLæ©èœïŒãã©ãããã©ãŒã ãšã¢ããªã®äž¡æ¹ïŒïŒ
- åçããããªã®ã¹ã¿ã€ã«ã転éãã
- ãããªã«ããã人éã®è¡åã®åé¡
æ°ããã¢ã¯ã·ã§ã³åé¡ã¢ãã«ã詳ããèŠãŠã¿ãŸãããã Visionãã©ãããã©ãŒã ã§å©çšå¯èœãªå§¿å¢èªèã¢ãã«ã䜿çšããŸããã¢ã¯ã·ã§ã³åé¡åã¯ãå ¥åãšããŠïŒ
window_size, 3, 18
ïŒã®åœ¢åŒããšããã¥ãŒã©ã«ãããã¯ãŒã¯ã§ãããæåã®å€ã¯ãã¬ãŒã æ°ã§ç€ºããããããªãã©ã°ã¡ã³ãã®æéãè¡šãïŒéåžžã¯çŽ2ç§ã®ãã©ã°ã¡ã³ãã䜿çšãããŸãïŒãïŒ3ã18ïŒã¯ããŒãºã®èŠç¹ãè¡šããŸãã
ã¬ã€ã€ãŒãç¹°ãè¿ã代ããã«ããã¥ãŒã©ã«ãããã¯ãŒã¯ã¯1次å ã®ç³ã¿èŸŒã¿ã䜿çšããŸããããã¯ãæç³»åäºæž¬çšã«ç¹å¥ã«èšèšãããã¢ãã«ã®äžçš®ã§ããæ空éã°ã©ãç³ã¿èŸŒã¿ãããã¯ãŒã¯ïŒSTGCNïŒã®ããªãšãŒã·ã§ã³ã§ããå¯èœæ§ããããŸãããããã®è©³çŽ°ã¯ãã¢ããªã±ãŒã·ã§ã³ã§ãã®ãããªã¢ãã«ã䜿çšãããšãã«å¿é ããå¿ èŠã¯ãããŸãããããããç§ã¯åžžã«ãããã©ã®ããã«æ©èœããããç¥ãããã§ãã
ãªããžã§ã¯ãèªèã¢ãã«ã«ã€ããŠã¯ãTinyYOLOv2ã«åºã¥ããŠãããã¯ãŒã¯å šäœããã¬ãŒãã³ã°ããããæ°ããVisionFeaturePrint.Objectãã£ãŒãã£æœåºãŠãããã䜿çšããæ°ãããã¬ãŒãã³ã°è»¢éã¢ãŒãã䜿çšããããéžæã§ããŸããã¢ãã«ã®æ®ãã®éšåã¯ãŸã YOLOãšSSDã«äŒŒãŠããŸããã転éã®ãããã§ããã®ãã¬ãŒãã³ã°ã¯YOLOããŒã¹ã®ã¢ãã«å šäœããã¬ãŒãã³ã°ãããããã¯ããã«é«éã«ãªããŸãã
åç §ïŒ
- Create MLã䜿çšããŠã¢ã¯ã·ã§ã³åé¡åãäœæããïŒWWDCãããªïŒ
- Create MLïŒWWDCãããªïŒã§ç»åããã³ãããªã¹ã¿ã€ã«è»¢éã¢ãã«ãæ§ç¯ãã
- Control training in Create ML with Swift ( Create ML Swift) ( WWDC)
Metal Performance Shaders
Metal Performance ShadersïŒMPSïŒã¯ãMetalã®ããã©ãŒãã³ã¹ã³ã³ãã¥ãŒãã£ã³ã°ã³ã¢ã«åºã¥ããã©ãããã©ãŒã ã§ãããäž»ã«ç»ååŠçã«äœ¿çšãããŸããã2016幎以éã¯ãã¥ãŒã©ã«ãããã¯ãŒã¯ããµããŒãããŠããŸããç§ã¯ããã«ã€ããŠãã§ã«ããããããã°ãæžããŠããŸãã
ä»æ¥ãã»ãšãã©ã®ãŠãŒã¶ãŒã¯MPSã§ã¯ãªãCoreMLãéžæããŸãããã¡ãããCore MLã¯ãGPUã§ã¢ãã«ãå®è¡ãããšãã«ãMPSã®èœåãåŒãç¶ã䜿çšããŸãããã ããç¹ã«ãŠãŒã¶ãŒãèªåã§ãã¬ãŒãã³ã°ãå®æœããå Žåã¯ãMPSãçŽæ¥äœ¿çšããããšãã§ããŸãïŒã¡ãªã¿ã«ãMPSã®ä»£ããã«äœ¿çšããããšããå§ãããæ°ãããã©ãããã©ãŒã ML Computeãå©çšå¯èœã«ãªããŸããããã®èª¬æã以äžã«ç€ºããŸãïŒã
ä»å¹Žã®MPSCNNã«ã¯ããã€ãã®æ°æ©èœããããŸãããæ¢åã®æ©èœã«ããã€ãã®æ¹åãå ããããŠããŸãã
æ°ããã¯ã©ã¹ãè¿œå ããŸãã
MPSImageCanny
ãšããžèªèçšããã³ã©ã€ã³ã»ã°ã¡ã³ãèªèçšã®MPSImageEDLinesããããã¯ãã³ã³ãã¥ãŒã¿ãŒã®ããžã§ã³ã®åé¡ã«åãçµããšãã«éåžžã«åœ¹ç«ã¡ãŸãã
ä»ã®å€ãã®å€æŽã泚ç®ã«å€ããŸãã
MPSCNNConvolutionDataSource
æ°ããããããã£ãè¿œå ãããŠãkernelWeightsDataType
ãŸãããç³ã¿èŸŒã¿ã®ããã«äœ¿çšããããããéã¿ä¿æ°ã®ç°ãªãããŒã¿åã䜿çšããããšãå¯èœã«ããããšãèå³æ·±ãããšã«ãCore MLã§ã¯ãã®ããŒã¿ã¿ã€ããåã ã®ã¬ã€ã€ãŒã«äœ¿çšã§ããŸãããéã¿ãINT8ããŒã¿ã¿ã€ãã«ããããšã¯ã§ããŸããã- ã
kernelWeightsDataType
è¿ãããå Žå.float32
ãç³ã¿èŸŒã¿å±€ãšå®å šã«æ¥ç¶ãããå±€ã¯ã16ãããã§ã¯ãªã32ãããã®æµ®åå°æ°ç¹ã䜿çšããŠå®è¡ãããŸãã以åã¯ã16ãããã®ã¿ããµããŒããããŠããŸããã - æ倱é¢æ°ã§ãã©ã¡ãŒã¿ãŒã䜿çšã§ããããã«ãªããŸãã
reduceAcrossBatch
ã
Metalãããªããæããããªãã®ã§ããã°ãMPSCNNãåŒãç¶ã䜿çšã§ããŸãããã ãããã®ãããªã°ã©ãã®äœæãšå®è¡ãå€§å¹ ã«ç°¡çŽ åããæ°ãããã©ãããã©ãŒã ãMPSã°ã©ããå©çšå¯èœã«ãªããŸããã
泚ãWWDCã®ãããªãMPSNDArrayãæ°ããAPIã§ãããšè¿°ã¹ãŠããããå®éã«ãããæšå¹ŽåºãŠããŸãããã¢ãã«å ã®ãã¹ãŠã®ãã³ãµãŒãç»åã«ã§ããããã§ã¯ãªããããMPSImageãããã¯ããã«æè»ãªããŒã¿æ§é ã§ãã
NewïŒã¡ã¿ã«ããã©ãŒãã³ã¹ã·ã§ãŒããŒã°ã©ã
APIã¯MPS
MPSNNGraph
ã§é·ãéå©çšå¯èœã§ããããå®éããã®ãããªã°ã©ãã¯ãã¥ãŒã©ã«ãããã¯ãŒã¯ã®ã¿ãèšè¿°ããŠããŸãããã ãããã¹ãŠã®ã°ã©ãããã¥ãŒã©ã«ãããã¯ãŒã¯ã§ããå¿
èŠã¯ãããŸããããã®å ŽåãMetal Performance ShadersGraphãã©ãããã©ãŒã ã圹ç«ã¡ãŸãã
ãã®æ°ãããã©ãããã©ãŒã ã䜿çšããŠãæ±çšGPUèšç®ã°ã©ããäœæã§ããŸãã MPS Graphãã©ãããã©ãŒã ã¯ãããã«åºã¥ããŠæ§ç¯ãããŠããŸãããMetal PerformanceShadersã«äŸåããŠããŸããã
å»æ¢ãããAPIã®ä»¥åã®ããŒãžã§ã³ã§ã¯
MPSNNGraph
ãã°ã©ãã«ã«ã¹ã¿ã æäœãè¿œå ããããšã¯ã§ããŸããã§ãããæ°ãããã©ãããã©ãŒã ã¯ããã®ç¹ã§ã¯ããã«æè»æ§ããããŸãããã ããç¬èªã®ã¡ã¿ã«ã³ã¢ãè¿œå ããããšã¯ã§ããŸãããæ¢åã®ããªããã£ãã䜿çšããŠãã¹ãŠã®èšç®ãè¡šçŸããå¿
èŠããããŸãã
幞ããªããšã«ã³ã³ãã€ã©
MPSGraph
ãã®ãããªããªããã£ãã®åäžã®èšç®ã³ã¢ãžã®çµ±åããµããŒãããã°ã©ãã£ãã¯ããã»ããµã§æãå¹ççãªäœæ¥ãä¿èšŒããŸãããã ããæäŸãããããªããã£ããäžéšã®æäœã«äœ¿çšããããšãäžå¯èœãŸãã¯å°é£ãªå Žåããã®ã¹ããŒã ã¯æ©èœããŸããã Appleããã®ãããªæ°ããAPIãäœæãããšãã«ãæ¬æ Œçãªã«ã¹ã¿ã é¢æ°ãäœæããæ©èœãæäŸããªãçç±ãããããŸãããããããäœãã§ããŸããã
æ°ãããã©ãããã©ãŒã
MPSGraph
ã¯ãMPSGraphOperations
ãã³ãµãŒã䜿çšããŠã»ããå
ã®æäœéã®é¢ä¿ãèšè¿°ãããããªãåçŽã§è«ççãªæ§é ã§ããMPSGraphTensors
æäœã®çµæãå«ãŸããŠããŸããããã«ãå¶åŸ¡ã®äŸåé¢ä¿ãå®çŸ©ããŠãåã
ã®ããŒããä»ã®ããŒããããå
ã«éå§ããããã«åŒ·å¶ã§ããŸããã°ã©ããæ§æããåŸãã°ã©ããå®è¡ããããã³ãã³ããããã¡ãŒã«è»¢éããŠãçµæãåŸ
ã€å¿
èŠããããŸãã
MPSGraph
ã°ã©ãã«æ°åŠãŸãã¯ãã¥ãŒã©ã«ãããã¯ãŒã¯æäœãè¿œå ã§ããããã«ããã€ã³ã¹ã¿ã³ã¹ã¡ãœããã®ã»ããå
šäœãæäŸããŸãã
ããã«ããã¬ãŒãã³ã°ããµããŒããããŠããŸããããã«ã¯ãæ倱åŠçæäœãã°ã©ãã«è¿œå ããŠãããåŸæ¥ã®ã¬ã€ã€ãŒãšã¯éã®é åºã§ãã¹ãŠã®ã¬ã€ã€ãŒã®åŸé æäœãå®è¡ããããšãå«ãŸããŸã
MPSNNGraph
ã䟿å®äžãèªå埮åã¢ãŒãã䜿çšã§ããŸãããã®ã¢ãŒãã§ã¯MPSGraph
ãã°ã©ãã®åŸé
æäœãèªåçã«å®è¡ãããŸããããã«ãããå€ãã®åŽåãç¯çŽã§ããŸãã
ãã®ãããªèšç®ã°ã©ããäœæããããã®ãæ°ããã·ã³ãã«ã§ããããããAPIãç»å Žããããšãå¬ããæããŸãã以åã®ããŒãžã§ã³ãããã¯ããã«äœ¿ããããã§ãããããŠãããªãã¯ãããæ±ãããã«éå±ã®å°é家ã§ããå¿ èŠã¯ãããŸãããã¡ãªã¿ã«ãTensorFlow 1.xã®ã°ã©ãã«ãã䌌ãŠããŸãããæé©åãšããç¹ã§å€§ããªã¡ãªããããããã³ã¹ããæå°éã«æããããšãã§ããŸããããã§ããã°ã©ãã«ä»»æã®èšç®ã³ã¢ãè¿œå ããååãªæ©äŒã¯ãããŸããã
åç §ïŒ
- Metal Performance Shaders GraphïŒWWDCãããªïŒã䜿çšããŠã«ã¹ã¿ãã€ãºãããMLã¢ãã«ãæ§ç¯ãã
- ã·ã§ãŒããŒã°ã©ããžã®ã«ã¹ã¿ã é¢æ°ã®è¿œå
BNNSïŒåºæ¬çãªãã¥ãŒã©ã«ãããã¯ãŒã¯ãµãã«ãŒãã³ïŒ
Core MLãCPUã§å®è¡ãããŠããå ŽåãAccelerateãã©ãããã©ãŒã ã®äžéšã§ããBNSSã«ãŒãã³ã䜿çšããŸããç§ã¯ãã§ã«ãã®èšäºã§BNNSã«ã€ããŠæžããŠããŸãããããã®BNNSæ©èœã®ã»ãšãã©ã¯çŸåšãã»ãšãã©å»æ¢ãããæ°ããæ©èœã»ããã«çœ®ãæããããŠããŸãã
以åã¯ãå®å šã«æ¥ç¶ãããã¬ã€ã€ãŒãæãããã¿ãã°ã«ãŒãåãããã³ã¢ã¯ãã£ãåæ©èœã®ã¿ããµããŒããããŠããŸããããã®ã¢ããããŒãã§ã¯ãn次å ã¢ã¬ã€ãã»ãŒãã¹ãŠã®ã¿ã€ãã®Core MLã¬ã€ã€ãŒãããã³ãã®ãããªãã¬ãŒãã³ã°ã¬ã€ã€ãŒã®äžäœäºææ§ããŒãžã§ã³ïŒLSTMãªã©ã®çŸåšCore MLãã¬ãŒãã³ã°ããµããŒãããŠããªãã¬ã€ã€ãŒãå«ãïŒã®ãµããŒããBNNSã«è¿œå ãããŸããè€æ°ã®æ³šæã®
å±€ã®ååšã«ã泚ç®ãã䟡å€ããããŸãã..ããããã®ã¬ã€ã€ãŒã¯ãBERTãªã©ã®Transformerã¢ãã«ã§ãã䜿çšãããŸãããã1ã€ã®èå³æ·±ãç¹ã¯ããã³ãœã«ã³ã³ããªã¥ãŒã·ã§ã³ã§ãã
GPUãã¬ãŒãã³ã°ã«MPSã䜿çšããªãã®ãšåãããã«ããããã®BNNSæ©èœãèªåã§äœ¿çšããŠããªãå¯èœæ§ããããŸãã代ããã«ã䜿çšãããããã»ããµãæœè±¡åãããããé«ãã¬ãã«ã®MLComputeãã©ãããã©ãŒã ãå©çšå¯èœã«ãªããŸãããML Computeã¯BNNSãšMPSã«åºã¥ããŠããŸãããéçºè ã¯ãã®ãããªå°ããªããšã«ã€ããŠå¿é ããå¿ èŠã¯ãããŸããã
åç §ïŒBNNSãã©ãããã©ãŒã ã®ããã¥ã¡ã³ã
æ°èŠïŒMLã³ã³ãã¥ãŒãã£ã³ã°
ML Computeã¯ãCPUãŸãã¯GPUã§ãã¥ãŒã©ã«ãããã¯ãŒã¯ããã¬ãŒãã³ã°ããããã®æ ¹æ¬çã«æ°ãããã©ãããã©ãŒã ã§ãïŒãã ããæããã«ãNeural Engineããã»ããµã§ã¯ãããŸããïŒãè€æ°ã®GPUãåããMacProã§ã¯ããã®ãã©ãããã©ãŒã ã¯ããããã¹ãŠãèªåçã«äœ¿çšããŠãã¬ãŒãã³ã°ã§ããŸãã
å¥ã®åŠç¿ãã©ãããã©ãŒã ã®ååšã«å°ãé©ãããããã®ãã©ãããã©ãŒã ã䜿çšãããšãäœã¬ãã«ã®ã³ã³ããŒãã³ããBNNSãšMPSããããããŠå°æ¥çã«ã¯Neural Engineããé ãããšãã§ããããããã¹ãŠãæ¬åœã«ç°¡çŽ åãããŸãã
äœããããML Computeã¯ãMacã ãã§ãªãiOSã·ã¹ãã ã§ããµããŒããããŠããŸãã CoreMLãã©ãã«ãèšåãããŠããªãã®ã¯ããããã§ãã ML Computeã¯ãå®å šã«å¥åã«äœæãããããã§ãããã®ãã¬ãŒã ã¯ãŒã¯ã䜿çšããŠã³ã¢MLã¢ãã«ãäœæããããšã¯ã§ããŸããã
ç§èªèº«ã®çµéšãããML Computeã®ã¿ã¹ã¯ã¯ããŸã第äžã«ããµãŒãããŒãã£ã®æ·±å±€åŠç¿ããŒã«ã®äœæ¥ãã¹ããŒãã¢ããããããšã§ãããšèšããŸãã ML ComputeãçŽæ¥æäœããããã«ãã³ãŒããèšè¿°ããå¿ èŠã¯ãããŸããã TensorFlowãªã©ã®ããŒã«ããã®ãã©ãããã©ãŒã ã䜿çšããŠMacã§ããŒããŠã§ã¢ã¢ã¯ã»ã©ã¬ãŒã·ã§ã³ã«ããåŠç¿ãµããŒããæå¹ã«ããããšãæ³å®ãããŠããïŒãŸãã¯éçºè ãæãã§ããïŒããã§ãã
BNNSãšã»ãŒåãã¬ã€ã€ãŒã®ã»ããã䜿çšã§ããŸããã¬ã€ã€ãŒãã°ã©ãã«è¿œå ããŠããå®è¡ããå¿ èŠããããŸãïŒããã§ã¯ããããžãŒåŸ æ©ãã¢ãŒãã¯äœ¿çšãããŸããïŒã
ã°ã©ããäœæããã«ã¯ãæåã«ãªããžã§ã¯ã
MLCGraph
ãã€ã³ã¹ã¿ã³ã¹åããããã«ããŒããè¿œå ããå¿
èŠããããŸããããŒãã¯ãµãã¯ã©ã¹MLCLayer
ã§ããããŒãã¯ãªããžã§ã¯ããä»ããŠçžäºã«æ¥ç¶ãããŠããŸãMLCTensor
ä»ã®ã¬ã€ã€ãŒã®åºåãå«ãŸããŠããŸãã
èå³æ·±ãããšã«ãåå²ãé£çµãåãã©ãŒããããããã³è»¢éã®æäœã¯ãå¥ã ã®ã¿ã€ãã®ã¬ã€ã€ãŒã§ã¯ãªããã°ã©ãäžã§çŽæ¥æäœãããŸãã
åªãããããã°æ©èœ-
summarizedDOTDescription
ãã°ã©ãã®DOTèšè¿°ãè¿ãããããããããšãã°GraphvizãŸãã¯OmniGraffleã䜿çšããŠã°ã©ããäœæã§ããŸãïŒã¡ãªã¿ã«ãKerasã¯ãã®æ¹æ³ã§ã¢ãã«ã°ã©ããçæããŸãïŒã
ML Computeã¯ãæšè«ã°ã©ããšåŠç¿ã°ã©ããåºå¥ããŸããåŸè ã«ã¯ãæ倱ã¬ã€ã€ãŒããªããã£ãã€ã¶ãŒãªã©ã®è¿œå ã®ããŒããå«ãŸããŸãã
ã«ã¹ã¿ã ã¬ã€ã€ãŒãäœæããæ¹æ³ã¯ãªãããã§ãããã®ãããMLComputeã§äœ¿çšå¯èœãªã¿ã€ãã䜿çšããã ãã§æžã¿ãŸãã
ãã®æ°ãããã©ãããã©ãŒã ã«WWDCã»ãã·ã§ã³ããªãã£ãã®ã¯äžæè°ã§ãããããã¥ã¡ã³ããããªãæ£ãã°ã£ãŠããŸãããšã«ãããããã¯Appleããã€ã¹ã§ã®ã¢ãã«ã®ãã¬ãŒãã³ã°ã«æé©ãªAPIã§ãããšæããããããä»åŸãéçºãç¶ããŠãããŸãã
åç §ïŒML ComputePlatformããã¥ã¡ã³ã
çµè«
ã³ã¢MLã¯ããã®ãããªã¢ãã«ãæå·åã®èªåæŽæ°ãªã©äŸ¿å©ãªæ°æ©èœã®æ°ãè¿œå ããŸãããæšå¹Žè¿œå ãããã¬ã€ã€ãŒã¯ã»ãšãã©ãã¹ãŠã®åé¡ã解決ã§ãããããæ°ããã¬ã€ã€ãŒã¿ã€ãã¯å®éã«ã¯å¿ èŠãããŸãããå šäœçã«ãç§ã¯ãã®ã¢ããããŒãã奜ãã§ãã
ã§coremltools 4ã€ã®æ·»å éèŠãªæ¹å-æ°ããã³ã³ããŒã¿ã¢ãŒããã¯ãã£åã³ãã«ãã€ã³ãµããŒãTensorFlow 2åã³PyTorchã PyTorchã¢ãã«ãå€æããããã«ONNXã䜿çšããå¿ èŠããªããªã£ãããšãå¬ããæããŸãã
ã€ã³ããžã§ã³å€ãã®æ°ãã䟿å©ãªæ©èœãè¿œå ãããŸããããããŠãAppleããããªåææ©èœãè¿œå ããããšãæ°ã«å ¥ã£ãŠããŸããæ©æ¢°åŠç¿ã·ã¹ãã ã¯ãããªã®åã ã®ãã¬ãŒã ã«é©çšã§ããŸããããã®å Žåãæéã¯èæ ®ãããŸãããã¢ãã€ã«ããã€ã¹ã¯çŸåšããããªããŒã¿ã«åºã¥ããŠãªã¢ã«ã¿ã€ã ã§æ©æ¢°åŠç¿ãå®è¡ããã®ã«ååãªé床ã§ãããããè¿ãå°æ¥ããããªãã³ã³ãã¥ãŒã¿ããžã§ã³ãã¯ãããžãŒã®éçºã«ãããŠããéèŠãªåœ¹å²ãæãããšæããŸãããã¬ãŒãã³ã°
ã«é¢ããŠ...ãã®ã¿ã¹ã¯ã«7ã€ã®ç°ãªãAPIãå¿ èŠãã©ããã¯ããããŸãããæ°ããã€ã³ã¿ãŒãã§ãŒã¹ãå®å šã«æŽç·ŽããããŸã§ãAppleã¯å€ãã€ã³ã¿ãŒãã§ãŒã¹ãå»æ¢ããããªãã£ããšæããŸããMLComputeãã©ãããã©ãŒã ã«ã€ããŠã¯ã»ãšãã©ç¥ãããŠããŸããããã ãããã®èšäºã®å·çæç¹ã§ã¯ãæåã®ããŒã¿çã®ã¿ããªãªãŒã¹ãããŠããŸãã誰ãå ã«ããã®ããç¥ã£ãŠããŸã...
è¬çŸ©ã®åçã¯flaticon.comã®Freepikã¢ã€ã³ã³ã䜿çšããŠããŸãã