Softpia Japan Seminar 20190724

Softpia Japan Seminar 20190724

2019年7月24日、ソフトピアジャパンで開催された「人工知能セミナー ~クラウド・モバイル・エッジにおける機械学習~」の発表資料です。

「機械学習モデルを利用したモバイルアプリ開発の事例」について。

人工知能セミナー ~クラウド・モバイル・エッジにおける機械学習~
https://www.softopia.or.jp/events/20190724jinzai/

Ece52fe9ce913851256726020707febd?s=128

Keiji ARIYAMA

July 24, 2019
Tweet

Transcript

  1. C-LIS CO., LTD.

  2. ਓ޻஌ೳηϛφʔɹʙΫϥ΢υɾϞόΠϧɾΤοδʹ͓͚Δػցֶशʙ ɹιϑτϐΞδϟύϯ   ػցֶशϞσϧΛར༻ͨ͠
 ϞόΠϧΞϓϦ։ൃͷࣄྫ

  3.   ༗ࢁܓೋʢ,FJKJ"3*:"."ʣ $-*4$0 -5% ઐ໳ɿ"OESPJEΞϓϦ։ൃ ػցֶशྺɿ໿̐೥ ஶॻɿ
 ʰ"OESPJE4UVEJPͰ͸͡ΊΔ؆୯"OESPJEΞϓϦ։ൃʱʢٕज़ධ࿦ࣾʣ
 ʰ5FOTPS'MPXΛ͸͡Ί·ͨ͠ʱʢΠϯϓϨε3%ʣ


    ڞஶʰ5FOTPS'MPX׆༻ΨΠυʱʢٕज़ධ࿦ࣾʣ Photo : Koji MORIGUCHI (MORIGCHOWDER)
  4. 5FOTPS'MPXൃදʢ೥݄ʣ  

  5. ػցֶशΛར༻ͨ͋͠Ε͜Ε   IUUQLJWBOUJVNIBUFCMPKQFOUSZ TensorFlowͰΞχϝΏΔΏΓͷ੍࡞ձࣾΛࣝผ͢Δ IUUQCPIFNJBIBUFOBCMPHDPNFOUSZ σΟʔϓϥʔχϯάͰ͓ͦদ͞Μͷ࿡ͭࢠ͸ݟ෼͚ΒΕΔͷ͔ʁ IUUQCPIFNJBIBUFOBCMPHDPNFOUSZ IUUQDISJTUJOBIBUFOBCMPHDPNFOUSZ Deep

    LearningͰϥϒϥΠϒʂΩϟϥΛࣝผ͢Δ
  6.   ؟ڸ່ͬͷΠϥετΛ
 Πϯλʔωοτ͔ΒࣗಈͰऩू͍ͨ͠ʂ

  7. ؟ڸ່ͬ൑ఆ  

  8.   ධՁ༻αʔόʔ ܇࿅ɾֶश༻αʔόʔ܈ σʔληοτసૹ ʢTFRecordʣ ֶशࡁϞσϧऔಘ ը૾औಘ ը૾औಘ ϥϕϧ

    ෇͚ σʔληοτ؅ཧ αʔόʔ ը૾ऩू ϥϕϧ ෇͚ σʔληοτ
 ؅ཧΞϓϦ playground.megane.ai ֶशࡁΈϞσϧ഑ஔ ը૾ૹ৴ ൑ఆ݁Ռ .FHBOF$P
  9. ͳͥϞόΠϧΞϓϦʹ૊ΈࠐΉͷ͔ ϨΠςϯγ͕69ʹ༩͑ΔӨڹΛ࡟ݮ͢ΔͨΊ αʔόʔʹૹ৴͢Δʢ৺ཧతɾ๏తʣϋʔυϧ͕ߴ͍σʔλΛऔΓѻ͏ͨΊ  

  10. ϞόΠϧΞϓϦ΁ͷػցֶशϞσϧͷ૊ΈࠐΈ 5FOTPS'MPXGPS.PCJMF 5FOTPS'MPX-JUF .-,JUʢ'JSFCBTF.-,JUʣ  

  11. 5FOTPS'MPX-JUF σόΠε্Ͱͷਪ࿦ΛՄೳʹ͢ΔϑϨʔϜϫʔΫɻ 5FOTPS'MPXͷαϒηοτϥΠϯλΠϜͰɺར༻Ͱ ͖ͳ͍ΦϖϨʔγϣϯ͕͋Δɻ "OESPJEJ04ΤοδσόΠεʹରԠɻ   IUUQTXXXUFOTPSqPXPSHMJUF

  12. .-,JUCFUBʢ'JSFCBTF.-,JUʣ (PPHMF͕ఏڙ͢ΔαʔϏεͰɺ(PPHMF͕࡞੒ͨ͠ػցֶश ϞσϧΛ"OESPJEJ04ΞϓϦʹ૊ΈࠐΜͩΓɺΦϦδφϧͷ ΞϓϦΛ഑৴Ͱ͖Δɻ w7JTJPO w-BOHVBHF w$VTUPN   IUUQTEFWFMPQFSTHPPHMFDPNNMLJU

  13. .-,JU7JTJPO #BSDPEF4DBO 'BDF%FUFDUJPO *NBHF-BCFMJOH -BOENBSL%FUFDUJPO 0CKFDU%FUFDUJPO5SBDLJOH 5FYU3FDPHOJUJPO   IUUQTEFWFMPQFSTHPPHMFDPNNMLJU

  14. .-,JU-BOHVBHF -BOHVBHF*EFOUJpDBUJPO 0O%FWJDF5SBOTMBUJPO 4NBSU3FQMZ   IUUQTEFWFMPQFSTHPPHMFDPNNMLJU

  15. .-,JU$VTUPN ඞཁʹԠͨ͡Ϟσϧͷμ΢ϯϩʔυ ϞσϧͷࣗಈΞοϓσʔτ Ϟσϧͷ"#ςετ Ϟσϧͷಈతʢ%ZOBNJDʣͳબ୒   IUUQTEFWFMPQFSTHPPHMFDPNNMLJU

  16. ػցֶशϫʔΫϑϩʔ   σʔληοτͷ੔උ ϞσϧͷֶशͱධՁ ϞσϧͷσϓϩΠ ਪ࿦

  17. 'PPE(BMMFSZ ୺຤ʹอଘ͞Ε͍ͯΔࣸਅͷ৯΂෺͚ͩΛදࣔʢ৯΂෺ Ҏ֎Λಁաͯ͠දࣔʣͯ͠Ұཡ͢ΔΞϓϦɻ   IUUQTHJUIVCDPNLFJKJGPPE@HBMMFSZ@XJUI@UFOTPSqPX

  18. def _export_graph(sess, input_tensors, output_tensors, output_dir): output_path = os.path.join(output_dir, 'model.tflite') converter

    = TFLiteConverter.from_session(sess, input_tensors, output_tensors) # converter.post_training_quantize = True tflite_model = converter.convert() open(output_path, "wb").write(tflite_model)   Ϟσϧͷग़ྗʢ5FOTPS'MPX-JUFʣ
  19. val tfInference = Interpreter( model, options) val resizedImageBuffer = ByteBuffer

    .allocateDirect(IMAGE_BYTES_LENGTH) .order(ByteOrder.nativeOrder()) val inputBuffer = ByteBuffer .allocateDirect(IMAGE_BYTES_LENGTH * 4) .order(ByteOrder.nativeOrder()) val resultBuffer = ByteBuffer .allocateDirect(4) .order(ByteOrder.nativeOrder())   Ϟσϧͷ࣮ߦ JPLFJKJGPPEHBMMFSZ*NBHF3FDPHOJ[FSLU
  20. val scaledBitmap = Bitmap.createScaledBitmap(bitmap, IMAGE_WIDTH, IMAGE_HEIGHT, false) resizedImageBuffer.rewind() scaledBitmap.copyPixelsToBuffer(resizedImageBuffer) inputBuffer.rewind()

    for (index in (0..IMAGE_BYTES_LENGTH - 1)) { inputBuffer.putFloat(resizedImageBuffer[index].toInt().and(0xFF).toFloat()) } inputBuffer.rewind() resultBuffer.rewind() tfInference.run(inputBuffer, resultBuffer) resultBuffer.rewind() val confidence = resultBuffer.getFloat()   Ϟσϧͷ࣮ߦ JPLFJKJGPPEHBMMFSZ*NBHF3FDPHOJ[FSLU
  21. Ϟσϧͷ࣮ߦ   Input Output Interpreter tfInference inputBuffer resultBuffer લॲཧ

    σίʔυ
  22. ϞσϧΛ૊ΈࠐΉ্Ͱͷ՝୊ Ϟσϧͷେ͖͞ ࣮ߦ଎౓ ফඅϝϞϦ Ϟσϧͷอޢ ϢʔβʔϓϥΠόγʔ  

  23. .#Λ௒͑ΔϞσϧ   IUUQTHJUIVCDPNLFJKJGPPE@HBMMFSZ@XJUI@UFOTPSqPXSFMFBTFTUBH

  24. ϞσϧͷΞʔΩςΫνϟΛมߋ  

  25. ϞσϧʢύϥϝʔλʔʣͷྔࢠԽ   CJUුಈখ਺఺਺ΛCJU੔਺ʹม׵ʢྔࢠԽʣ

  26. ྔࢠԽͷબ୒ࢶ 1PTUUSBJOJOH2VBOUJ[BUJPO 2VBOUJ[BUJPOBXBSF5SBJOJOH  

  27. 1PTUUSBJOJOHRVBOUJ[BUJPO   def _export_graph(sess, input_tensors, output_tensors, output_dir): output_path =

    os.path.join(output_dir, 'model.tflite') converter = TFLiteConverter.from_session(sess, input_tensors, output_tensors) converter.post_training_quantize = True tflite_model = converter.convert() open(output_path, "wb").write(tflite_model)
  28. if model.QUANTIZATION: g = tf.get_default_graph() tf.contrib.quantize.create_training_graph(input_graph=g, quant_delay=2000000)   IUUQTHJUIVCDPNUFOTPSqPXUFOTPSqPXUSFFSUFOTPSqPXDPOUSJCRVBOUJ[F

    2VBOUJ[BUJPOBXBSFUSBJOJOH
  29. ϞσϧΛྔࢠԽ  

  30. "OESPJE/FVSBM/FUXPSLT"1* ϞόΠϧ୺຤্ͰػցֶशͷܭࢉॲཧΛ࣮ߦ͢ΔͨΊʹઃܭ͞Εͨɻ IUUQTEFWFMPQFSBOESPJEDPNOELHVJEFTOFVSBMOFUXPSLT "OESPJEʢ"1*ϨϕϧʣҎ߱ͰରԠɻ    IUUQTCMPHLFJKJJPUFOTPSqPXBEWFOU@DBMFOEBSIUNM ͍·//"1*ʢ5FOTPS'MPX-JUFʣ͸࢖͑Δͷ͔

  31. ਪ࿦଎౓ͷൺֱ   ػछ໊ NN API͋Γ NN APIͳ͠ Essential PH-1

    556,323ns 185,372,624ns Pixel 2 450,807ns 187,395,464ns Pixel 3 477,489ns 129,994,563ns IUUQTHJUIVCDPNLFJKJGPPE@HBMMFSZ@XJUI@UFOTPSqPXSFMFBTFTUBHUqJUF@OOBQJ
  32. ͞·͟·ͳ੍໿ εΧϥʔͰͷԋࢉ͕Ͱ͖ͳ͍ɻʷOPSNBMJ[FE@JNBHFJNBHF@QI  εϥΠε͕࢖͑ͳ͍ɻʷJNBHFJNBHF<   > )ZQFSCPMJD5BOHFOU͕࢖͑ͳ͍ɻʷPVUQVUUGUBOI PVU@P⒎TFU 

     IUUQTXXXUFOTPSqPXPSHMJUFHVJEFPQT@DPNQBUJCJMJUZVOTVQQPSUFE@PQFSBUJPOT
  33.   ਫ਼౓͕ۃ୺ʹ௿Լ

  34.   max: 14.586626 min: -3.8083103 ϞσϧΛߏ੒͍ͯ͠Δύϥϝʔλʔͷ࠷େɾ࠷খ஋Λ֬ೝ

  35. Ϟσϧઃܭͷ࣌఺Ͱʮଌఆͱௐ੔ʯ   σʔληοτͷ੔උ ϞσϧͷֶशͱධՁ ϞσϧͷσϓϩΠ ਪ࿦ Ϟσϧͷઃܭ

  36. ଌఆʹج͍ͮͨϞσϧͷௐ੔   Ϟσϧͷઃܭ Ϟσϧͷௐ੔ TensorFlow Lite΁ม׵ ʢྔࢠԽʣ αΠζɾ࣮ߦ଎౓
 ଌఆ

  37. ΞϓϦଆͰͷ଎౓վળ /BWJFSגࣜձࣾ φϏΤʣ ౦ژ౎จژ۠ຊڷຊڷ࢛ஸ໨Ϗϧ' σΟʔϓϥʔχϯάΛ༻͍ͨը૾ม׵ٕज़ͷ։ൃ͓Αͼιϑτ΢ΣΞͷఏڙ   IUUQTXXXOBWJFSDP Ϟσϧ͸มߋͤͣɺ࣮ߦ଎౓Λ̏ʙ̐ഒʹߴ଎Խ

  38. Ϟσϧͷอޢ ʰΞϓϦʹ૊ΈࠐΉʹ౰ͨͬͯɺϞσϧʢΞʔΩςΫνϟɾ ύϥϝʔλʔʣ͕֎෦ʹྲྀग़͠ͳ͍Α͏ʹอޢ͍ͨ͠ʱ  

  39. Ϟσϧͷܗࣜ 5FOTPS'MPX-JUFͷϞσϧ͸'MBU#V⒎FSTɻ 'MBU#V⒎FST͸ɺσʔλͷల։΍ύʔεΛͤͣετϨʔδ ্ͷσʔλʹϝϞϦΞυϨεΛϚοϓͯ͠ΞΫηε͢Δ ͜ͱͰɺϝϞϦͷϑοτϓϦϯτΛ࡟ݮ͢Δ
 ʢʹ҉߸Խͨ͠'MBU#V⒎FSTͷϑΝΠϧ͸ɺಁաతʹಡΈ ࠐΉ͜ͱ͕Ͱ͖ͳ͍ʣɻ  

  40. ෮߸Խͯ͠Ұ౓ϩʔΧϧϑΝΠϧʹอଘ   assets app local ϑΝΠϧಡΈࠐΈ Interpreter ෮߸Խॲཧ

  41. ϢʔβʔϓϥΠόγʔ ػցֶशͷϞσϧΛܧଓతʹվળ͢ΔͨΊʹ͸ɺσʔλ͕ඞཁɻ Ϣʔβʔͷ͍ΔΞϓϦͷ৔߹ɺϢʔβʔ͔ΒσʔλΛఏڙʢૹ৴ɾอଘʣ͢Δ ߹ҙΛಘΔඞཁ͕͋Δɻ ϓϥΠόγʔσʔλͷऔΓѻ͏ମ੍Λ੔͑Δඞཁ͕͋Δɻσʔλͷ಺༰ʹΑͬ ͯ͸๏཯ʹΑΔن੍΋͋Δɻ  

  42. 'FEFSBUFE-FBSOJOH ͢΂ͯͷσʔληοτΛαʔόʔ্Ͱॲཧ͢ΔʮूதτϨʔχϯάʯͱ͸ҟͳ ΓɺҰͭҰͭͷ୺຤্ͰϞσϧͷֶशͷલஈॲཧΛߦ্ͬͨͰɺαʔόʔʹૹ ৴ͯ͠ฏۉԽ͢Δɻ   IUUQTEFWFMPQFSTKQHPPHMFCMPHDPNGFEFSBUFEMFBSOJOHDPMMBCPSBUJWFIUNM

  43. C-LIS CO., LTD. ຊࢿྉ͸ɺ༗ݶձࣾγʔϦεͷஶ࡞෺Ͱ͢ɻຊࢿྉͷશ෦ɺ·ͨ͸Ұ෦ʹ͍ͭͯɺஶ࡞ऀ͔ΒจॻʹΑΔڐ୚Λಘͣʹෳ੡͢Δ͜ͱ͸ې͡ΒΕ͍ͯ·͢ɻ 5IF"OESPJE4UVEJPJDPOJTSFQSPEVDFEPSNPEJpFEGSPNXPSLDSFBUFEBOETIBSFECZ(PPHMFBOEVTFEBDDPSEJOHUPUFSNTEFTDSJCFEJOUIF$SFBUJWF$PNNPOT"UUSJCVUJPO-JDFOTF ֤੡඼໊ɾϒϥϯυ໊ɺձ໊ࣾͳͲ͸ɺҰൠʹ֤ࣾͷ঎ඪ·ͨ͸ొ࿥঎ඪͰ͢ɻຊࢿྉதͰ͸ɺ˜ɺšɺäΛׂѪ͍ͯ͠·͢ɻ 5IF"OESPJESPCPUJTSFQSPEVDFEPSNPEJpFEGSPNXPSLDSFBUFEBOETIBSFECZ(PPHMFBOEVTFEBDDPSEJOHUPUFSNTEFTDSJCFEJOUIF$SFBUJWF$PNNPOT"UUSJCVUJPO-JDFOTF