Slide 1

Slide 1 text

TFUG Okinawa val.2 ΞΠύʔୂ௕@ླྀٿେֶ

Slide 2

Slide 2 text

औΓʹདྷͨ

Slide 3

Slide 3 text

ຊ೔͓࿩͢Δ͜ͱ

Slide 4

Slide 4 text

ຊ೔͓࿩͔ͨͬͨ͜͠ͱ • YOLOͱ͸ • TensorflowͰ૊ΜͰΈͨ • ૊ΜͰΈͨYOLOΛֶशͤͯ͞Έͨ

Slide 5

Slide 5 text

ຊ೔͓࿩͔ͨͬͨ͢͠Δ͜ͱ • YOLOͱ͸ • TensorflowͰ૊ΜͰΈͨ • ૊ΜͰΈͨYOLOΛֶशͤͯ͞Έͨ

Slide 6

Slide 6 text

ࣗݾ঺հ

Slide 7

Slide 7 text

ࣗݾ঺հ • ΞΠύʔୂ௕ • ͪΎΒσʔλגࣜձࣾ • PyData.OkinawaڞಉΦʔΨφΠβʔ • Pythonͱո्ͱΫιΈ͍ͨͳөը͕޷͖Ͱ͢

Slide 8

Slide 8 text

๻ͷϨϕϧ • ਺ֶΘ͔ΒΜ • TensorflowΘ͔ΒΜ • σΟʔϓϥʔχϯάઙ͍ཧղ • ͭ·Γॳ৺ऀ

Slide 9

Slide 9 text

(YOLOΛબ୒ͨ͠) ܦҢ

Slide 10

Slide 10 text

ܦҢ Ϙεʣը૾ೝࣝͷҊ݅͘ΔΑʂ ๻ʣ͓ɺ͕Μ͹Δ͍ͧ Ϙεʣ·ͩΘ͔ΒΜ͚ͲObject DetectionͬΆ͍Αʂʂ ๻ʣ;͊ʔʔʔ

Slide 11

Slide 11 text

ษڧͤͶ͹ʢਅإʣ

Slide 12

Slide 12 text

YOLO(v3)

Slide 13

Slide 13 text

YOLOͱ͸ • ϦΞϧλΠϜΦϒδΣΫτݕग़ΞϧΰϦζϜ • YOLO(You Look Only Onse) • darknetͱ͍͏ϑϨʔϜϫʔΫͰಈ͔ͤΔ • σϞ͕͋Δ • ʢݕग़͕ʣ଎͍

Slide 14

Slide 14 text

darknet https://pjreddie.com/darknet/

Slide 15

Slide 15 text

YOLOͱ͸ • ը૾ೖྗ͢ΔͱӈԼͷΑ͏ͳ݁ՌʹͳΔ • ʮ΋ͷʯͷݕग़͢Δ͚ͩ
 Ͱͳ͘ɺΫϥε΋෼ྨ
 ͢Δɻ͠Ύ͍͝

Slide 16

Slide 16 text

YOLOͱ͸

Slide 17

Slide 17 text

YOLOͷ࢓૊Έ

Slide 18

Slide 18 text

YOLOͷ࢓૊Έ • ʢ·ʹ͋Θͳ͔ͬͨ͝ΊΜʣ • ͕ͬͪ͜Θ͔Γ΍͍͢ͷͰ֬ೝ͍ͯͩ͘͠͞ • https://github.com/leetenki/YOLOv2/blob/ master/YOLOv2.md

Slide 19

Slide 19 text

YOLOͷ࢓૊Έ • ʢ·ʹ͋Θͳ͔ͬͨ͝ΊΜʣ • ͕ͬͪ͜Θ͔Γ΍͍͢ͷͰ֬ೝ͍ͯͩ͘͠͞ • https://github.com/leetenki/YOLOv2/blob/ master/YOLOv2.md

Slide 20

Slide 20 text

No content

Slide 21

Slide 21 text

ֶͼͷಓΛ੾Γସ͑Δ

Slide 22

Slide 22 text

पΓͷ໠ऀͷֶͼํ 1. ࿦จಡΉ 2. هࣄΛړΔ 3. ཧղͨ͠ɻΑ࣮͠૷͠Α͏

Slide 23

Slide 23 text

΅͘ʢLv.1ʣ 1. ਆ༷ʢ࣮૷͍ͯ͠ΔਓɾίʔυʣΛݟ͚ͭΔ 2. ࣸܦ͢Δ 3. ͬ͘͟Γཧղͨ͠ -> هࣄړΔ

Slide 24

Slide 24 text

ਆ༷ʢ࣮૷ʣΛ୳͢

Slide 25

Slide 25 text

ਆ͸͍ͨ

Slide 26

Slide 26 text

ਆͷهࣄ https://itnext.io/implementing-yolo-v3-in-tensorflow-tf-slim-c3c55ff59dbe

Slide 27

Slide 27 text

ࣸܦ͢Δ

Slide 28

Slide 28 text

