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

20160928-meganeco

ARIYAMA Keiji
September 28, 2016

 20160928-meganeco

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

ARIYAMA Keiji

September 28, 2016
Tweet

More Decks by ARIYAMA Keiji

Other Decks in Technology

Transcript

  1. 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 
  2. C-LIS CO., LTD. Πϥετσʔληοτ  ਖ਼ྫ ෛྫ ߹ܭ ܇࿅σʔλ 1,600

    3,200 4,800 ςετσʔλ 400 800 1,200 ߹ܭ 2,000 4,005 6,000
  3. C-LIS CO., LTD. άϥϑͱηογϣϯΛҙࣝ͢Δ  ީิྖҬͷ੾Γग़͠ SelectiveSearch إೝࣝ TensorFlow άϥϑͷ࡞੒

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

    άϥϑͷ࣮ߦ run άϥϑ
 Ϧηοτ OݸͷྖҬΛ͢΂ͯධՁ OݸͷީิྖҬ ը૾σʔλʴ
  5.  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()

  6.  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
  7.  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():
 
 # ҎԼུ
  8. C-LIS CO., LTD. إೝࣝ TensorFlow ީิྖҬͷΈ༩͑Δ  άϥϑͷ࡞੒ ηογϣϯͷ։࢝ άϥϑͷ࣮ߦ

    run άϥϑ
 Ϧηοτ OݸͷྖҬΛ͢΂ͯධՁ ը૾σʔλ OݸͷީิྖҬ
  9. 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/Ͱॻ͖ग़͠
  10. C-LIS CO., LTD. ৽σʔληοτ  ਖ਼ྫ ෛྫ ߹ܭ ܇࿅σʔλ 10,453

    10,792 21,245 ςετσʔλ 2,619 2,703 5,322 ߹ܭ 13,072 13,495 26,567
  11. C-LIS CO., LTD. چσʔληοτ  ਖ਼ྫ ෛྫ ߹ܭ ܇࿅σʔλ 1,600

    3,200 4,800 ςετσʔλ 400 800 1,200 ߹ܭ 2,000 4,005 6,000
  12. C-LIS CO., LTD.  ৽چͷςετσʔλΛݕূ چϞσϧ ৽ςετσʔλ  چςετσʔλ ৽Ϟσϧ

     چςετσʔλ چϞσϧ  ৽ςετσʔλ ৽Ϟσϧ