SlideShare a Scribd company logo
1 of 43
深層学習
Day4
Day4
01 強化学習
02 AlphaGo
03 軽量化・高速化技術
04 応用モデル
05 Transformer/GAN
06 物体検知・セグメン
テーション
行動
1-3
01 強化学習
 強化学習
これまでの教師あり学習では求めた結果と正解値との誤差を求め、誤差が小さくなるよう
パラメータを更新し、予測や分類をしていた。
強化学習では、ある環境において方策を行う。その方策にて得る報酬を最大化するよう試
行錯誤を繰り返し、優れた方策を見つけ出すことが目的。
状態
S
状態
S´
行動
1-2
行動(a)
1-1
・・・
行動2-
2-3
行動
2-2
行動
2-1
・・・
・・・
エージェント
価値
価値
価値
Q(s, a)
価値
価値
価値
Q(s´,a)
報酬
※Q(s,a):状態と行動から価値を定義する
行動価値関数
01 強化学習
 価値Q(s, a)の最適化
・モンテカルロ法:1連の行動(エピソード)後、Qテーブルを更新
・Qラーニング:行動毎にQテーブルを更新
A B
C D
Qラーニング:
Q(s, a) = r(s, a) + γMax( Q( s´, a ))
γ:割引率(γは0~1, 0に近いほど目先重視)
r(s, a) : 報酬
初期のQテーブル
ご褒美Get!
Q(B, D) = 100
01 強化学習
 Qラーニング(例)
Q(s, a) = r(s, a) + γMax( Q( s´, a )) γは0.8とする
Q(A, B) = 0 + 0.8 × Max(Q(B, A), Q(B, B), Q(B, D))
= 0 + 0.8 × Max(0, 0, 100)
= 80
これを繰り返す。
初期のQテーブル
状態や行動が多かったり離散的ではなく連続的であったりするので、これを発展させてNNを使用するDQNがある。(Deep Q-Network)
その際にはε-greedy法(たまにはランダムな行動をさせてもっとよい価値を見つける)、Experience Replay(従来のQ学習のように
1ステップごとにそのステップの内容(experience)を学習するのではなく、メモリ(replay buffer)に各ステップの内容を保存しておき、
メモリから内容をランダムに取り出して(replay)、ニューラルネットワークに学習させる方法)を使う。
01 強化学習
 方策勾配
状態sのときに行動aをとる確率をπ(a|s)とする。これ自体がNNでパラメータ
Θとして、
S
a1
Θ
状態sのときに行動aをとる確率をπ(a|s)とする。これ自体がNNでパラメータΘとすると更
新式は以下。
Θ = Θ + ε∇J(Θ) ← 最大にしたいので足し算。Jは目的関数でE(二乗誤差やクロスエントロピーに相当のもの)
なお、∇J(Θ)には、以下定理が成り立つ。
a2
02 AlphaGo
 AlphaGo Lee
なお、RollOutとPolicyNetは、最初に教師あり学習が行われる。その後にPolicyNet, ValueNetの強化学習が行われる。
02 AlphaGo
 AlphaGo Zero
※PlicyValueNetにはResidual Networkが使われている。ネットワークにショートカット構造を追加して、勾配の爆発、消失を抑える
効果を狙ったもの
なお、人間の教師データは用いず、すべて自前(石の配置のみの強化学習)。
03 軽量化・高速化技術
 分散深層学習
04 応用モデル
 MobileNet
畳み込みの処理をフィルタ(K×K)とそのフィルタの数分(M)で一気に処理せず、
フィルタ(K×K)・1フィルタと、単位フィルタ(1×1)・Mチャネルの処理
をそれぞれ別に実施し最後に合わせることで計算量を削減。
前者をDepthWise Convolution, 後者をPointWise Convolutionと名付けた。
(確認テストでも問われた)
04 応用モデル
 Dense Net
Alpha GOにも出てきたResidualNet(ResNet)の1種。
前方の各層からの出力全てが後方
の層への入力として用いられる
xl = H[x0, x1, x2, ・・・, xl-1]
初期k0とするといずれの層も出力はkなので、
k0+k, k0+2k, k0+3k, k0+4kとなっていく。kはgrouth rateとよ
び、小さい整数のほうがNetworkが小さくなってよい。
04 応用モデル
 バッチ正規化(Batch Norm)
学習時間の短縮や初期値への依存低減、過学習の抑制など効果があるが、Batch Sizeが小さ
い条件下では、学習が収束しないことがあり、代わりにLayer Normalizationなどの正規化手法
が使われることが多い。
それぞれのチャンネル
の平均と分散を求め正
規化を実施
全てのチャネルの平均
と分散を求め正規化を
実施。したがってミニバ
ッチの数に依存しない
Bach Normのバッチサイズが
1と等価。コントラストの正規化、
画像スタイルの転送やテクス
チャ合成タスクに利用
04 応用モデル
 Wavenet
