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

20160928-meganeco

Ece52fe9ce913851256726020707febd?s=47 ARIYAMA Keiji
September 28, 2016

 20160928-meganeco

「TensorFlowで趣味の画像収集サーバーを作る9月特大号」
TensorFlowによる認識処理の高速化と新データセットでの訓練・評価検証

Ece52fe9ce913851256726020707febd?s=128

ARIYAMA Keiji

September 28, 2016
Tweet

More Decks by ARIYAMA Keiji

Other Decks in Technology

Transcript

  1. C-LIS CO., LTD.

  2. 5FOTPS'MPXͰ झຯͷը૾ऩूαʔόʔΛ࡞Δ ݄̕ಛେ߸

  3. C-LIS CO., LTD.  ༗ࢁܓೋʢ,FJKJ"3*:"."ʣ C-LIS CO., LTD. AndroidΞϓϦ։ൃऀ ػցֶशॳ৺ऀ

    ΍ͬͯ·ͤΜ 1IPUP,PKJ.03*(6$)* "6/$3&"5*7&'*3.
  4. C-LIS CO., LTD. 

  5. C-LIS CO., LTD. 

  6. લճ·Ͱͷ͓࿩

  7.  IUUQTUFDICPPLGFTUPSH"

  8. C-LIS CO., LTD. 

  9. C-LIS CO., LTD. IUUQBN[OUPC,3N

  10. C-LIS CO., LTD. .FHBOF /PU

  11. ޷Έͷ؟ڸ່ͬը૾ΛࣗಈͰऩू͍ͨ͠

  12. C-LIS CO., LTD. Ϟσϧ 7((/FUΛࢀߟʹ৞ΈࠐΈ૚ͷ࿈ଓΛ༻͍ͨ$// ʢ$POWPMVUJPOBM/FVSBM/FUXPSLʣϞσϧ  DPO YY DPO

    YY GD  QPPM Y DPO YY DPO YY QPPM Y GD  GD  PVUQVU 
  13. C-LIS CO., LTD. %BUB"VHNFOUBUJPO ը૾Λ  ʜ౓·ͰɺͦΕͧΕճసͨ͠ը૾Λ࡞੒ ಡΈࠐΈ࣌ͷॲཧ
 3BOEPN$SPQʢQYதɺQYྖҬΛ͘Γൈ͘ʣ
 3BOEPN'MJQʢԣ࣠ํ޲ʹ൓సʣ


    3BOEPN6Q%PXOʢॎ࣠ํ޲ʹ൓సʣ
 3BOEPN#SJHIUOFTT
 3BOEPN$POUSBTU 
  14. C-LIS CO., LTD. ܇࿅ ֶशΞϧΰϦζϜ"EBN ֶश཰ ϛχόον 

  15. C-LIS CO., LTD. ݕূ σʔληοτ͔ΒΛςετ༻ͱͯ͠෼཭ ਖ਼౴཰ʙ 

  16. Πϥετإݕग़ثʢ'BDF%FUFDUPSʣ

  17. C-LIS CO., LTD. Πϥετإσʔληοτ ؟ڸ່ͬͱͦ͏Ͱͳ͍΋ͷɻ߹Θͤͯ ຕΛ
 ਖ਼ྫʢʹإʣͱ͢Δʢ͏ͪςετσʔλຕʣ ෛྫ͸ɺطଘͷը૾Λࡉ੾Εʹͯ͠ɺإ͕ͳ͍෦෼  ຕΛෛྫͱ͢Δʢ͏ͪςετσʔλຕʣ

    
  18. C-LIS CO., LTD. Πϥετσʔληοτ  ਖ਼ྫ ෛྫ ߹ܭ ܇࿅σʔλ 1,600

    3,200 4,800 ςετσʔλ 400 800 1,200 ߹ܭ 2,000 4,005 6,000
  19. C-LIS CO., LTD. Ϟσϧ $*'"3νϡʔτϦΞϧͷϞσϧΛࢀߟʹ
 υϩοϓΞ΢τʢˋʣΛ௥Ճͨ͠$//ʢ$POWPMVUJPOBM/FVSBM /FUXPSLʣ  DPO YY

    GD  QPPM Y DPO YY GD  PVUQVU  MSO MSO QPPM Y
  20. C-LIS CO., LTD. %BUB"VHNFOUBUJPO ը૾͸Yʹॖখ ը૾Λ  ʜ౓ɺͦΕͧΕճసͨ͠ը૾Λ࡞੒ ಡΈࠐΈ࣌ͷॲཧ
 3BOEPN$SPQʢQYதɺQYྖҬͰ͘Γൈ͘ʣ


    3BOEPN'MJQʢԣ࣠ํ޲ʹ൓సʣ
 3BOEPN6Q%PXOʢॎ࣠ํ޲ʹ൓సʣ
 3BOEPN#SJHIUOFTT
 3BOEPN$POUSBTU 
  21. C-LIS CO., LTD. ܇࿅ ֶशΞϧΰϦζϜ"EBN ֶश཰ ϛχόον 

  22. C-LIS CO., LTD. ܇࿅ ϛχόονɺ໿ສεςοϓͷ܇࿅Ͱ
 ϩε཰͕·Ͱ௿Լ ςετσʔλͰͷਖ਼ղ཰ 

  23. إݕग़

  24. C-LIS CO., LTD.  إ͸Ͳ͜ʹ͋Δʁ

  25. C-LIS CO., LTD. 4FMFDUJWF4FBSDI 35$PSQPSBUJPOͷʮ౜༲͛ϩϘοτʯ 5FOTPS'MPXษڧձʢ̐ʣ೥݄೔Ͱൃද  IUUQXXXTMJEFTIBSFOFU:VLJ/BLBHBXBUFOTPSqPXSFW

  26. C-LIS CO., LTD. 4FMFDUJWF4FBSDI "MQBDBࣾʹΑΔ࣮૷
 IUUQCMPHKQBMQBDBBJFOUSZ EMJCͷ࣮૷
 IUUQTHJUIVCDPNEBWJTLJOHEMJCCMPCNBTUFS QZUIPO@FYBNQMFTpOE@DBOEJEBUF@PCKFDU@MPDBUJPOTQZ 

  27. C-LIS CO., LTD. લճͷ՝୊ ݕग़࣌ؒͷ୹ॖ ೝࣝਫ਼౓ͷ޲্ 

  28. ݕग़࣌ؒͷ୹ॖ

  29. C-LIS CO., LTD. إݕग़ͷखॱ  ީิྖҬͷ੾Γग़͠ SelectiveSearch

  30. C-LIS CO., LTD. إݕग़ͷखॱ  إೝࣝ TensorFlow ީิྖҬͷ੾Γग़͠ SelectiveSearch OݸͷީิྖҬ

  31. C-LIS CO., LTD. άϥϑͱηογϣϯΛҙࣝ͢Δ  ީิྖҬͷ੾Γग़͠ SelectiveSearch إೝࣝ TensorFlow άϥϑͷ࡞੒

    ηογϣϯͷ։࢝ tf.Session() άϥϑͷ࣮ߦ run OݸͷީิྖҬ ը૾σʔλʴ ը૾σʔλ
  32. C-LIS CO., LTD. إೝࣝ TensorFlow άϥϑͱηογϣϯΛҙࣝ͢Δ  άϥϑͷ࡞੒ ηογϣϯͷ։࢝ tf.Session()

    άϥϑͷ࣮ߦ run άϥϑ
 Ϧηοτ OݸͷྖҬΛ͢΂ͯධՁ OݸͷީิྖҬ ը૾σʔλʴ
  33. C-LIS CO., LTD.  ࠷దͳྖҬΛ୳ࡧʢ3FHSFTTJPOʣ

  34. C-LIS CO., LTD. إೝࣝ TensorFlow ຖճάϥϑΛ࡞੒ɾηογϣϯΛ։࢝  άϥϑͷ࡞੒ ηογϣϯͷ։࢝ άϥϑͷ࣮ߦ

    run άϥϑ
 Ϧηοτ OݸͷྖҬΛ͢΂ͯධՁ OݸͷީิྖҬ ը૾σʔλʴ
  35.  class FaceDetector(object):
 image_path = None
 original_image = None
 graph

    = None
 sess = None
 queue = None
 top_k_indices = None
 top_k_values = None
 region_batch = None
 coord = None
 
 configuration = None
 
 def __init__(self, image_path, batch_size, train_dir):
 self.image_path = image_path
 self.original_image = Image.open(image_path)
 self.original_image = self.original_image.convert('RGB')
 
 checkpoint = tf.train.get_checkpoint_state(train_dir)
 if not (checkpoint and checkpoint.model_checkpoint_path):
 print('νΣοΫϙΠϯτϑΝΠϧ͕ݟ͔ͭΓ·ͤΜ')
 return
 
 self.graph, self.queue, self.top_k_indices, self.top_k_values, self.region_batch = \
 self._init_graph(self.original_image, batch_size)
 
 with self.graph.as_default() as g:
 self.sess = tf.Session()
 saver = tf.train.Saver()
 saver.restore(self.sess, checkpoint.model_checkpoint_path)
 
 self.coord = tf.train.Coordinator()

  36.  def _init_graph(self, image, batch_size):
 reshaped_image = np.array(image.getdata()).reshape(image.height, image.width, 3).astype(


    np.float32)
 
 graph = tf.Graph()
 
 with graph.as_default() as g:
 queue = tf.FIFOQueue(3000, tf.int32, shapes=[4])
 
 region = queue.dequeue()
 whitten_image = self._load_image(reshaped_image, region)
 
 image_batch, region_batch = tf.train.batch(
 [whitten_image, region],
 batch_size=batch_size,
 capacity=10000)
 
 logits = tf.nn.softmax(model.inference(image_batch, tf.constant(1.0), batch_size))
 top_k_values, top_k_indices = tf.nn.top_k(logits, 2, sorted=True)
 
 return graph, queue, top_k_indices, top_k_values, region_batch
  37.  def _eval(self, region_list, batch_size):
 result = []
 
 with

    graph.as_default() as g:
 threads = tf.train.start_queue_runners(sess=sess, coord=coord)
 
 step = 0
 try:
 # όοναΠζʹ߹Θͤͯ਺Λௐ੔
 while len(region_list) < batch_size or len(region_list) % batch_size != 0:
 add = region_list[0:(batch_size - (len(region_list) % batch_size))]
 region_list = region_list + add
 
 region_list = np.array(region_list)
 
 enqueue = queue.enqueue_many(region_list)
 sess.run(enqueue)
 
 num_iter = int(math.ceil(len(region_list) / batch_size))
 
 while step < num_iter and not coord.should_stop():
 
 # ҎԼུ
  38. C-LIS CO., LTD. إೝࣝ TensorFlow ީิྖҬͷΈ༩͑Δ  άϥϑͷ࡞੒ ηογϣϯͷ։࢝ άϥϑͷ࣮ߦ

    run άϥϑ
 Ϧηοτ OݸͷྖҬΛ͢΂ͯධՁ ը૾σʔλ OݸͷީิྖҬ
  39. ೝࣝਫ਼౓ͷ޲্ σʔληοτͷ֦ॆ

  40. C-LIS CO., LTD. 5XJUUFS"1* ಛఆͷϢʔβʔͷλΠϜϥΠϯʹ౤ߘ͞ΕͨϝσΟΞ ʢը૾ʣΛμ΢ϯϩʔυ ϋογϡΛܭࢉͯ͠ॏෳը૾ΛϑΟϧλϦϯά
 ʢαΠζҧ͍ͳͲͷྨࣅը૾͸ফ͖͠Εͳ͍ʣ 

  41. C-LIS CO., LTD. Πϥετإσʔλऩूʹ
 ࠷దͳΞΧ΢ϯτ !CPU@FSFDUJPO IUUQTUXJUUFSDPNCPU@FSFDUJPO 

  42. C-LIS CO., LTD. ࿐ࠎʹੑతͳը૾͸ɺ΄΅ଘࡏ͠ͳ͍ πΠʔτʹඞͣը૾͕ఴ෇͞Ε͍ͯΔ ը૾ʹਓҎ্ͷঁͷࢠͷإؚ͕·Ε͍ͯΔ

  43. 5XJUUFS͔Βऔಘͨ͠ϑΝΠϧ਺   ݕग़ͨ͠إྖҬͷ਺ɹɹɹɹɹɹɹɹ  

  44. C-LIS CO., LTD. { "detected_faces": { "mode": "selective_search", "regions": [

    { "label": 1, "rect": { "left": 212.0, "bottom": 654.0, "top": 94.0, "right": 483.0 }, "probability": 0.9994481205940247 } ] }, "created_at": "2016-09-28T03:37:16.223942", "file_name": "kage_maturi-CAARxE8UwAEzAjJ.jpg", "generator": "Megane Co" }  ݁ՌΛ+40/Ͱॻ͖ग़͠
  45. C-LIS CO., LTD. 3FHJPO$SPQQFS +BWB'9 ,PUMJO  IUUQTHJUIVCDPNLFJKJSFHJPO@DSPQQFS

  46. %FNP

  47. C-LIS CO., LTD. 3FHJPO$SPQQFS /FXGFBUVSF ɾબ୒தͷྖҬΛϑΥʔΧε ɾ6OEP ɾTFUUJOHTKTPOʹΑΔઃఆ
 ɹϥϕϧ͝ͱͷ࿮ઢ৭
 ɹฤूɺ࡟আͷՄ൱

     IUUQTHJUIVCDPNLFJKJSFHJPO@DSPQQFS
  48. C-LIS CO., LTD.  ݕग़ͨ͠إྖҬͷ਺ʢॏෳΛ࡟আʣɹɹɹɹɹɹɹɹ   إʢਖ਼ྫʣ  ޡݕग़ʢෛྫʣ

    
  49. C-LIS CO., LTD. ৽σʔληοτ  ਖ਼ྫ ෛྫ ߹ܭ ܇࿅σʔλ 10,453

    10,792 21,245 ςετσʔλ 2,619 2,703 5,322 ߹ܭ 13,072 13,495 26,567
  50. C-LIS CO., LTD. ৽σʔληοτʹΑΔ܇࿅ ϛχόονɺສεςοϓͷ܇࿅Ͱ
 ϩε཰͕·Ͱ௿Լ ςετσʔλʹΑΔݕূͰͷਖ਼ղ཰ 

  51. C-LIS CO., LTD. چσʔληοτ  ਖ਼ྫ ෛྫ ߹ܭ ܇࿅σʔλ 1,600

    3,200 4,800 ςετσʔλ 400 800 1,200 ߹ܭ 2,000 4,005 6,000
  52. C-LIS CO., LTD. چσʔληοτͷ܇࿅ ϛχόονɺ໿ສεςοϓͷ܇࿅Ͱ
 ϩε཰͕·Ͱ௿Լ ςετσʔλͰͷݕূͰͷਖ਼ղ཰ 

  53. C-LIS CO., LTD.  ৽Ϟσϧ͸ੑೳ͕ѱ͍ʁ چςετσʔλ چϞσϧ  ৽ςετσʔλ ৽Ϟσϧ

    
  54. C-LIS CO., LTD.  ৽چͷςετσʔλΛަ׵ چϞσϧ ৽ςετσʔλ  چςετσʔλ ৽Ϟσϧ

    
  55. C-LIS CO., LTD.  ৽چͷςετσʔλΛݕূ چϞσϧ ৽ςετσʔλ  چςετσʔλ ৽Ϟσϧ

     چςετσʔλ چϞσϧ  ৽ςετσʔλ ৽Ϟσϧ 
  56. C-LIS CO., LTD. إೝࣝʹࣦഊͨ͠σʔλΛݕূ
 ʢچςετσʔλʣ   OPU@GBDF  GBDF

  57. C-LIS CO., LTD. إೝࣝʹࣦഊͨ͠σʔλΛݕূ
 ʢ৽ςετσʔλʣ   OPU@GBDF  GBDF

  58. ࣍ճ༧ࠂ

  59. C-LIS CO., LTD. σʔλͷΫϨϯδϯάʹΑΔೝࣝਫ਼౓ͷมԽΛݟΔ ݕग़଎౓Λ͞Βʹվળ͢Δ ࣍ճ༧ࠂ  IUUQTXXXTBLVSBBEKQLPVLBSZPLV

  60. C-LIS CO., LTD. C-LIS CO., LTD. ຊࢿྉ͸ɺ༗ݶձࣾγʔϦεͷஶ࡞෺Ͱ͢ɻܝࡌ͞Ε͍ͯΔΠϥετʹ͸ݸผʹஶ࡞ݖ͕͋Γ·͢ɻ ຊࢿྉͷશ෦ɺ·ͨ͸Ұ෦ʹ͍ͭͯɺஶ࡞ऀ͔ΒจॻʹΑΔڐ୚Λಘͣʹෳ੡͢Δ͜ͱ͸ې͡ΒΕ͍ͯ·͢ɻ ֤੡඼໊ɾϒϥϯυ໊ɺձ໊ࣾͳͲ͸ɺҰൠʹ֤ࣾͷ঎ඪ·ͨ͸ొ࿥঎ඪͰ͢ɻຊࢿྉதͰ͸ɺ˜ɺšɺäΛׂѪͯ͠ ͍·͢ɻ