エッジAIとPython

 エッジAIとPython

Presentation Slides at Python Kansai #1 https://kansai-python.connpass.com/event/135610/

227382dbd5e033db211c159edf32853c?s=128

Hacarus Inc.

July 14, 2019
Tweet

Transcript

  1. 2.

    છా وࢤ • !ULTNE JO4/4 • גࣜձࣾϋΧϧε औక໾ $50 •

    ژ౎େֶେֶӃ ৘ใֶݚڀՊଔ • 1ZUIPOྺ ೥ • .BDIJOF-FBSOJOH.FFUVQ ,"/4"*্ཱͪ͛
  2. 7.

    Ϋϥ΢υ"*WTΤοδ"* • ϦΞϧλΠϜͳԠ౴ • ωοτϫʔΫଳҬͷ࡟ݮ • ηΩϡϦςΟɾϓϥΠόγʔͷอޢ Ϋϥ΢υ"* Τοδ"* ֶश

    ਪ࿦ ֶश ਪ࿦ • ५୔ͳίϯϐϡʔςΟϯ άϦιʔε • ڊେͳετϨʔδ • ඇྗͳίϯϐϡʔςΟϯ άϦιʔε • ݶΒΕͨετϨʔδ • ઐ༻ϋʔυ΢ΣΞ΋͘͠ ͸ιϑτ΢ΣΞ࣮૷ͷ޻ ෉ʹΑΔΞΫηϥϨʔ γϣϯ
  3. 9.

    ϋʔυ΢ΣΞͷλΠϓͱσόΠεྫ λΠϓ ൚༻04ͷ༗ແ σόΠεྫ 4JOHMF#PBSE$PNQVUFS $16(164P$ -JOVY 3BTQCFSSZ1J# ɾ#SPBEDPN#$.#QZWJEFPDPSF /7*%*"+FUTPO/BOP%FWFMPQFS,JU

    ɾDPSF.BYXFMMKFUTPOJOGFSFODF 64#"DDFMFSBUPS "4*$ ແ͠ *OUFM/FVSBM$PNQVUF4UJDL ɾ.ZSJBE97160QFO7*/0 (PPHMF$PSBM64#"DDFMFSBUPS ɾ(PPHMF&EHF5165FOTPS'MPX-JUF ϚΠίϯ $164P$ ແ͠ 4POZ413&4&/4& ɾ"3.$PSUFY.'%//35ϥΠϒϥϦ 4JQFFE."JY.%PDL ɾ3*4$7,FOESZUF ੡ ,.BJY1Z '1(" σόΠε࣍ୈ 1:/2; ɾ;ZOR;#//1:/2 %.1;*"$,JU ɾ;ZOR6MUSB4DBMF ;6$(ઐ༻4%, ೥݄࣌఺Ͱ͓খݣ͍ͷൣғ಺Ͱ೔ຊͰೖखՄೳͳ΋ͷΛத৺ʹ঺հ '1("Ҏ֎
  4. 10.

    Ϋϥ΢υΛ׆༻ͨ͠ "*P5 "84Ͱͷྫ • σόΠεͷ؅ཧɾϞχλ Ϧϯά • ΞϓϦέʔγϣϯɾ"*Ϟ σϧͷߋ৽ •

    Ϋϥ΢υετϨʔδ΁ͷ σʔλͷอଘ AWS IoT • εςʔλεͷಉظ • σόΠεσʔλͷ ૹ৴
  5. 14.

    /7*%*"+FUTPO/BOP%FWFMPQFS,JU ॲཧνοϓ • $162VBEDPSF"3."!()[ • (16ɿDPSF.BYXFMM ϝϞϦ • (#CJU-1%%3 04

    • -JOVY5FHSB +FU1BDL 6CVOUV૬౰ 1ZUIPO࣮ߦ؀ڥ • σϑΥϧτ͸ ͱ  • ೚ҙͷ΋ͷΛΠϯετʔϧ͢Δ͜ͱ΋Մೳ ϑϨʔϜϫʔΫ • 5FOTPS'MPX $BGGF "QBDIF .9/FU 0QFO/FVSBM /FUXPSL&YDIBOHF 0//9 1Z5PSDI FUD ͓஋ஈ •  +1: 48*5$)4$*&/$& • ిݯͱϚΠΫϩ4%͸ผ్ߪೖ͕ඞཁ ͦͷଞ • KFUTPOJOGFSFODFͰ͸ $ 1ZUIPOͷ "1*͕ఏڙ͞ΕΔ • 1Z5PSDI Λ࢖ͬͨΤοδͰͷసҠֶशͷαϯϓϧ͋Γ
  6. 15.

    /7*%*"+FUTPO/BOP%FWFMPQFS,JU import jetson.inference import jetson.utils img, width, height = jetson.utils.loadImageRGBA('face.png')

    net = jetson.inference.detectNet('facenet') detections = net.Detect(img, width, height) jetson.utils.cudaDeviceSynchronize() jetson.utils.saveImageRGBA('output.png', img, width, height) IUUQTHJUIVCDPNEVTUZOWKFUTPO JOGFSFODFCMPCNBTUFSEPDTEFUFDUOFUDPOTPMFNE
  7. 17.

    *OUFM/FVSBM$PNQVUF4UJDL ॲཧνοϓ • *OUFM.PWJEJVT .ZSJBE97JTJPO1SPDFTTJOH6OJU γεςϜཁ݅ • 6CVOUV-54 CJU $FOU04

    CJU • 3BTQCJBO 3BTQCFSSZ1J# ͸৘ใଟ͍ • 8JOEPXT CJU • 64#5ZQF"ʹͯϗετͱ઀ଓ 1ZUIPO࣮ߦ؀ڥ • ಛʹ੍ݶͳ͠ ϑϨʔϜϫʔΫ • 5FOTPS'MPX $BGGF "QBDIF .9/FU 0QFO/FVSBM /FUXPSL&YDIBOHF 0//9 1Z5PSDI ͓஋ஈ •  +1: 48*5$)4$*&/4& ͦͷଞ • 0QFO7*/0UPPMLJU ʹͯ $ 1ZUIPOͷ "1*͕ఏڙ • 0QFO$7ܦ༝Ͱͷݺͼग़͠΋Մೳ
  8. 18.

    *OUFM/FVSBM$PNQVUF4UJDL import cv2 net = cv2.dnn.readNet('face-detection-adas-0001.xml', 'face-detection-adas-0001.bin') net.setPreferableTarget(cv2.dnn.DNN_TARGET_MYRIAD) img =

    cv2.imread('face.png') blob = cv2.dnn.blobFromImage(img, 1.0, ddepth=cv2.CV_8U) net.setInput(blob) ans = net.forward() for detection in ans.reshape(-1, 7): confidence = float(detection[2]) if confidence > 0.5: xmin = int(detection[3] * img.shape[1]) ymin = int(detection[4] * img.shape[0]) xmax = int(detection[5] * img.shape[1]) ymax = int(detection[6] * img.shape[0]) cv2.rectangle(img, (xmin, ymin), (xmax, ymax), (0, 255, 0)) cv2.imwrite('output.png', img) IUUQTEPDTPQFODWPSHNBTUFSEEUVUPSJBM@UBCMF@PG@DPOUFOU@E OOIUNM
  9. 20.

    (PPHMF$PSBM64#"DDFMFSBUPS ॲཧνοϓ • (PPHMF&EHF516.-BDDFMFSBUPSDPQSPDFTTPS γεςϜཁ݅ • %FCJBOҎ͓߱Αͼͦͷ೿ੜܥ 6CVOUV • Y΋͘͠͸

    "3.XJUI"3.WJOTUSVDUJPOTFU • 64#5ZQF$ʹͯϗετͱ઀ଓ 1ZUIPO࣮ߦ؀ڥ • 1ZUIPO͕ݱ࣌఺Ͱ͸҆શ ϑϨʔϜϫʔΫ • 5FOTPS'MPX-JUF ͓஋ஈ •  +1: .PVTFS ͦͷଞ • $ 1ZUIPOͷ "1*͕ఏڙ • ը૾෼ྨʹؔͯ͠͸ΤοδͰͷసҠֶश͕Մೳ • "VUP.- 7JTJPO&EHFͰੜ੒ͨ͠ϞσϧΛಡΈࠐΈՄೳ
  10. 21.

    (PPHMF$PSBM64#"DDFMFSBUPS from edgetpu.detection.engine import DetectionEngine from PIL import Image, ImageDraw

    engine = DetectionEngine('mobilenet_ssd_v2_face_quant_postprocess_edgetpu.tflite') img = Image.open('face.png') draw = ImageDraw.Draw(img) ans = engine.DetectWithImage(img, threshold=0.05, keep_aspect_ratio=True, relative_coord=False, top_k=10) if ans: for obj in ans: box = obj.bounding_box.flatten().tolist() # Draw a rectangle. draw.rectangle(box, outline='red') img.save('output.png') IUUQTDPSBMXJUIHPPHMFDPNEPDTSFGFSFODFFEHFUQVEFUFDUJPOFOH JOF
  11. 23.

    4JQFFE."JY .%PDL ॲཧνοϓ • 3*4$7%VBM$PSFCJU XJUI'16 • ,16 $//BDDFMFSBUPS 04

    • 'SFF3504 1ZUIPO࣮ߦ؀ڥ • .BJY1Z .JDSP1ZUIPO ͷϙʔςΟϯά ֦ு ϑϨʔϜϫʔΫ • 5FOTPS'MPX ,FSBT %BSLOFU ͓஋ஈ •  +1: 48*5$)4$*&/$& ͦͷଞ • υΩϡϝϯτɾαϯϓϧίʔυͱ࣮ࡍͷ࣮ߦ؀ڥͱͷ৯͍ҧ ͍͕νϥϗϥʜ • Կނ͔ /&4ͷ࣮ߦ؀ڥ͕ண͍͍ͯΔʜ
  12. 24.

    4JQFFE."JY .%PDL import sensor import image import lcd import KPU

    as kpu lcd.init() sensor.reset() sensor.set_pixformat(sensor.RGB565) sensor.set_framesize(sensor.QVGA) sensor.set_hmirror(0) sensor.run(1) task = kpu.load(0x300000) # you need put model(face.kfpkg) in flash at address 0x300000 anchor = (1.889, 2.5245, 2.9465, 3.94056, 3.99987, 5.3658, 5.155437, 6.92275, 6.718375, 9.01025) a = kpu.init_yolo2(task, 0.5, 0.3, 5, anchor) img = sensor.snapshot() code = kpu.run_yolo2(task, img) if code: for i in code: print(i) a = img.draw_rectangle(i.rect()) a = lcd.display(img) a = kpu.deinit(task) IUUQTNBJYQZTJQFFEDPNFOMJCT.BJYLQVIUNM
  13. 25.
  14. 26.

    • ओʹਪ࿦ॲཧΛΤοδଆʹΦϑϩʔ υ͢Δ͜ͱʹΑΓɺҎԼࡾ఺ͷվળ ΛਤΔ • Ԡ౴଎౓ • ηΩϡϦςΟɾϓϥΠόγʔ • ωοτϫʔΫଳҬ

    • ӡ༻ɾ؅ཧʹ͸Ϋϥ΢υͱͷ઀ଓΛ ֬อ͢Δํ͕٢ Τοδ"*ͱ͸ • ҰൠతʹඇྗͳΤοδσόΠεͷೳ ྗΛิ׬͢ΔͨΊʹɺҎԼͷΑ͏ͳ ༷ʑͳܗࣜͷઐ༻ϋʔυ΢ΣΞ͕։ ൃ͞Ε͍ͯΔ • 4#$ • 64#"DDFMBSBUPS • ϚΠίϯ • '1(" Τοδ"*޲͚σόΠε ຊ೔ͷτʔΫͰ͓࣋ͪؼΓ͍͖͍ͨͩͨࣄ ࠶ • ϋʔυ΢ΣΞʹ͋Θͤͯɺ"1*4%, ͕ఏڙ͞Ε͍ͯΔɻݴޠ͸ $ 1ZUIPO͋ͨΓ͕ϙϐϡϥʔ • ਪ࿦ॲཧࣗମͷهड़͸׳Εͯ͠·͑ ͹ɺେ͖ͳҧ͍͸ͳ͍ • طʹߏங͞ΕͨωοτϫʔΫΛϋʔ υ΢ΣΞ࠷దԽͯ͠ར༻͠ɺม׵ઐ ༻πʔϧ͕ఏڙ͞Ε͍ͯΔࣄ΋ଟ͍ 1ZUIPOΛͲ͏࢖͏ͷ͔ 1ZUIPO੒෼ গͳͯ͘ ͢Έ·ͤΜ
  15. 27.

    w +FUTPO/BOP%FWFMPQFS,JU ߏ੒Λγϯϓϧʹ͍ͨ͠ w (PPHMF$PSBM w %FW#PBSEͷٕదΛ଴ͭ ͱʹ͔͘؆୯ʹ͍ͨ͠ w 3BTQCFSSZ1Jϕʔε

    w 3BTQCFSSZ1JͷٕదΛ଴ͭ ࢄʑ͍ΖΜͳηϯαʔͭ ͳ͛ͯ༡ͼ͍ͨ w 3*4$7ܥ w 4J'JWF ͷ -JOVYϘʔυͳͲ ͻͱϠϚ౰͍ͯͨɺ͍҆ ͷҰ൪ w '1("ͿͬࠐΈ ϋʔυίΞʹੜ͖͍ͨ Ͱɺ݁ہΦεεϝ͸ʁ