生の音声波形を生成する深層学習モデル。高解像度の画像を精密に生成できるPixcel CNN
を音声に応用したもの。パラメータ数に対する受容野が広い時系列データに対してDilated
CNN(層が深くなるほどリンクを離す)を実施する。パラメータ数に対する受容野が広いこ
とが利点。(確認テストでも問われた)
下図ではDilated = 1, 2, 4, 8となっている。
05 Transformer
 Transformer
・Seq2seq(RNNベースEncoder-Decoderモデル)よりも早くて精度が高い
・RNNもCNNも使わずに Attentionのみを使用 したEncoder-Decoderモデルで計算量も精度
も改善。しかも並列計算可能
・大枠が① Encoder-Decoderとなっており、②Self-Attentionと③Position-wise Feed-
Forward Networkが組み込まれている。
・Self Attention
Self-Attention層はSeq2Seqなどで付随される形で利用されていたAttention層(異なるデー
タ間の照応関係を獲得する)とは異なり、入力データ内の単語同士の照応関係情報(類似度
や重要度)を獲得する。Itが何を指しているかなどわかるようにもなった。
例)
従来のAttention I have a dog. ⇔ 私は犬を飼っています
⇒このとき、例えば「I」は、特に「私」や「飼っています」との照応関係を獲得する
Self-Attention I have a dog. ⇔ I have a dog.
⇒このとき、例えば「I」は、特に「I」、「have」との照応関係を獲得する
05 Transformer
 Transformer
Encoder
・Positional Encoding
単語ベクトルに単語の位置を追加
・Multi-Head Attention
8つのScaled dot product attentionの出力をConcatしたもの
※Scaled dot product attention
全単語に関するAttentionをまとめて計算したもの(dkはKの次元)
Qは入力値(単語x1)×重み(Wq)。Kは入力値×重み(Wk)。Vは入力値×重み(Wv)
単語1つ1つにQVKを予め定めておく。
・Add & Norm
Add (Residual Connectioon)
入出力の差分の学習。だが、実装上は出力に入力を加算しているだけ。
→学習・テストエラーの低減
Norm(Layer Norm)
各層においてバイアスを除く活性化関数への入力を平均0、分散1に正則化
→学習の高速化
・Feed Forward Network
入力xにW1重みをかけて線形変換→ReLu→重みW2で線形変換
05 Transformer
 Transformer
Decoder
・Positional Encoding
Encoderと同じ。同じものは以降は記載省略する。
・Masked Multi-Head Attention
右図の「Mask(opt)」の部分で予測する単語以降はSoftMax
に渡さないようにする。カンニング防止のようなもの。
・Multi-Head Attention
・Add & Norm
・Feed Forward Network
05 GAN
 GAN(Generative Adversarial Nets)
敵対的生成ネットワーク。「教師なし学習」による画像生成。
お札の偽造者(Generator<G>)が頑張って偽造紙幣を作成(G(z))、一方で警察官がそれを
見抜こう(Discriminator<D(x)>)としてくる。
警察官は自分が勝利する確率を最大に、偽造者は警察が勝利する確率を最小にするよう頑
張る。(ミニマックスゲーム)
どんどん偽造精度があがってくるイメージ。
05 GAN
 GAN(Generative Adversarial Nets)
敵対的生成ネットワーク。「教師なし学習」による画像生成。
お札の偽造者(Generator<G>)が頑張って偽造紙幣を作成(G(z))、一方で警察官がそれを
見抜こう(Discriminator<D(x)>)としてくる。
警察官は自分が勝利する確率を最大に、偽造者は警察が勝利する確率を最小にするよう頑
張る(ミニマックスゲーム)。価値関数Vとすると
どんどん偽造精度があがってくるイメージ。
05 GAN
 GAN(Generative Adversarial Nets)
お互いが競い合う価値関数は以下。
以下のステップにより算出。
ステップ1により、Gを固定としたときの価値関数が最大となるD(x)は
ステップ2により、価値関数Vは
05 GAN
 DCGAN(Deep Convolutional GAN)
GANに畳み込み層を利用したもの。
・Generator
中間層はReLU、最後はtanh。中間層は全結合なし、Bach Normあり。
・Discriminator
畳み込み層により画像から特徴量を抽出し、最終層をsigmoid関数で活性化。
中間層は全結合なし、Bach Normあり。
乱数が
画像に。
G(z)
06 物体検知・セグメンテーション
 分類・物体検知・意味領域分割・個体領域分割
分類(Classification):画像に対してラベル付け
物体検出(Object Detection):Bounding Box、箱でオブジェクトを検知
意味領域分割(Semantic Segmentation):その中でどこがラベルか(例だとどれが風船か)
個別領域分割(Instance Segmentation):例だと風船それぞれのクラスラベル付け
06 物体検知・セグメンテーション
 物体検知
conf 0.994で犬を検出、conf 0.982で猫を検出
06 物体検知・セグメンテーション
 データセットと適切なデータセットの選び方
代表的なデータセットは以下の通り。
画像当たりのBox数(Box/画像)の値で、自分がやろうとしていることに対して適切なデータ
セットを選ぶ。さらに、クラス数からも選ぶ。
クラス数が多くてもよいとは限らず、例えば同じノートパソコンでも、Laptop, Surfaceな
ど違うクラス分けがされて多い場合もある。
06 物体検知・セグメンテーション
 評価指標
