Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Visionで変わるiOSのアプリ開発

 Visionで変わるiOSのアプリ開発

Developers.IO 2017 WORLD in 福岡で「Visionで変わるiOSのアプリ開発」という内容で登壇しました。

[10/29(日)『Developers.IO 2017 WORLD in 福岡』を開催します!](http://dev.classmethod.jp/news/developers-io-2017-world-fukuoka/)

Takaaki Tanaka

October 29, 2017
Tweet

More Decks by Takaaki Tanaka

Other Decks in Technology

Transcript

  1. ը૾ղੳ  3FRVFTU wը૾ʹରͯ͠ͲͷΑ͏ͳཁٻΛߦ͏͔ʹΑͬͯΫϥεΛ࢖͍෼͚Δ
   إݕग़   7/%FUFDU'BDF3FDUBOHMFT3FRVFTU

      إϥϯυϚʔΫݕग़   7/%FUFDU'BDF-BOENBSLT3FRVFTU   ը૾ϨδετϨʔγϣϯ   7/*NBHF3FHJTUSBUJPO3FRVFTU   ۣܗݕग़   7/%FUFDU3FDUBOHMFT3FRVFTU   όʔίʔυݕग़   7/%FUFDU#BSDPEFT3FRVFTU   ςΩετݕग़   7/%FUFDU5FYU3FDUBOHMFT3FRVFTU   ΦϒδΣΫττϥοΩϯά   7/5SBDL0CKFDU3FRVFTU
  2. ը૾ղੳ  0CTFSWBUJPO wཁٻ͔ΒฦͬͯདྷΔ݁Ռ
  إݕग़   7/'BDF0CTFSWBUJPO 

    إϥϯυϚʔΫݕग़   7/'BDF0CTFSWBUJPO  ը૾ϨδετϨʔγϣϯ   7/*NBHF"MJHONFOU0CTFSWBUJPO  ۣܗݕग़   7/3FDUBOHMF0CTFSWBUJPO  όʔίʔυݕग़   7/#BSDPEF0CTFSWBUJPO  ςΩετݕग़   7/5FYU0CTFSWBUJPO  ΦϒδΣΫττϥοΩϯά   7/%FUFDUFE0CKFDU0CTFSWBUJPO
  3. ը૾ղੳ  ࣮૷ wཉ͍͠ը૾ղੳʹରԠͨ͠3FRVFTUΛ 7/*NBHF3FRVFTU)BOEFS΁౉͢
 let request = VNDetectFaceRectanglesRequest {

    (request, error) in for observation in request.results as! [VNFaceObservation] { // TODO: VNFaceObservationΛݩʹॲཧΛ͢Δ } if let cgImage = image.cgImage { let handler = VNImageRequestHandler(cgImage: cgImage, options: [:]) try? handler.perform([request]) }
  4. ը૾ղੳ  ࣮૷ wཉ͍͠ը૾ղੳʹରԠͨ͠3FRVFTUΛ 7/*NBHF3FRVFTU)BOEFS΁౉͢
 let request = VNDetectFaceRectanglesRequest {

    (request, error) in for observation in request.results as! [VNFaceObservation] { // TODO: VNFaceObservationΛݩʹॲཧΛ͢Δ } if let cgImage = image.cgImage { let handler = VNImageRequestHandler(cgImage: cgImage, options: [:]) try? handler.perform([request]) } إݕग़༻ͷ7/3FRVFTUΛ࡞੒
  5. ը૾ղੳ  ࣮૷ wཉ͍͠ը૾ղੳʹରԠͨ͠3FRVFTUΛ 7/*NBHF3FRVFTU)BOEFS΁౉͢
 let request = VNDetectFaceRectanglesRequest {

    (request, error) in for observation in request.results as! [VNFaceObservation] { // TODO: VNFaceObservationΛݩʹॲཧΛ͢Δ } if let cgImage = image.cgImage { let handler = VNImageRequestHandler(cgImage: cgImage, options: [:]) try? handler.perform([request]) } 7/*NBHF3FRVFTU)BOEMFS࡞੒࣌ʹإݕग़Λߦ͍ͨ ͍ը૾Λࢦఆ
  6. ը૾ղੳ  ࣮૷ wཉ͍͠ը૾ղੳʹରԠͨ͠3FRVFTUΛ 7/*NBHF3FRVFTU)BOEFS΁౉͢
 let request = VNDetectFaceRectanglesRequest {

    (request, error) in for observation in request.results as! [VNFaceObservation] { // TODO: VNFaceObservationΛݩʹॲཧΛ͢Δ } if let cgImage = image.cgImage { let handler = VNImageRequestHandler(cgImage: cgImage, options: [:]) try? handler.perform([request]) } 3FRVFTUΛҾ਺ʹࢦఆͯ͠QFSGPSNΛίʔϧ
  7. ը૾ղੳ  ࣮૷ wཉ͍͠ը૾ղੳʹରԠͨ͠3FRVFTUΛ 7/*NBHF3FRVFTU)BOEFS΁౉͢
 let request = VNDetectFaceRectanglesRequest {

    (request, error) in for observation in request.results as! [VNFaceObservation] { // TODO: VNFaceObservationΛݩʹॲཧΛ͢Δ } if let cgImage = image.cgImage { let handler = VNImageRequestHandler(cgImage: cgImage, options: [:]) try? handler.perform([request]) } ը૾͔Βࢦఆͨ͠ϦΫΤετʹϚονͨ݁͠Ռ͕ม͑ ͯདྷΔͱɺSFRVFTUͷSFTVMUTʹղੳ݁Ռ͕ฦͬͯ͘Δ
  8. ը૾ղੳ  ࣮૷ wࢼ͠ʹ݁ՌΛड͚औͬͯΈΔ
 let request = VNDetectFaceRectanglesRequest { (request,

    error) in for observation in request.results as! [VNFaceObservation] { print(observation) } if let cgImage = image.cgImage { let handler = VNImageRequestHandler(cgImage: cgImage, options: [:]) try? handler.perform([request]) }
  9. ը૾ղੳ  ࣮૷ wࢼ͠ʹ݁ՌΛड͚औͬͯΈΔ
 let request = VNDetectFaceRectanglesRequest { (request,

    error) in for observation in request.results as! [VNFaceObservation] { print(observation) } if let cgImage = image.cgImage { let handler = VNImageRequestHandler(cgImage: cgImage, options: [:]) try? handler.perform([request]) } <VNFaceObservation: 0x604000182700> 68149739- D1B0-4E89-8FB2-44F33969FAED 1 [0.557461 0.616566 0.069802 0.0930694] ID=0 <VNFaceObservation: 0x6040001828a0> D113842C- B9CA-4D70-88CE-74814860D383 1 [0.722581 0.400897 0.0740046 0.0986728] ID=0 <VNFaceObservation: 0x600000182e50> 69A72E48-0270-4687- B0B4-4F57A8E5DEA3 1 [0.28446 0.639232 0.0771421 0.102856] ID=0
  10. ը૾ղੳ  7/'BDF0CTFSWBUJPOͷར༻ wը૾αΠζʹରԠ͢Δൺ཰Ͱݕग़Օॴͷۣܗ৘ ใ͕ฦͬͯདྷΔ w ݪ఺   

    w αΠζ   <VNFaceObservation: 0x6040001828a0> D113842C- B9CA-4D70-88CE-74814860D383 1 [0.722581 0.400897 0.0740046 0.0986728] ID=0
  11. 7JTJPO $PSF.-  طଘͷֶशϞσϧͷೖख w෺ମೝࣝ w .PCJMF/FU w 4RVFF[F/FU w

    3FT/FU w *ODFQUJPOW wγʔϯೝࣝ w 1MBDF(PPH-F/FU
  12. 7JTJPO $PSF.-  ࣮૷ wར༻͢Δ.-.PEFMΫϥεΛ7/$PSF.-.PEFM Ϋϥεʹม׵
 guard let mlmodel =

    MobileNet().model() else { return } guard let coreMLModel = try? VNCoreMLModel(for: mlmodel) else { fatalError("faild create VMCoreMLModel") }
  13. 7JTJPO $PSF.-  ࣮૷ w7/$PSF.-.PEFMʹରԠͨ͠3FRVFTUΛ 7/*NBHF3FRVFTU)BOEFS΁౉͢
 let request = VNCoreMLRequest(model:

    coreMLModel) { request, error in let results = request.results as? [VNClassificationObservation] // TODO: VNClassificationObservationͷ݁ՌͰॲཧΛߦ͏ } let handler = VNImageRequestHandler(ciImage: ciImage, options: [:]) guard (try? handler.perform([request])) != nil else { fatalError("faild handler.perform") } } ར༻ֶ͍ͨ͠शϞσϧΛݩʹ7/$PSF.-3FRVFTUΛ ੜ੒
  14. 7JTJPO $PSF.-  ࣮૷ w7/$PSF.-.PEFMʹରԠͨ͠3FRVFTUΛ 7/*NBHF3FRVFTU)BOEFS΁౉͢
 let request = VNCoreMLRequest(model:

    coreMLModel) { request, error in let results = request.results as? [VNClassificationObservation] // TODO: VNClassificationObservationͷ݁ՌͰॲཧΛߦ͏ } let handler = VNImageRequestHandler(ciImage: ciImage, options: [:]) guard (try? handler.perform([request])) != nil else { fatalError("faild handler.perform") } } 7/*NBHF3FRVFTU)BOEMFS࡞੒࣌ʹֶशϞσϧͷ݁ ՌΛฦ͍ͨ͠ը૾Λࢦఆ
  15. 7JTJPO $PSF.-  ࣮૷ w7/$PSF.-.PEFMʹରԠͨ͠3FRVFTUΛ 7/*NBHF3FRVFTU)BOEFS΁౉͢
 let request = VNCoreMLRequest(model:

    coreMLModel) { request, error in let results = request.results as? [VNClassificationObservation] // TODO: VNClassificationObservationͷ݁ՌͰॲཧΛߦ͏ } let handler = VNImageRequestHandler(ciImage: ciImage, options: [:]) guard (try? handler.perform([request])) != nil else { fatalError("faild handler.perform") } } 3FRVFTUΛҾ਺ʹࢦఆͯ͠QFSGPSNΛίʔϧ
  16. 7JTJPO $PSF.-  ࣮૷ w7/$PSF.-.PEFMʹରԠͨ͠3FRVFTUΛ 7/*NBHF3FRVFTU)BOEFS΁౉͢
 let request = VNCoreMLRequest(model:

    coreMLModel) { request, error in let results = request.results as? [VNClassificationObservation] // TODO: VNClassificationObservationͷ݁ՌͰॲཧΛߦ͏ } let handler = VNImageRequestHandler(ciImage: ciImage, options: [:]) guard (try? handler.perform([request])) != nil else { fatalError("faild handler.perform") } } ը૾͔Βࢦఆͨ͠ϦΫΤετʹϚονͨ݁͠Ռ͕ม͑ ͯདྷΔͱɺSFRVFTUͷSFTVMUTʹղੳ݁Ռ͕ฦͬͯ͘Δ
  17. .-.0%&-ͷ࡞੒  ,FSBTͷ$*'"3αϯϓϧ model = Sequential() model.add(Conv2D(32, (3, 3), padding='same',

    input_shape=X_train.shape[1:])) model.add(Activation('relu')) model.add(Conv2D(32, (3, 3))) model.add(Activation('relu')) model.add(MaxPooling2D(pool_size=(2, 2))) model.add(Dropout(0.25)) model.add(Conv2D(64, (3, 3), padding='same')) model.add(Activation('relu')) model.add(Conv2D(64, (3, 3))) model.add(Activation('relu')) model.add(MaxPooling2D(pool_size=(2, 2))) model.add(Dropout(0.25)) model.add(Flatten()) model.add(Dense(512)) model.add(Activation('relu')) model.add(Dropout(0.5)) model.add(Dense(nb_classes)) model.add(Activation('softmax')) model.compile(loss='categorical_crossentropy', optimizer='rmsprop', metrics=['accuracy'])
  18. .-.0%&-ͷ࡞੒  .-.0%&-΁ͷม׵ w,FSBT͕࡞੒ֶͨ͠शϞσϧΛDPSFNMUPPMTΛ ࢖ͬͯ.-.0%&-΁ม׵͢Δ
 path = './model.h5' import coremltools

    coreml_model = coremltools.converters.keras.convert(path, input_names = 'image', image_input_names = 'image', class_labels = 'labels.txt') coreml_model.save('Food.mlmodel')
  19. ँࣙ   <J04>ը૾ղੳϑϨʔϜϫʔΫ7JTJPOͰإೝࣝΛࢼͨ݁͠Ռ  <J04>7JTJPO'SBNFXPSLͰը૾ͷࣝผΛࢼͯ͠Έ·ͨ͠88%$  <J04>$PSF.-Ͱը૾ͷࣝผΛࢼͯ͠Έ·ͨ͠ʢ7JTJPO'SBNFXPSLΛ࢖Θ ͳ͍ύλʔϯʣ88%$ 

    <J04>Ի੠ೝ͔ࣝΒಘͨจষͷܗଶૉղੳͱ඼ࢺ෼ղΛͯ͠Έͨ  ,FSBTͰ͸͡ΊΔ%FFQ-FBSOJOH  ஶ໊ͳσΟʔϓϥʔχϯάϑϨʔϜϫʔΫΛαϙʔτ͢Δ"84७ਖ਼".*ɿʮ"84 %FFQ-FBSOJOH".*ʯ  J04%$Ͱ$PSF.-ͷ࿩Λ͖ͯ͠·ͨ͠ʢ͋Δ͍͸๏཯૬ஊࣄ຿ॴʹߦͬͯ ͖ͨ࿩ʣ  5FOTPS'MPXʹΑΔ΋΋Ϋϩϝϯόʔإೝࣝʢલฤʣ  ,FSBT J04$PSF.- 7JTJPO'SBNFXPSLʹΑΔɺ΋΋ΫϩإࣝผΞϓ Ϧͷ։ൃ