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

20161119-meganeco

Ece52fe9ce913851256726020707febd?s=47 ARIYAMA Keiji
November 19, 2016

 20161119-meganeco

「TensorFlowで趣味の画像収集サーバーを作る 11月号」
大量の画像からデータセットを作成するために構築したワークフローについて解説します。

Ece52fe9ce913851256726020707febd?s=128

ARIYAMA Keiji

November 19, 2016
Tweet

Transcript

  1. C-LIS CO., LTD. 5FOTPS'MPXͰझຯͷը૾ऩूαʔόʔΛ࡞Δ݄߸ BCDB

  2. C-LIS CO., LTD.  ༗ࢁܓೋʢ,FJKJ"3*:"."ʣ $-*4$0 -5% "OESPJEΞϓϦ։ൃνϣοτσΩϧ ػցֶशॳ৺ऀ Photo

    : Koji MORIGUCHI (AUN CREATIVE FIRM) ΍ͬͯ·ͤΜ
  3.  ݄೔ʙ https://devfestkansai.connpass.com/event/42864/

  4. C-LIS CO., LTD.  (%(,PCFʢʣ (%(,ZPUPʢʣ ೔ຊ"OESPJEͷձ"OESPJE#B[BBSBOE$POGFSFODFʢʣ (%(,PCFʢ ڞ࠵($16#0TBLBʣ 5FOTPS'MPXษڧձʢ̏ʣʢ

    ڞ࠵೔ຊ"OESPJEͷձʣ 5FOTPS'MPXษڧձʢ̐ʣʢʣ ͳʹΘ5&$)ಓʢʣ 5FOTPS'MPXษڧձʢʣʢʣ ೔ຊ"OESPJEͷձ"OESPJE#B[BBSBOE$POGFSFODFʢʣ ˡ/FXʂ
  5.  10% 1SJOU0O%FNBOE ిࢠॻ੶ Impress R&D͔Βൃചத http://amzn.to/2axRog

  6. C-LIS CO., LTD. 

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

  8. 4PGUXBSF%FTJHO೥݄߸ʰ"OESPJE4UVEJPͷελΠϧͰޮ཰ΞοϓʱΑΓ © ࠜઇΕ͍ ؟ ڸ ͬ ່

  9.  ̎Ϋϥε෼ྨ  

  10.  ؟ڸ່ͬσʔληοτ

  11. ؟ڸ່ͬը૾ຕ ඇ؟ڸ່ͬຕ ܭɿ ຕ  ೥݄ ؟ڸ່ͬ ඇ؟ڸ່ͬ ޡݕग़ ؟ڸ່ͬ

    ඇ؟ڸ່ͬ
  12. ؟ڸ່ͬը૾ ຕ ඇ؟ڸ່ͬ ຕ ܭɿ ຕ  ೥݄ ؟ڸ່ͬ ඇ؟ڸ່ͬ

  13. ؟ڸ່ͬը૾ ຕ ඇ؟ڸ່ͬ ຕ ܭɿ ຕ  ೥݄ ؟ڸ່ͬ ඇ؟ڸ່ͬ

  14.  ݱࡏͷߏ੒ Downloader Face Detection Megane Detection API TensorFlow ֬ೝɾमਖ਼

    ೝࣝ݁Ռ JSON ܇࿅ λΠϜϥΠϯ ϝσΟΞ σʔληοτ ܇࿅
  15.  %PXOMPBEFS Downloader Face Detection Megane Detection API TensorFlow ֬ೝɾमਖ਼

    ೝࣝ݁Ռ JSON ܇࿅ λΠϜϥΠϯ ϝσΟΞ σʔληοτ ܇࿅
  16. w͋Β͔͡Ίొ࿥ͨ͠5XJUUFS*%ͷ౤ߘ͢ΔϝσΟΞΛμ΢ϯϩʔυ w5XJUUFS*%ͱը૾63-ΛσʔλϕʔεͰ؅ཧ͢Δ͜ͱͰɺ
 ը૾ͷݖརऀΛ֬ೝՄೳʹ  %PXOMPBEFS

  17. wը૾ͷॏෳ͕සൟʹൃੜͯ͠͠·͏ɻ ఆظతͳ޿ࠂπΠʔτ ιʔγϟϧήʔϜͷϓϨΠը໘ େચɹͳͲ  ՝୊

  18.  JNBHF)BTI 67d85827b2396276 = = =

  19.  'BDF%FUFDUJPO Downloader Face Detection Megane Detection API TensorFlow ֬ೝɾमਖ਼

    ೝࣝ݁Ռ JSON ܇࿅ λΠϜϥΠϯ ϝσΟΞ σʔληοτ ܇࿅
  20.  © ࠜઇΕ͍ Sliding Window Selective Search

  21.  إೝࣝ༻ͷϞσϧ DPO YY DPO YY GD  QPPM Y

    DPO YY DPO YY QPPM Y GD  PVUQVU  MSO MSO Y
  22.  ܇࿅ 12ສεςοϓֶशޙͷςετσʔλʹΑΔਖ਼౴཰ 96%

  23.  .FHBOF%FUFDUJPO Downloader Face Detection Megane Detection API TensorFlow ֬ೝɾमਖ਼

    ೝࣝ݁Ռ JSON ܇࿅ λΠϜϥΠϯ ϝσΟΞ σʔληοτ ܇࿅
  24.  ؟ڸೝࣝ༻ͷϞσϧ DPO YY DPO YY GD  QPPM Y

    DPO YY DPO YY QPPM Y GD  PVUQVU  MSO MSO Y
  25.  ܇࿅ 8ສεςοϓֶशޙͷςετσʔλʹΑΔਖ਼౴཰ 96%

  26. C-LIS CO., LTD. 

  27.  ೝࣝ݁Ռ Downloader Face Detection Megane Detection API TensorFlow ֬ೝɾमਖ਼

    ೝࣝ݁Ռ JSON ܇࿅ λΠϜϥΠϯ ϝσΟΞ σʔληοτ ܇࿅
  28. { "generator": "Megane Co", "file_name": "neyuki_rei-CZY6tnUUYAAJVe6.jpg", "created_at": "2016-11-18T10:19:04.879281", "detected_faces": {

    "mode": "selective_search", "model_version": "20161118003546" "configurations": { }, "regions": [ { "rect": { "top": 59.0, "bottom": 175.0, "left": 85.0, "right": 176.0 }, "label": 2, "probability": 0.9962707757949829 },  ೝࣝ݁Ռͷ+40/ { "rect": { "top": 220.0, "bottom": 274.0, "left": 455.0, "right": 524.0 }, "label": 1, "probability": 0.9997575879096985 }, { "rect": { "top": 196.0, "bottom": 282.0, "left": 244.0, "right": 330.0 }, "label": 1, "probability": 1.0 }
  29.  ೝࣝ݁Ռͷ֬ೝͱमਖ਼ Downloader Face Detection Megane Detection API TensorFlow ֬ೝɾमਖ਼

    ೝࣝ݁Ռ JSON ܇࿅ λΠϜϥΠϯ ϝσΟΞ σʔληοτ ܇࿅
  30. C-LIS CO., LTD. https://github.com/keiji/region_cropper © ࠜઇΕ͍

  31.  ೝࣝ݁Ռͷ֬ೝͱमਖ਼ Downloader Face Detection Megane Detection API TensorFlow ֬ೝɾमਖ਼

    ೝࣝ݁Ռ JSON ܇࿅ λΠϜϥΠϯ ϝσΟΞ σʔληοτ ܇࿅
  32.  ཷ·Δະॲཧը૾ ॲཧࡁΈɿ20,000ຕ ະॲཧɿ 24,000ຕ

  33.  ສ݅Λ௒͑ͨ͋ͨΓͰ
 ํ਑Λมߋ

  34.  ೝࣝʹࣦഊͨ͠ը૾͚ͩ σʔληοτ΁௥Ճ

  35.  Ұ൪ࠨͷ؟ڸ່ͬͷإΛೝࣝͰ͖͍ͯͳ͍ © ࠜઇΕ͍

  36.  ؟ڸΛ͔͚͍ͯͳ͍ͷʹ؟ڸ່ͬͱೝࣝ © ࠜઇΕ͍

  37.  إͱೝࣝ͢Δ৔ॴ͕ؒҧ͍ͬͯΔ ؟ڸ່ͬͱೝ͍ࣝͯ͠Δ © ࠜઇΕ͍

  38.  σʔληοτສຕʹ౸ୡ

  39. C-LIS CO., LTD. 

  40. C-LIS CO., LTD. 

  41. C-LIS CO., LTD.  ࢲͷ σʔληοτ͸ ສઍͰ͢ɻ

  42.  ͗͢ΌʔΜϝϞ http://memo.sugyan.com/

  43. C-LIS CO., LTD. 

  44. C-LIS CO., LTD.  ࢲͷ σʔληοτ͸ ສઍͰ͢ɻ

  45.  ΋͏ͪΐͬͱ͚ͩ ଓ͘Μ͡Ό

  46. w؟ڸ່ͬը૾Λൃݟͨ͠Βϝϯγϣϯ͢ΔॲཧΛ࣮૷ wإೝࣝͷਫ਼౓޲্ ϞσϧͷܰྔԽ 4FMFDUJWF4FBSDIͷύϥϝʔλʔௐ੔ إͷύλʔϯʢਖ਼໘ɾԣإɾԼ޲͖ͳͲʣΛΫϥεʹ෼཭͢Δ wΠϥετإೝࣝͷ"1*Խ w؟ڸೝࣝͷΫϥεΛ૿΍͢  ࠓޙͷ՝୊

  47.  ؟ڸೝࣝͷΫϥεΛ૿΍͢ʁ ԑͳ͠ ্ԑɾηϧϑϨʔϜ

  48.  ҧ͍·͢

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

  50.  ๻ʹʰ؟ڸ່ͬʱͷ࿩ͤͨ͞Β ௕͘ͳΓ·͢Αʁ

  51.  ؟ڸೝࣝͷΫϥεΛ૿΍͢ 4PGUXBSF%FTJHO೥݄߸ʰ"OESPJE4UVEJPͷελΠϧͰޮ཰ΞοϓʱΑΓ © ࠜઇΕ͍

  52.  ؟ڸೝࣝͷΫϥεΛ૿΍͢ © ࠜઇΕ͍ ϥϑஈ֊

  53.  ؟ڸೝࣝͷΫϥεΛ૿΍͢ 4PGUXBSF%FTJHO೥݄߸ʰ"OESPJE4UVEJPͷελΠϧͰޮ཰ΞοϓʱΑΓ © ࠜઇΕ͍

  54.  ؟ڸೝࣝͷΫϥεΛ૿΍͢ © ࠜઇΕ͍

  55.  ग़ྗ૚Λ௥Ճ͢Δ DPO YY DPO YY GD  QPPM Y

    DPO YY DPO YY QPPM Y GD  PVUQVU  MSO MSO Y φΠε؟ڸ່ͬʂ ؟ڸΛ͔͚ͨঁࢠ Human
  56.  άϥϑͷΤΫεϙʔτ

  57. 5FOTPS'MPXͰߏஙͨ͠ʮάϥϑʯͱʮύϥϝʔλʔʯΛͦͷ··ॻ͖ग़͢ɻ γϦΞϥΠβʔʹ1SPUPDPM#V⒎FSTΛ࢖༻͍ͯ͠Δɻ  άϥϑͷΤΫεϙʔτͱ͸ʁ

  58. "OESPJEͳͲͰಡΈࠐΉ৔߹͸άϥϑͱύϥϝʔλʔΛΤΫεϙʔτ͢Δඞཁ ͕͋ΔʢΒ͍͠ʣɻ ࣥචͨ͠ͱ͖͸ɺ܇࿅݁ՌΛ֤ΤϙοΫ͝ͱʹΤΫεϙʔτͯ͠ɺ͋ͱͰҰؾ ʹਖ਼౴཰ΛݟΔͱ͍͏͜ͱΛͨ͠ɻ  4BWFSͱͷҧ͍

  59. ܇࿅ࡁΈͷϞσϧʢάϥϑʴύϥϝʔλʔʣ͕͋Δɻ άϥϑʹυϩοϓΞ΢τͳͲͷ܇࿅༻ͷॲཧؚ͕·Ε͍ͯΔɻ  લఏ

  60. def inference(image_node, keep_prob, batch_size=1):
 conv1_1 = _conv('conv1_1', image_node, [3, 3,

    3, 64], 64)
 conv1_2 = _conv('conv1_2', conv1_1, [3, 3, 64, 64], 64)
 pool1 = _pool('pool1', conv1_2, [1, 2, 2, 1])
 
 conv2_1 = _conv('conv2_1', pool1, [3, 3, 64, 128], 128)
 conv2_2 = _conv('conv2_2', conv2_1, [3, 3, 128, 128], 128)
 pool2 = _pool('pool2', conv2_2, [1, 2, 2, 1])
 
 conv3_1 = _conv('conv3_1', pool2, [3, 3, 128, 256], 256)
 conv3_2 = _conv('conv3_2', conv3_1, [3, 3, 256, 256], 256)
 pool3 = _pool('pool3', conv3_2, [1, 2, 2, 1])
  ܇࿅༻ͷάϥϑ reshape = tf.reshape(pool3, [batch_size, -1])
 dim = reshape.get_shape()[1].value
 
 fc4 = _fc('fc4', reshape, [dim, 512], 512, keep_prob)
 fc5 = _fc('fc5', fc4, [512, 256], 256, keep_prob)
 
 # output
 with tf.variable_scope('output') as scope:
 weights = _get_weights(shape=[256, NUM_CLASSES], stddev=1 / 256.0)
 biases = _get_biases([NUM_CLASSES], value=0.0)
 logits = tf.add(tf.matmul(fc5, weights), biases, name='logits')
 
 return logits

  61. def _fc(name, input_layer, weights_shape, biases_size, keep_prob):
 with tf.variable_scope(name) as scope:


    weights = _get_weights(shape=weights_shape, stddev=0.05)
 biases = _get_biases([biases_size], value=0.1)
 fc = tf.nn.relu(tf.matmul(input_layer, weights) + biases, name=scope.name)
 fc = tf.nn.dropout(fc, keep_prob)
 return fc
  ܇࿅༻ͷάϥϑ http://goo.gl/forms/2IsX177eJ3CpNKng1 model_vgg_lite_minibatch.py
  62. def _fc(name, input_layer, weights_shape, biases_size, keep_prob):
 with tf.variable_scope(name) as scope:


    weights = _get_weights(shape=weights_shape, stddev=0.05)
 biases = _get_biases([biases_size], value=0.1)
 fc = tf.nn.relu(tf.matmul(input_layer, weights) + biases, name=scope.name)
 fc = tf.nn.dropout(fc, keep_prob)
 return fc
  ධՁ༻ͷάϥϑ http://goo.gl/forms/2IsX177eJ3CpNKng1 model_vgg_lite_minibatch_no_dropout.py
  63. # coding: UTF-8
 from __future__ import absolute_import
 from __future__ import

    division
 from __future__ import print_function
 
 import tensorflow as tf
 
 from tensorflow.python.framework import graph_util
 
 import model_vgg_lite_minibatch_no_dropout as model
 
 FLAGS = tf.app.flags.FLAGS
 tf.app.flags.DEFINE_string('output_graph_path', None, "ग़ྗ͢ΔάϥϑͷσΟϨΫτϦ")
 tf.app.flags.DEFINE_string('checkpoint_dir', './checkpoints', "νΣοΫϙΠϯτͷσΟϨΫτϦ")
 tf.app.flags.DEFINE_integer('batch_size', 1, "όοναΠζ")
 
  64. def main(argv=None):
 # eval༻ͷΤϯτϦϙΠϯτ
 input_image = tf.placeholder(tf.float32, shape=[FLAGS.batch_size, 32, 32,

    3], name='input_image')
 logits = model.inference(input_image, batch_size=FLAGS.batch_size)
 
 saver = tf.train.Saver()
 
 with tf.Session() as sess: 
 # ύϥϝʔλʔͷಡΈࠐΈ
 checkpoint = tf.train.get_checkpoint_state(FLAGS.checkpoint_dir)
 if checkpoint and checkpoint.model_checkpoint_path:
 saver.restore(sees, checkpoint.model_checkpoint_path)
 # άϥϑʴύϥϝʔλʔͷΤΫεϙʔτ
 constant_graph_def = graph_util.convert_variables_to_constants(
 sess, sess.graph_def, ["output/logits"])
 with tf.gfile.FastGFile(FLAGS.output_graph_path, 'wb') as f:
 f.write(constant_graph_def.SerializeToString()) 
  65. $ python3 convert_to_graph.py --checkpoint_dir ./checkpoints \ --output_graph_path ./graphs/exported_graph.pb \ --batch_size

    1 Converted 18 variables to const ops.  ධՁ༻άϥϑʴύϥϝʔλʔͷΤΫεϙʔτ
  66. with tf.gfile.FastGFile(graph_file, 'rb') as f:
 graph_def = tf.GraphDef()
 graph_def.ParseFromString(f.read())
 _

    = tf.import_graph_def(graph_def, name='')
  ධՁଆͰάϥϑΛΠϯϙʔτ
  67. predictions = sess.run(logits,
 feed_dict={
 input_image: batch_byte_array,
 labels: batch_label,
 })
 

    MPHJUTͱMBCFM͔Βਖ਼౴൑ఆ
  68. labels = tf.placeholder(tf.int32, shape=[FLAGS.batch_size], name='label')
 input_image = tf.get_default_graph().get_tensor_by_name('input_image:0')
 logits =

    tf.get_default_graph().get_tensor_by_name('output/logits:0')
 
 top_k_op = tf.nn.in_top_k(logits, labels, 1)
  ΦϖϨʔγϣϯͷऔಘͱάϥϑͷߏங
  69.  ࣮ߦ

  70. E tensorflow/core/common_runtime/executor.cc:334] Executor failed to create kernel. Invalid argument: NodeDef

    mentions attr 'Tshape' not in Op<name=Reshape; signature=tensor:T, shape:int32 -> output:T; attr=T:type>; NodeDef: Reshape = Reshape[T=DT_FLOAT, Tshape=DT_INT32, _device="/job:localhost/replica:0/task:0/cpu:0"] (pool3, Reshape/shape) [[Node: Reshape = Reshape[T=DT_FLOAT, Tshape=DT_INT32, _device="/job:localhost/ replica:0/task:0/cpu:0"](pool3, Reshape/shape)]] E tensorflow/core/client/tensor_c_api.cc:485] NodeDef mentions attr 'Tshape' not in Op<name=Reshape; signature=tensor:T, shape:int32 -> output:T; attr=T:type>; NodeDef: Reshape = Reshape[T=DT_FLOAT, Tshape=DT_INT32, _device="/job:localhost/replica:0/task: 0/cpu:0"](pool3, Reshape/shape) [[Node: Reshape = Reshape[T=DT_FLOAT, Tshape=DT_INT32, _device="/job:localhost/ replica:0/task:0/cpu:0"](pool3, Reshape/shape)]]  ಈ͖·ͤΜ
  71. ['input_image', 'conv1_1/weights', 'conv1_1/weights/read', 'conv1_1/Conv2D', 'conv1_1/biases', 'conv1_1/biases/read', 'conv1_1/BiasAdd', 'conv1_1/conv1_1', 'conv1_2/weights', 'conv1_2/weights/read',

    'conv1_2/Conv2D', 'conv1_2/biases', 'conv1_2/biases/read', 'conv1_2/BiasAdd', 'conv1_2/conv1_2', 'pool1',  ߏ੒͢Δϊʔυ 'conv2_1/weights', 'conv2_1/weights/read', 'conv2_1/Conv2D', 'conv2_1/biases', 'conv2_1/biases/read', 'conv2_1/BiasAdd', 'conv2_1/conv2_1', 'conv2_2/weights', 'conv2_2/weights/read', 'conv2_2/Conv2D', 'conv2_2/biases', 'conv2_2/biases/read', 'conv2_2/BiasAdd', 'conv2_2/conv2_2', 'pool2', 'conv3_1/weights', 'conv3_1/weights/read', 'conv3_1/Conv2D', 'conv3_1/biases', 'conv3_1/biases/read', 'conv3_1/BiasAdd', 'conv3_1/conv3_1', 'conv3_2/weights', 'conv3_2/weights/read', 'conv3_2/Conv2D', 'conv3_2/biases', 'conv3_2/biases/read', 'conv3_2/BiasAdd', 'conv3_2/conv3_2', 'pool3', 'Reshape/shape', 'Reshape', 'fc4/weights', 'fc4/weights/read', 'fc4/biases', 'fc4/biases/read', 'fc4/MatMul', 'fc4/add', 'fc4/fc4', 'fc5/weights', 'fc5/weights/read', 'fc5/biases', 'fc5/biases/read', 'fc5/MatMul', 'fc5/add', 'fc5/fc5', 'output/weights', 'output/weights/read', 'output/biases', 'output/biases/read', 'output/MatMul', 'output/logits']
  72. ['train_image', 'input_image', 'conv1_1/weights', 'conv1_1/weights/read', 'conv1_1/Conv2D', 'conv1_1/biases', 'conv1_1/biases/read', 'conv1_1/BiasAdd', 'conv1_1/conv1_1', 'conv1_2/weights',

    'conv1_2/weights/read', 'conv1_2/Conv2D', 'conv1_2/biases', 'conv1_2/biases/read', 'conv1_2/BiasAdd', 'conv1_2/conv1_2', 'pool1',  ܇࿅தʹΤΫεϙʔτͨ͠΋ͷͱൺֱ 'conv2_1/weights', 'conv2_1/weights/read', 'conv2_1/Conv2D', 'conv2_1/biases', 'conv2_1/biases/read', 'conv2_1/BiasAdd', 'conv2_1/conv2_1', 'conv2_2/weights', 'conv2_2/weights/read', 'conv2_2/Conv2D', 'conv2_2/biases', 'conv2_2/biases/read', 'conv2_2/BiasAdd', 'conv2_2/conv2_2', 'pool2', 'conv3_1/weights', 'conv3_1/weights/read', 'conv3_1/Conv2D', 'conv3_1/biases', 'conv3_1/biases/read', 'conv3_1/BiasAdd', 'conv3_1/conv3_1', 'conv3_2/weights', 'conv3_2/weights/read', 'conv3_2/Conv2D', 'conv3_2/biases', 'conv3_2/biases/read', 'conv3_2/BiasAdd', 'conv3_2/conv3_2', 'pool3', 'Reshape/shape', 'Reshape', 'fc4/weights', 'fc4/weights/read', 'fc4/biases', 'fc4/biases/read', 'fc4/MatMul', 'fc4/add', 'fc4/fc4', 'fc5/weights', 'fc5/weights/read', 'fc5/biases', 'fc5/biases/read', 'fc5/MatMul', 'fc5/add', 'fc5/fc5', 'output/weights', 'output/weights/read', 'output/biases', 'output/biases/read', 'output/MatMul', 'output/logits']
  73.  ݁࿦ Α͘Θ͔Βͳ͍

  74.  /FYU ʰ5FOTPS'MPXΛ"OESPJEͰ࣮ߦ͠Α͏ʂʱ ݹ઒ɹ৽ ։ൃτϥοΫϧʔϜ5

  75.  ػցֶशϋϯζΦϯ https://gcpug-tokushima.connpass.com/event/43430/

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