confが0.5以上なら採用(threshold = 0.5)の場合、クラス分類だと0.5未満はpred列「0」とし
ている。物体検出ではconfが0.5以上のものからを対象とする。(0.5未満は下図の通り物体検
出には対象となっていない)
06 物体検知・セグメンテーション
 物体位置の評価指標(IoU(Intersection over Union))
Ground-Truth BoundingBoxとPredicted BoundedBoxの全体和分の重なり部分
(真と予想のうちどれだけ重なってるか)
06 物体検知・セグメンテーション
 物体位置の評価指標(IoU(Intersection over Union))
conf=0.5, IoU = 0.5を閾値としたときTP, FPの判定は以下の通り。
注意として、すでに検出済みの場合はFPとなる(下表のP5)
06 物体検知・セグメンテーション
 物体位置の評価指標(IoU(Intersection over Union))
下表はPic1~4についてのもので、人かどうかだけの判定とする。Pic.4にも人が写っていた。
P5, P6は基準値をconf, IoUともに超えているがすでに判定済みのためFPとなっている。
人が写っていたPic.4がおそらくconf0.5未満だったため対象となっていないことからRecallの
分母に1がプラスされている。
06 物体検知・セグメンテーション
 物体位置の評価指標(AP(Average Precision))
クラスラベルを固定して(例えば、人など)横軸にRecall、縦軸にPrecisionをとったときの面積。
0.05ずつconfを増やし
たとき、それぞれの
Precision, Recallの値
をとって、その面積
 mAP
APをクラス数で平均したもの。
06 物体検知・セグメンテーション
 物体位置の評価指標(MS COCO)
mAPはIoU=0.5でやっていたが、IoUを0.5から0.95までそれぞれのときのmAPの平均
06 物体検知・セグメンテーション
 物体位置の評価指標(FPS(Frames Per Second))
検知の時間も大切。1秒当たりにいくつフレームを処理するか。
右にいくほど処理が速い。ただし、それぞれデータ
セットに何を使ったかも重要
左にいくほど処理時間が短くてよい。
06 物体検知・セグメンテーション
 2段階検出器・1段階検出器
候補領域検出とクラス推定を別々にやるか、同時にやるか。特徴とフレームワークは以下の通り。
06 物体検知・セグメンテーション
 1段階検出器SSD
Default Boxを用意しておき、Boxを変形してconfを求める。以下はアーキテクチャ。
06 物体検知・セグメンテーション
 1段階検出器SSD
Default Boxを用意しておくことで生ずる問題として以下があり、それぞれ対応も記載する。
・Non-Maximum Suppression
Boxが重なってしまっている場合、confの1番大きなものだけにする
・Hard Negative Mining
右図のように背景が多すぎの場合に比率として6以下とする
などで無駄なBoxを削減する。
06 物体検知・セグメンテーション
 Semantic Segmentation
畳込みとpoolingで右図のように犬・猫が分かれる。Poolingで輪郭が失われてしまうので、低レイ
ヤーPooling層の出力をelement-wise addition することでローカルな情報を補完してからUp-
samplingする。Skip-Connectionを入れたU-Netというものもある。
演習
01 強化学習
 Qラーニング
以下のサイトを参照。繰り返し更新していくことで、最終的に経路が出力された。
https://dse-souken.com/2021/05/18/ai-17/
03 軽量化・高速化技術
 プルーニング
以下のサイトを参照。alphaの値でどのくらいプルーニングされて最適なのか確認。
https://colab.research.google.com/drive/1a8CwUouDwdOrg3Wd4qSY2XvynKi3LkgE#scrollTo
=fzta30Dh0HI9
Tree Score = 木の不純度の総和 + α x ノードの数
なので、このバランスをとれるαを決める。
alha=0.011くらいがtestのacuracyが
高いらしい。(右図が実行結果)
Tenforflow
 演習のソースコードを実施
ts.sessionなどでエラーとなり、最近はsessionいらずといった記事もあったので以下の通り
修正して実行できた
Tensorflow
 演習のソースコードを実施
やりながらわかったが、TenSorflowには1系と2系があり、サンプルコードは1系記法になっ
ているのでエラーとなるようだ。tf .compat.v1.placeholderのようにcompat.v1を間に入れると
回避できる。
以下は線形回帰(左)と非線形回帰(右)。
Keras
 演習のソースコードを実施
以下はKerasの線形回帰。
05 Transfer
 演習のソースコードを実施
参考
参考
 強化学習
https://dajiro.com/entry/2020/05/18/091134
 Alpha GO
https://www.slideshare.net/suckgeunlee/aialphago
 Transformer
https://deepsquare.jp/2020/07/transformer/#outline__1_2
https://qiita.com/omiita/items/07e69aef6c156d23c538
 GAN
https://www.imagazine.co.jp/gan:敵対的生成ネットワークとは何か%E3%80%80~「教師/

More Related Content

Featured

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by HubspotMarius Sescu
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTExpeed Software
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsPixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 

Featured (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

ラビットチャレンジレポート 深層学習Day4