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

Caffeでお手軽本格ディープラーニングiOSアプリ

 Caffeでお手軽本格ディープラーニングiOSアプリ

@potatotips #22
#DeepLearning #MachineLearning

C751122503efdfb6b4849730922c9879?s=128

Takuya Matsuyama

October 13, 2015
Tweet

Transcript

  1. $B⒎FͰ͓खܰຊ֨ σΟʔϓϥʔχϯά J04ΞϓϦ 5",6:" !OPSBEBJLP QPUBUPUJQT

  2. দࢁ୓໼ w !OPSBEBJLP w ϑϦʔϥϯε೥໨ ݩ:BIPP  w J04ΞϓϦ ΢ΣϒΞϓϦͳͲΛ੍࡞

    w ػցֶशʹڵຯ͋Γ w ֆ΋ඳ͖·͢ 2
  3. ΊΜ͖͖ ໙ར͖ 3

  4. 4 ໙ར͖ ࣸਅʹج͍ͮͯϥʔϝϯ԰Λਪન͢ΔΞϓϦ ೖྗ

  5. 5 σΟʔϓϥʔχϯά ͷٕज़Λ࢖༻ ʴ ʹ

  6. ը૾ೝࣝʹڧ͍ ػցֶशΞϧΰϦζϜ 6 σΟʔϓϥʔχϯάͱ͸

  7. w ೴ͷਆܦߏ଄Λ໛฿ͨ͠χϡʔϥϧωοτϫʔΫͷҰछ w େྔͷσʔλ͔Β෺ମͷಛ௃Λࣗಈతʹֶश ‣ ͜Ε·Ͱ͸ಛ௃ͷநग़ํ๏͸ਓ͕͕ؒΜ͹ͬͯ༻ҙ͍ͯͨ͠ 7 

  8. ࡞Ζ͏ σΟʔϓϥʔχϯάΞϓϦ ୭Ͱ΋؆୯ʹ࡞ΕΔํ๏Λ͝঺հ͠·͢ 8

  9. $B⒎F σΟʔϓϥʔχϯά༻ ϑϨʔϜϫʔΫ w IUUQDB⒎FCFSLFMFZWJTJPOPSH w (16ԋࢉ $6%" Ͱߴ଎ʹֶशͰ͖Δ w

    ͙͢ʹࢼͤΔֶशࡁΈϞσϧ΋͋Δ w .BD049ରԠ 9
  10. Caffe for J04্Ͱಈ͘$B⒎F w IUUQTHJUIVCDPNBMFQIDB⒎F w $B⒎FͷGPSL w J04্Ͱࣝผॲཧ͕࣮༻ʹ଱͑Δ଎౓Ͱಈ͔ͤΔ ‣

    J1IPOFTͰʙඵ w αʔό͍ΒͣͰ࢖͑Δ w ͨͩ͠9$PEF͸·ͩඇରԠ 10
  11. $B⒎FGPSJ04 αϯϓϧ࡞Γ·ͨ͠ w IUUQTHJUIVCDPNOPSBEBJLP DB⒎FJPTTBNQMF w ୯७ͳ෺ମೝࣝ w #-7$$B⒎F/FU.PEFMΛ࢖༻ 11

  12. demo

  13. ࢖༻͢Δσʔλ w MBCFMTUYUࣝผ݁ՌΛ໊લʹม׵͢ΔͨΊͷҰཡ w EFQMPZQSPUPUYUωοτϫʔΫఆٛ w NFBOCJOBSZQSPUPฏۉը૾ w CWMD@SFGFSFODF@DB⒎FOFUDB⒎FNPEFMֶशࡁΈσʔλ 13

  14. ॲཧͷྲྀΕ ࣝผର৅ͷը૾ͷಡΈࠐΈ w ૾ͷը૾ $MBTTJpFSΫϥεͷॳظԽ w ͭͷϞσϧσʔλ΁ͷϑΝΠϧύεΛࢦఆ $MBTTJpFSͷ࣮ߦ w ը૾Λࢦఆͯ݁͠ՌΛऔಘ

    ࣝผ݁Ռͷग़ྗ 14
  15. UIImage* image = [UIImage imageNamed:@"sample.jpg"]; cv::Mat src_img, img; UIImageToMat(image, src_img);

    cv::cvtColor(src_img, img, CV_RGBA2BGRA); ը૾ͷಡΈࠐΈ w 6**NBHFΛಡΈࠐΈ w DW.BUܗࣜʹม׵ w Χϥʔ഑ྻΛ3(#"͔Β#(3"ʹม׵
  16. // ϑΝΠϧύεΛstringܕʹม׵ string model_file_str = std::string([model_file UTF8String]); string label_file_str =

    std::string([label_file UTF8String]); string trained_file_str = std::string([trained_file UTF8String]); string mean_file_str = std::string([mean_file UTF8String]); Classifier classifier = Classifier(model_file_str, trained_file_str, mean_file_str, label_file_str); $MBTTJpFSͷॳظԽ w ϞσϧఆٛɺϥϕϧɺֶशࡁΈϞσϧɺฏۉը૾ͷύεΛऔಘ w ֤ϑΝΠϧύεΛTUETUSJOHʹม׵ w $MBTTJpFSͷΠϯελϯεΛ࡞੒
  17. // ࣝผͷ࣮ߦ std::vector<Prediction> result = classifier.Classify(img); $MBTTJpFSͷ࣮ߦ w ը૾Λࢦఆ͢Δ͚ͩʂ

  18. for (std::vector<Prediction>::iterator it = result.begin(); it != result.end(); ++it) {

    NSString* label = [NSString stringWithUTF8String:it->first.c_str()]; NSNumber* probability = [NSNumber numberWithFloat:it->second]; NSLog(@"label: %@, prob: %@", label, probability); } ࣝผ݁Ռͷग़ྗ w TUEWFDUPSܗࣜͰෳ਺ͷࣝผީิ͕ಘΒΕΔ w JUFSBUPSͰճ֤ͯ͠ީิΛऔಘ w JUpSTUϥϕϧɺJUTFDPOE֬཰
  19. ·ͱΊ w $B⒎FΛ࢖͑͹ΦϦδφϧͷֶशϞσϧ͕࡞ΕΔ w $B⒎FGPSJ04ͳΒαʔό͍ΒͣͰࣝผॲཧ͕ग़དྷΔ w αϯϓϧϓϩδΣΫτͷ͝঺հ w ΦϦδφϧͷֶशϞσϧͰΞϓϦΛ࡞Ζ͏ʂ 19

  20. ͝ਗ਼ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠ 20