ͦͷલʹ؀ڥͷ࿩ • Ubuntu 16.04(Docker) • Python 3.7(Anaconda) • Tensorflow 1.12

Slide 29

Slide 29 text

Tensorflow Πϯετʔϧ $ pip3 install --upgrade tensorflow Collecting tensorflow Could not find a version that satisfies the requirement tensorflow (from versions: ) No matching distribution found for tensorflow ݟ͔ͭΒͳ͍ͱ͸ɾɾɾɾʁ

Slide 30

Slide 30 text

ఘΊͳ͍ؾ࣋ͪ $ pip3 install —upgrade https://storage.googleapis.com/tensorflow/ mac/cpu/tensorflow-1.10.1-py3-none-any.whl https://qiita.com/nahshi/items/fcf4898f7c45f11a5c63

Slide 31

Slide 31 text

ʗ(^o^)ʘ Traceback (most recent call last): File "YOLO_small_tf.py", line 3, in import tensorflow as tf File "/opt/conda/lib/python3.7/site-packages/tensorflow/__init__.py", line 22, in from tensorflow.python import pywrap_tensorflow # pylint: disable=unused-import File "/opt/conda/lib/python3.7/site-packages/tensorflow/python/ __init__.py", line 49, in from tensorflow.python import pywrap_tensorflow File "/opt/conda/lib/python3.7/site-packages/tensorflow/python/ pywrap_tensorflow.py", line 58, in from tensorflow.python.pywrap_tensorflow_internal import * File "/opt/conda/lib/python3.7/site-packages/tensorflow/python/ pywrap_tensorflow_internal.py", line 114 def TFE_ContextOptionsSetAsync(arg1, async): ^ SyntaxError: invalid syntax

Slide 32

Slide 32 text

པΜͩGoogle͞Μ

Slide 33

Slide 33 text

ఘΊͨ • Ubuntu 16.04(Docker) • Python 3.7 3.6(Anaconda) • Tensorflow 1.12

Slide 34

Slide 34 text

ʢվΊͯʣ ࣸܦ͢Δ

Slide 35

Slide 35 text

΍ͬͨ͜ͱ • YOLOv3ͷϞσϧͷఆٛ • yolov3ͷॏΈΛtensorfowͰಡΈࠐΊΔ༻ɺ convert͢Δॲཧ • σϞεΫϦϓτ

Slide 36

Slide 36 text

ࡶͳίϝϯτΛ࢒ͭͭ͠΋ ࣸܦͰ͖ͨ

Slide 37

Slide 37 text

࣮ߦͨ݁͠Ռ

Slide 38

Slide 38 text

࣮ߦͨ݁͠Ռ

Slide 39

Slide 39 text

ʢͱΓ͋͑ͣ͸ʣ ͓k

Slide 40

Slide 40 text

͜ͷޙɺࣗ෼Ͱֶशͤͨ͞Γɺ FineTuningͱ͔֎Εσʔλͷ ߟ࡯ͱ͔΍ͬͯΈ͔͚ͨͬͨͲ ཧղ͕ؒʹ߹Θͳ͔ͬͨͷͰ Tensorflowͷ࣮૷ͷ࿩Λ͠·͢

Slide 41

Slide 41 text

࣮૷ͷ࿩

Slide 42

Slide 42 text

• ௚ײతʹɺKerasΈ͍ͨʹॻ͚Δ • tf.contrib.keras͸ɾɾɾʁ • tf.contrib͸tensorflowνʔϜ͸αϙʔτ͠ ͍ͯͳ͍͚Ͳɺςετऴ͍͑ͯͣΕ͸Ϛʔδ ͍ͨ͠ΑͶతͳύοέʔδΒ͍͠ ࣮૷ͷ࿩ tf.contrib.slim

Slide 43

Slide 43 text

࣮૷ͷ࿩ tf.contrib.slim with slim.arg_scope([slim.max_pool2d], padding=‘SAME’): # Layer01 h_conv1 = slim.conv2d(x_image, 32, [5, 5]) h_pool1 = slim.max_pool2d(h_conv1, [2, 2]) # Layer02 h_conv2 = slim.conv2d(h_pool1, 64, [5, 5]) h_pool2 = slim.max_pool2d(h_conv2, [2, 2]) # Layer03 h_pool2_flat = slim.flatten(h_pool2) h_fc1 = slim.fully_connected(h_pool2_flat, 1024)

Slide 44

Slide 44 text

• with۟ͰϒϩοΫΛ࡞ΓɺϒϩοΫ಺ͷؔ਺ ͷσϑΥϧτҾ਺Λ·ͱΊͯఆٛͰ͖Δ • ͨͩͨͩศར ࣮૷ͷ࿩ slim.arg_scope()

Slide 45

Slide 45 text

࣮૷ͷ࿩ slim.arg_scope() h_conv1 = slim.conv2d(x_image, 32, [5, 5], activation_fn=tf.nn.relu, weights_initializer=tf.truncated_normal_initializer(stddev=0.1), biases_initializer=tf.constant_initializer(0.1)) with slim.arg_scope([slim.conv2d], activation_fn=tf.nn.relu, weight_initializer=tf.truncated_normal_initializer(stddev=0.1), biases_initializer=tf.constant_initializer(0.1): h_conv1 = slim.conv2d(x_image, 32, [5, 5])

Slide 46

Slide 46 text

• ఆֶٛͨ͠शάϥϑΛඳըͯ͘͠ΕͨΓɺॏ ΈΛάϥϑԽͨ͠ΓͱԿ͔ͱศརͳ΍ͭ Tensorboard

Slide 47

Slide 47 text

Tensorboard ࢖͏ͨΊͷ࣮૷ (ఆٛͨ͠άϥϑඳըͷΈ) with tf.Session() as sess: # tensorboard file_writer = tf.summary.FileWriter('./logs/', sess.graph)

Slide 48

Slide 48 text

Tensorboard

Slide 49

Slide 49 text

஫ҙ͍ͨ͜͠ͱ with tf.variable_scope(‘darknet-53'): route_1, route_2, inputs = darknet53(inputs) with tf.variable_scope('yolo-v3'): with tf.variable_scope('detect_1'): route, inputs = _yolo_block(inputs, 512) • ఆ͚ٛͨͩ͠Ͱ͸
 άϥϑ͸ݟͮΒ͍ • είʔϓΛ
 ༻ҙ͠·͠ΐ͏ είʔϓແ είʔϓ༗

Slide 50

Slide 50 text

ཧղ͢ΔͨΊʹࢼߦͨ͠࿩

Slide 51

Slide 51 text

• ίʔυΛཧղ͠Α͏ͱͨ͠ͱ͖ɺೖྗͱग़ྗ ΍Βɺม਺ͷத਎Λ֬ೝ͠ͳ͕Β΍Γ·ͤΜ ͔ʁ • ๻͸΍Γ·͢ • ͱ͍͏͜ͱͰɺ࠷ڧͷprintσόοάΛࢼͦ͏ ͱ͠·ͨ͠ Tensorflowͷσόοά

Slide 52

Slide 52 text

• ʗ(^o^)ʘ • Tensorflow͸άϥϑΛߏ੒ͨ͋͠ͱʹσʔλ Λྲྀͯ͠ॲཧ͢ΔͷͰɺఆ͍ٛͯ͠Δͱ͜Ζ Λεςοϓͯ͠printͯ͠΋Θ͔Βͳ͍ ࠷ڧͷprintσόοά Tensor("xxx:0", shape=TensorShape([Dimension(1), Dimension(1)]), dtype=float32)

Slide 53

Slide 53 text

tf.print • ೖྗ͞ΕͨTensorͷ݁ՌΛɺ
 stdout΍ΒɺϩάϨϕϧͰग़ྗͯ͘͠ΕΔ • ਆ • ͪͳΈʹ΍΍͍͚͜͠Ͳɺtf.Print͸Ҿ਺΋ҧ͏͠ඇਪ঑Ͱ͢ • ͔͠͠ɺSessionฦ͞ͳ͍ͱ͍͚ͳ͍ͷͰɺϞσϧΛఆٛ͢Δͱ͜Ζʹ૊ΈࠐΉ࡞ۀ ʹϋϚͬͨ • ·ͨɺTensorflowͰఆٛͨ͠ม਺ͷத਎͸ݟΕ͕ͨɺ࣍ݩΛ֬ೝ͢ΔͨΊʹtf.shape ͱ͔ڬΉͱ݁Ռ͕ฦͬͯ͜ͳ͘ͳΔɻͳͥ • ʢ͕࣌ؒͳ͍ͷͰʣఘΊͨ tensor = tf.range(10) print_op = tf.print(tensor)

Slide 54

Slide 54 text

tfdebug • Tensorflow༻ͷPythonͷpdbΈ͍ͨͳ΍ͭ • https://www.tensorflow.org/guide/debugger • λʔϛφϧͰṖͷςΫϊϩδʔUI • ࢖͍΍͍͢ʢ࢖͍ͮΒ͍ʣ • ݟํ͕Θ͔Βͳ͍ͷͰΠϥΠϥͭͭ͠΋υΩϡϝϯτ
 ಡΈͳ͕Β֬ೝதʢ࿝֐ʣ • vimϥΠΫ͡Όͳ͍ͱݏ

Slide 55

Slide 55 text

ࡶʢͳʣ ײʢ૝ʣ

Slide 56

Slide 56 text

ࡶײ • Θ͔ΒΜͱ͜Ζ͕Θ͔ͬͨ • ͍͍࿩ͩͧʂʢܾͯ͠ෛ͚੯͠ΈͰ͸ͳ͍ʣ • ࿦จಡ΋͏ • Tensorflow΋਺ֶ΋ɺ΋ͬͱ͕Μ͹Γ·͠ΐ͏

Slide 57

Slide 57 text

No content