-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
2164 lines (884 loc) · 151 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html class="theme-next pisces use-motion" lang="zh-Hans">
<head>
<meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
<meta name="theme-color" content="#222">
<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
<link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />
<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />
<link href="/css/main.css?v=5.1.2" rel="stylesheet" type="text/css" />
<meta name="keywords" content="Hexo, NexT" />
<link rel="shortcut icon" type="image/x-icon" href="/favicon.ico?v=5.1.2" />
<meta property="og:type" content="website">
<meta property="og:title" content="牧羊人小站">
<meta property="og:url" content="http://yoursite.com/index.html">
<meta property="og:site_name" content="牧羊人小站">
<meta property="og:locale" content="zh-Hans">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="牧羊人小站">
<script type="text/javascript" id="hexo.configurations">
var NexT = window.NexT || {};
var CONFIG = {
root: '/',
scheme: 'Pisces',
version: '5.1.2',
sidebar: {"position":"left","display":"post","offset":12,"offset_float":12,"b2t":false,"scrollpercent":false,"onmobile":false},
fancybox: true,
tabs: true,
motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn"}},
duoshuo: {
userId: '0',
author: '博主'
},
algolia: {
applicationID: '',
apiKey: '',
indexName: '',
hits: {"per_page":10},
labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
}
};
</script>
<link rel="canonical" href="http://yoursite.com/"/>
<title>牧羊人小站</title>
</head>
<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">
<div class="container sidebar-position-left
page-home">
<div class="headband"></div>
<header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
<div class="header-inner"><div class="site-brand-wrapper">
<div class="site-meta ">
<div class="custom-logo-site-title">
<a href="/" class="brand" rel="start">
<span class="logo-line-before"><i></i></span>
<span class="site-title">牧羊人小站</span>
<span class="logo-line-after"><i></i></span>
</a>
</div>
<p class="site-subtitle"></p>
</div>
<div class="site-nav-toggle">
<button>
<span class="btn-bar"></span>
<span class="btn-bar"></span>
<span class="btn-bar"></span>
</button>
</div>
</div>
<nav class="site-nav">
<ul id="menu" class="menu">
<li class="menu-item menu-item-home">
<a href="/" rel="section">
<i class="menu-item-icon fa fa-fw fa-home"></i> <br />
首页
</a>
</li>
<li class="menu-item menu-item-tags">
<a href="/tags/" rel="section">
<i class="menu-item-icon fa fa-fw fa-tags"></i> <br />
标签
</a>
</li>
<li class="menu-item menu-item-archives">
<a href="/archives/" rel="section">
<i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
归档
</a>
</li>
</ul>
</nav>
</div>
</header>
<main id="main" class="main">
<div class="main-inner">
<div class="content-wrap">
<div id="content" class="content">
<section id="posts" class="posts-expand">
<article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
<div class="post-block">
<link itemprop="mainEntityOfPage" href="http://yoursite.com/2017/12/31/【夕花朝食】丁酉晚钟/">
<span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
<meta itemprop="name" content="半城秋雨半城月">
<meta itemprop="description" content="">
<meta itemprop="image" content="/images/avatar.gif">
</span>
<span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
<meta itemprop="name" content="牧羊人小站">
</span>
<header class="post-header">
<h1 class="post-title" itemprop="name headline">
<a class="post-title-link" href="/2017/12/31/【夕花朝食】丁酉晚钟/" itemprop="url">丁酉晚钟</a></h1>
<div class="post-meta">
<span class="post-time">
<span class="post-meta-item-icon">
<i class="fa fa-calendar-o"></i>
</span>
<span class="post-meta-item-text">发表于</span>
<time title="创建于" itemprop="dateCreated datePublished" datetime="2017-12-31T23:53:23+08:00">
2017-12-31
</time>
</span>
<span class="post-category" >
<span class="post-meta-divider">|</span>
<span class="post-meta-item-icon">
<i class="fa fa-folder-o"></i>
</span>
<span class="post-meta-item-text">分类于</span>
<span itemprop="about" itemscope itemtype="http://schema.org/Thing">
<a href="/categories/夕花朝食/" itemprop="url" rel="index">
<span itemprop="name">夕花朝食</span>
</a>
</span>
</span>
</div>
</header>
<div class="post-body" itemprop="articleBody">
<p>又是一年,再次站在大悦城旁的天桥前,一样的时间一样的钟声,内心毅然涌起各种的思绪。丁酉年就这么过去了,乍一想是那么的快,那么的突然;再想想,倒是能想起很多很多,这一年大概也不是那么容易吧。经历过迷惘,经历过选择,有过不少悠然的时刻,也有过不少心累的时刻。闭上眼睛,能看见那个跌跌撞撞的自己一步一步蹒跚往前走,再睁开,眼角甚至不争气的湿润了一些。</p>
<p>春风拂面的时节,忘不了的是那个喧闹的惠新西街南口站。睡眼惺忪的自己,饿着肚子,跨域整个北京城;从西北角到东南角,3条地铁换乘,每天4个小时的往返;虽然每天都很累,但总会给自己一种自己至少很努力的感觉,大概这样就已经足够了吧。公司的食堂有着各种美味,虽然那是不觉得,之后辗转各处缺有了强烈的这种感觉。大概人都是对现在所拥有的感受不强,失去后才俞来俞想念。朝阳星辰交替的这条线路上也有着我对北京最美的记忆,在某个不知名的地铁站附近,那一片美不胜收的樱花树,看的那些霎那间,所有疲惫都那么值得了。</p>
<p>北京的夏天还是那么热,结束实习,回到学校准备考试,图书馆成了我的依赖之地。不是因为别的,只是贪图那里面空调带来的清凉。大概自己就是那么怕热吧,从小便如此。高中时候冬天毫无顾忌的光手疯狂刷题,南方的冬天随很凌冽却没什么令我后怕的。夏天却永远离不开风扇空调,热会侵蚀我的思绪,一点一点。每天往返图书馆的日子很无聊,准备新实习面试,努力补各种理论知识。由于中途回家一段时间的原因,cs231的课拖到7月初才 finish,毕竟在家的自己是永远不可能学习的- - 学习新知识总是有一种不可名状的美,枯燥之后喝的水都更加美味,坐累的起来走几步都觉得务必舒畅。图书馆,空调,书,cs231,deep learning,这大概就是自己对北京夏天的记忆了吧。</p>
<p>金秋,是收获的季节。对我来说却又那么多意外与惊喜。很幸运能在一家自己很喜欢的公司,做这自己很喜欢的事,学着自己感兴趣的东西,虽然只有一个月。还记得公司前台那几个丑萌丑萌的公仔,还记得公司休息室每天不限量的零食与下午1点30的水果(就记得吃的了,笑)。每天晚上回去,回想一天总会觉得自己又学到了不少东西。那时候就会很开心的想,啊,大概这就是做自己喜欢的事的感觉吧。意外总是不期而至,一个月后忽然就就接到 了MSRA 的 offer。在揪心的抉择之后,还是觉得或许应该去更大的平台试试,毕竟这样的机会下一次也许就没有了。北京的十月,永远是充满喜悦与惆怅的。</p>
<p>最后三个月便是无止境的终日与工作相伴,很累很累。有时半夜回来,抬头看看天上冰冷的圆月,自己对自己苦笑说,我也是见过凌晨2点的北京了。实习的方向和自己的兴趣有一些不 match,欣慰的是真的可以学到大量的知识。最近一个月几乎每天都是11点后回,0点之后也不再奇怪,逐渐有了腰酸背痛的毛病。最后下决心办了张健身卡,开始锻炼之路,令人惊喜的是,坚持锻炼之后确实不会那么经常的出现身体不适了。</p>
<p>到明天就真正24了,本命年或许应该对自己多一些期望,多一些目标吧。但真要列出来之时却又那么难以逐一数落,就简单说说吧。</p>
<p>再努力一点学习,努力提升一下自己,少吃一点垃圾食品,多健一些身,成熟一点,好好找工作,找好工作。嗯,这就是全部了,加油吧!</p>
</div>
<footer class="post-footer">
<div class="post-eof"></div>
</footer>
</div>
</article>
<article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
<div class="post-block">
<link itemprop="mainEntityOfPage" href="http://yoursite.com/2017/10/19/Mac-使用rar和unrar指令/">
<span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
<meta itemprop="name" content="半城秋雨半城月">
<meta itemprop="description" content="">
<meta itemprop="image" content="/images/avatar.gif">
</span>
<span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
<meta itemprop="name" content="牧羊人小站">
</span>
<header class="post-header">
<h1 class="post-title" itemprop="name headline">
<a class="post-title-link" href="/2017/10/19/Mac-使用rar和unrar指令/" itemprop="url">Mac 使用rar和unrar指令</a></h1>
<div class="post-meta">
<span class="post-time">
<span class="post-meta-item-icon">
<i class="fa fa-calendar-o"></i>
</span>
<span class="post-meta-item-text">发表于</span>
<time title="创建于" itemprop="dateCreated datePublished" datetime="2017-10-19T21:49:39+08:00">
2017-10-19
</time>
</span>
<span class="post-category" >
<span class="post-meta-divider">|</span>
<span class="post-meta-item-icon">
<i class="fa fa-folder-o"></i>
</span>
<span class="post-meta-item-text">分类于</span>
<span itemprop="about" itemscope itemtype="http://schema.org/Thing">
<a href="/categories/备忘/" itemprop="url" rel="index">
<span itemprop="name">备忘</span>
</a>
</span>
</span>
</div>
</header>
<div class="post-body" itemprop="articleBody">
<ul>
<li>下载<a href="http://note.youdao.com/" target="_blank" rel="external">RAR工具包</a>,下mac的包</li>
<li>从终端进入到解压文件夹rar,里面是刚才下载的文件</li>
<li>执行两条指令</li>
</ul>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line">sudo install -c -o $USER rar /usr/local/bin/</div><div class="line"></div><div class="line">sudo install -c -o $USER unrar /usr/local/bin</div></pre></td></tr></table></figure>
<ul>
<li>测试</li>
</ul>
<p>压缩文件A和B:rar a read.rar A B</p>
<p><img src="http://ws3.sinaimg.cn/large/005CRBrHly1g2kidmoc0uj30zq0aeta6.jpg" alt="83984158"></p>
<p>解压:unrar x read.rar</p>
<p><img src="http://wx1.sinaimg.cn/large/005CRBrHly1g2kidvy1ghj30yk0fc0vx.jpg" alt="83983382"></p>
</div>
<footer class="post-footer">
<div class="post-eof"></div>
</footer>
</div>
</article>
<article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
<div class="post-block">
<link itemprop="mainEntityOfPage" href="http://yoursite.com/2017/10/19/【论文笔记】Attention-Is-All-You-Need/">
<span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
<meta itemprop="name" content="半城秋雨半城月">
<meta itemprop="description" content="">
<meta itemprop="image" content="/images/avatar.gif">
</span>
<span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
<meta itemprop="name" content="牧羊人小站">
</span>
<header class="post-header">
<h1 class="post-title" itemprop="name headline">
<a class="post-title-link" href="/2017/10/19/【论文笔记】Attention-Is-All-You-Need/" itemprop="url">【论文笔记】Attention Is All You Need</a></h1>
<div class="post-meta">
<span class="post-time">
<span class="post-meta-item-icon">
<i class="fa fa-calendar-o"></i>
</span>
<span class="post-meta-item-text">发表于</span>
<time title="创建于" itemprop="dateCreated datePublished" datetime="2017-10-19T21:49:07+08:00">
2017-10-19
</time>
</span>
<span class="post-category" >
<span class="post-meta-divider">|</span>
<span class="post-meta-item-icon">
<i class="fa fa-folder-o"></i>
</span>
<span class="post-meta-item-text">分类于</span>
<span itemprop="about" itemscope itemtype="http://schema.org/Thing">
<a href="/categories/水滴石穿/" itemprop="url" rel="index">
<span itemprop="name">水滴石穿</span>
</a>
</span>
</span>
</div>
</header>
<div class="post-body" itemprop="articleBody">
<p>摘抄就不写了,有很多现成的可以参考,这里挑一些点写一下自己的理解。</p>
<p>整体结构如下<br><img src="http://ws1.sinaimg.cn/large/005CRBrHly1g2kjb8i9dqj31cs0xudmj.jpg" alt="46270443"></p>
<h4 id="Scaled-Dot-Product-Attention"><a href="#Scaled-Dot-Product-Attention" class="headerlink" title="Scaled Dot-Product Attention"></a>Scaled Dot-Product Attention</h4><p>paper中说主要提出了两种attention,Scaled Dot-Product和 Multi-Head 。其中scaled这个就是基本的点乘attention,区别在于它加了一个对维度的scale。</p>
<p><img src="http://wx4.sinaimg.cn/large/005CRBrHly1g2kjbh0lmzj31ai0iqgpy.jpg" alt="81012683"></p>
<p>之所以对点乘值除以一个根号dk,作者是说当Q和K的维度dk太大的时候,点乘的值也变得巨大,这样会使得softmax函数的梯度变得特别特别小。</p>
<blockquote>
<p>We suspect that for large values of dk, the dot products grow large in magnitude, pushing the softmax function into regions where it has extremely small gradients 4. To counteract this effect, we scale the dot products by 1/sqrt(dk).</p>
</blockquote>
<p>对于点乘的函数,我是这么理解的。。。<br><img src="http://wx4.sinaimg.cn/large/005CRBrHly1g2kjcnq7r8j312603eglv.jpg" alt="5755345"></p>
<pre><code>Qi 和 Vi都是k维,所以假设都是 1xk ,Q一共有n个,(K,V)一共有m对
Q dot KT分解为
[ Q1 ] [Q1*K1, Q1*K2...Q1*Km] [ W1 ]
[ Q2 ] dot [ K1,K2...Km] = [Q2*K1, Q2*K2...Q2*Km] = [ W2 ]
... ........ ...
[ Qn ] [Qn*K1, Qn*K2...Qn*Km] [ Wn ]
对应 (n,k)dot(k,m) = (n,m)
进过softmax之后,每一行代表一个权重信息Wi ,n行代表n个query各自取value时候的权重
[ W1 ] [ V1 ]
[ W2 ] dot [ V2 ]
... ...
[ Wn ] [ Vm ]
对应 (n,m)dot(m,v) = (n,v)
n行对应n个query,从而每个query最终得到一个weighted的value,还是保持v维
</code></pre><p>总之,最后每个query有一个weighted value, dv维</p>
<h4 id="Multi-Head-Attention"><a href="#Multi-Head-Attention" class="headerlink" title="Multi-Head Attention"></a>Multi-Head Attention</h4><p>这里设定的,原始Q,K,V的维度都等于d-model</p>
<p>基本思想就是分治,将Q,K,V全部分成h等份,每一份(dk=dv=dmodel/h)分别在linear变换后进入一个attention function ,得到的结果concate连接,再进过一个linear变换,得到最终结果。作者说这样的好处是可以充分让encoder-decoder的不同位置,通过不同的linear,体现出更丰富的结果</p>
<blockquote>
<p>Multi-head attention allows the model to jointly attend to information from different representation subspaces at different positions</p>
</blockquote>
<p>函数如下</p>
<p><img src="http://wx2.sinaimg.cn/large/005CRBrHly1g2kjdrtmitj316o048js2.jpg" alt="94634163"></p>
<p>这里面Q Wi,对应(n, dmodel) dot (dmodel,dk) = (n ,dk)</p>
<p>就是对Q做第i个linear变换,把它从dmodel维变成dk维,其实就是取Q的第i部分。K和V类似理解就好。</p>
<p>h份attention 函数parallel进行,每一份得到的结果也是 dv=dmodel/h,concate起来就又是dmodel维度了。</p>
</div>
<footer class="post-footer">
<div class="post-eof"></div>
</footer>
</div>
</article>
<article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
<div class="post-block">
<link itemprop="mainEntityOfPage" href="http://yoursite.com/2017/10/19/【caffe源码学习】l2-normalize-layer/">
<span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
<meta itemprop="name" content="半城秋雨半城月">
<meta itemprop="description" content="">
<meta itemprop="image" content="/images/avatar.gif">
</span>
<span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
<meta itemprop="name" content="牧羊人小站">
</span>
<header class="post-header">
<h1 class="post-title" itemprop="name headline">
<a class="post-title-link" href="/2017/10/19/【caffe源码学习】l2-normalize-layer/" itemprop="url">【caffe源码学习】l2_normalize_layer</a></h1>
<div class="post-meta">
<span class="post-time">
<span class="post-meta-item-icon">
<i class="fa fa-calendar-o"></i>
</span>
<span class="post-meta-item-text">发表于</span>
<time title="创建于" itemprop="dateCreated datePublished" datetime="2017-10-19T21:49:01+08:00">
2017-10-19
</time>
</span>
<span class="post-category" >
<span class="post-meta-divider">|</span>
<span class="post-meta-item-icon">
<i class="fa fa-folder-o"></i>
</span>
<span class="post-meta-item-text">分类于</span>
<span itemprop="about" itemscope itemtype="http://schema.org/Thing">
<a href="/categories/Caffe/" itemprop="url" rel="index">
<span itemprop="name">Caffe</span>
</a>
</span>
</span>
</div>
</header>
<div class="post-body" itemprop="articleBody">
<blockquote>
<p>参考的l2_normalize_layer来自<a href="https://github.com/gy20073/compact_bilinear_pooling" target="_blank" rel="external">Compact Bilinear Pooling</a></p>
</blockquote>
<p>先看一下hpp文件</p>
<h4 id="l2-normalize-layer-hpp"><a href="#l2-normalize-layer-hpp" class="headerlink" title="l2_normalize_layer.hpp"></a>l2_normalize_layer.hpp</h4><p>C++ hpp文件高亮支持一般,这里我就索性用截图了</p>
<p><img src="http://ws4.sinaimg.cn/large/005CRBrHly1g2kjfhy2hbj311e13aait.jpg" alt="51568918"></p>
<p>除了常规的cpu,gpu前向后向传播,还定义了一个叫<code>squared_</code>的Blob,用来存bottom的平方。top和bottom的blob都只有一个,类型名是<code>L2Normalize</code>。</p>
<h4 id="l2-normalize-layer"><a href="#l2-normalize-layer" class="headerlink" title="l2_normalize_layer"></a>l2_normalize_layer</h4><h4 id="Reshape"><a href="#Reshape" class="headerlink" title="Reshape"></a>Reshape</h4><p><img src="http://ws1.sinaimg.cn/large/005CRBrHly1g2kjg663jpj30yq08utas.jpg" alt="23341806"></p>
<p>把top 和 squared这两reshape成bottom的shape,[num,channel,height,width] 对应N <em> C</em> H * W</p>
<h4 id="Forward-cpu"><a href="#Forward-cpu" class="headerlink" title="Forward_cpu"></a>Forward_cpu</h4><p><img src="http://ws4.sinaimg.cn/large/005CRBrHly1g2kjghpefzj30x00egtcc.jpg" alt="80278970"></p>
<p>取bottom的数据到bottom_data, top和squared的数据都设为mutable待求。n是batch size N,d是dim,按照caffe的惯例还是等于<code>C * H * W</code>。</p>
<p>令squared等于bottom对应element值的平方,然后进入一个n循环,以样本为单位进行操作。每次循环取squared的样本下面长为d的全部元素和(即bottom的平方和),存到normsqr。然后每个bottom的每个元素除以normsqr的根号,赋值给top。</p>
<p>从而实现L2前向,<code>top[i] = bottom[i] / sqrt ( sum(bottom[j]*bottom[j]) )</code></p>
<p>用到的函数</p>
<ul>
<li><p><code>void caffe_sqr<float>(const int n, const float* a, float* y)</code> </p>
<p> 对应element_wise操作, y = a^2 ,注意是平方不是平方根。这里是 <code>squared_data = bottom_data * bottom_data</code></p>
</li>
<li><p><code>float caffe_cpu_asum<float>(const int n, const float* x)</code></p>
<p> 计算 vector x 的所有element的绝对值之和。这是是取squared_data的长度为<code>C * H * W</code>的元素和。</p>
</li>
<li><p><code>void caffe_cpu_scale<float>(const int n, const float alpha, const float *x,float* y)</code></p>
<p> 计算<code>y = alpha*x</code>,在这里 <code>top_data = pow(normsqr,-0.5)*bottom_data = bottom_data/pow(normsqr,0.5)</code>,而pow(normsqr,0.5)可以理解为bottom的平方和开根号。</p>
</li>
</ul>
<h4 id="Backward-cpu"><a href="#Backward-cpu" class="headerlink" title="Backward_cpu"></a>Backward_cpu</h4><p><img src="http://ws1.sinaimg.cn/large/005CRBrHly1g2kjgxd83ij30ys0hawiz.jpg" alt="59837972"></p>
<p>L2梯度的推导没怎么找到。。。</p>
<p>取top的data和diff,取bottom的data,bottom的diff设为mutable待求。n等于batch size N,d等于dim为<code>C* H * W</code>。</p>
<p>接下来还是n循环分样本做。</p>
<pre><code>a = top_data dot top_diff ,内积得到一个数值
bottom_diff = a * top_data
bottom_diff = top_diff - bottom_diff
a = bottom_data dot bottom_data
bottom_diff = pow(a,-0.5) * bottom_diff
= bottom_diff / pow(a,0.5)
</code></pre><p>用到的函数</p>
<ul>
<li><p><code>Dtype caffe_cpu_dot(const int n, const Dtype* x, const Dtype* y)</code></p>
<p> 返回x与y的内积,这里是top_data*top_diff ,返回一个数值</p>
</li>
<li><p><code>void caffe_sub<float>(const int n, const float* a, const float* b, float* y)</code></p>
<p> 实现element-wise的减 , y[i] = a[i] - b[i] 。这里是 bottom_diff = top_diff - bottom_diff。</p>
</li>
</ul>
<p>附完整代码</p>
<figure class="highlight c++"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div><div class="line">38</div><div class="line">39</div><div class="line">40</div><div class="line">41</div><div class="line">42</div><div class="line">43</div><div class="line">44</div><div class="line">45</div><div class="line">46</div><div class="line">47</div><div class="line">48</div><div class="line">49</div><div class="line">50</div><div class="line">51</div><div class="line">52</div><div class="line">53</div><div class="line">54</div><div class="line">55</div><div class="line">56</div><div class="line">57</div><div class="line">58</div><div class="line">59</div><div class="line">60</div><div class="line">61</div><div class="line">62</div><div class="line">63</div><div class="line">64</div><div class="line">65</div><div class="line">66</div><div class="line">67</div><div class="line">68</div></pre></td><td class="code"><pre><div class="line"></div><div class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string"><algorithm></span></span></div><div class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string"><cmath></span></span></div><div class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string"><vector></span></span></div><div class="line"></div><div class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">"caffe/layer.hpp"</span></span></div><div class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">"caffe/layers/l2_normalize_layer.hpp"</span></span></div><div class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">"caffe/util/math_functions.hpp"</span></span></div><div class="line"></div><div class="line"><span class="keyword">namespace</span> caffe {</div><div class="line"></div><div class="line"><span class="keyword">template</span> <<span class="keyword">typename</span> Dtype></div><div class="line"><span class="keyword">void</span> L2NormalizeLayer<Dtype>::Reshape(<span class="keyword">const</span> <span class="built_in">vector</span><Blob<Dtype>*>& bottom,</div><div class="line"> <span class="keyword">const</span> <span class="built_in">vector</span><Blob<Dtype>*>& top) {</div><div class="line"> CHECK(top[<span class="number">0</span>] != bottom[<span class="number">0</span>]) << <span class="string">"do not support in place operation"</span>;</div><div class="line"></div><div class="line"> top[<span class="number">0</span>]->Reshape(bottom[<span class="number">0</span>]->num(), bottom[<span class="number">0</span>]->channels(),</div><div class="line"> bottom[<span class="number">0</span>]->height(), bottom[<span class="number">0</span>]->width());</div><div class="line"> squared_.Reshape(bottom[<span class="number">0</span>]->num(), bottom[<span class="number">0</span>]->channels(),</div><div class="line"> bottom[<span class="number">0</span>]->height(), bottom[<span class="number">0</span>]->width());</div><div class="line">}</div><div class="line"></div><div class="line"><span class="keyword">template</span> <<span class="keyword">typename</span> Dtype></div><div class="line"><span class="keyword">void</span> L2NormalizeLayer<Dtype>::Forward_cpu(<span class="keyword">const</span> <span class="built_in">vector</span><Blob<Dtype>*>& bottom,</div><div class="line"> <span class="keyword">const</span> <span class="built_in">vector</span><Blob<Dtype>*>& top) {</div><div class="line"> <span class="keyword">const</span> Dtype* bottom_data = bottom[<span class="number">0</span>]->cpu_data();</div><div class="line"> Dtype* top_data = top[<span class="number">0</span>]->mutable_cpu_data();</div><div class="line"> Dtype* squared_data = squared_.mutable_cpu_data();</div><div class="line"> <span class="keyword">int</span> n = bottom[<span class="number">0</span>]->num();</div><div class="line"> <span class="keyword">int</span> d = bottom[<span class="number">0</span>]->count() / n;</div><div class="line"> caffe_sqr<Dtype>(n*d, bottom_data, squared_data);</div><div class="line"> Dtype epsilon = <span class="number">0.0000001</span>;</div><div class="line"> <span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">0</span>; i < n; ++i) {</div><div class="line"> Dtype normsqr = caffe_cpu_asum<Dtype>(d, squared_data+i*d);</div><div class="line"> caffe_cpu_scale<Dtype>(d, <span class="built_in">pow</span>(normsqr + epsilon, <span class="number">-0.5</span>),</div><div class="line"> bottom_data+i*d, top_data+i*d);</div><div class="line"> }</div><div class="line">}</div><div class="line"></div><div class="line"><span class="keyword">template</span> <<span class="keyword">typename</span> Dtype></div><div class="line"><span class="keyword">void</span> L2NormalizeLayer<Dtype>::Backward_cpu(<span class="keyword">const</span> <span class="built_in">vector</span><Blob<Dtype>*>& top,</div><div class="line"> <span class="keyword">const</span> <span class="built_in">vector</span><<span class="keyword">bool</span>>& propagate_down, <span class="keyword">const</span> <span class="built_in">vector</span><Blob<Dtype>*>& bottom) {</div><div class="line"> <span class="keyword">const</span> Dtype* top_diff = top[<span class="number">0</span>]->cpu_diff();</div><div class="line"> <span class="keyword">const</span> Dtype* top_data = top[<span class="number">0</span>]->cpu_data();</div><div class="line"> <span class="keyword">const</span> Dtype* bottom_data = bottom[<span class="number">0</span>]->cpu_data();</div><div class="line"> Dtype* bottom_diff = bottom[<span class="number">0</span>]->mutable_cpu_diff();</div><div class="line"> <span class="keyword">int</span> n = top[<span class="number">0</span>]->num();</div><div class="line"> <span class="keyword">int</span> d = top[<span class="number">0</span>]->count() / n;</div><div class="line"> Dtype epsilon = <span class="number">0.0000001</span>;</div><div class="line"> <span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">0</span>; i < n; ++i) {</div><div class="line"> Dtype a = caffe_cpu_dot(d, top_data+i*d, top_diff+i*d);</div><div class="line"> caffe_cpu_scale(d, a, top_data+i*d, bottom_diff+i*d);</div><div class="line"> caffe_sub(d, top_diff+i*d, bottom_diff+i*d, bottom_diff+i*d);</div><div class="line"> a = caffe_cpu_dot(d, bottom_data+i*d, bottom_data+i*d);</div><div class="line"> caffe_cpu_scale(d, Dtype(<span class="built_in">pow</span>(a + epsilon, <span class="number">-0.5</span>)),</div><div class="line"> bottom_diff+i*d, bottom_diff+i*d);</div><div class="line"> }</div><div class="line">}</div><div class="line"></div><div class="line"></div><div class="line"><span class="meta">#<span class="meta-keyword">ifdef</span> CPU_ONLY</span></div><div class="line">STUB_GPU(L2NormalizeLayer);</div><div class="line"><span class="meta">#<span class="meta-keyword">endif</span></span></div><div class="line"></div><div class="line">INSTANTIATE_CLASS(L2NormalizeLayer);</div><div class="line">REGISTER_LAYER_CLASS(L2Normalize);</div><div class="line"></div><div class="line">} <span class="comment">// namespace caffe</span></div></pre></td></tr></table></figure>
</div>
<footer class="post-footer">
<div class="post-eof"></div>
</footer>
</div>
</article>
<article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
<div class="post-block">
<link itemprop="mainEntityOfPage" href="http://yoursite.com/2017/10/19/【论文笔记】Multi-group-Shifting-Attention-Network/">
<span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
<meta itemprop="name" content="半城秋雨半城月">
<meta itemprop="description" content="">
<meta itemprop="image" content="/images/avatar.gif">
</span>
<span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
<meta itemprop="name" content="牧羊人小站">
</span>
<header class="post-header">
<h1 class="post-title" itemprop="name headline">
<a class="post-title-link" href="/2017/10/19/【论文笔记】Multi-group-Shifting-Attention-Network/" itemprop="url">【论文笔记】Multi-group Shifting Attention Network</a></h1>
<div class="post-meta">
<span class="post-time">
<span class="post-meta-item-icon">
<i class="fa fa-calendar-o"></i>
</span>
<span class="post-meta-item-text">发表于</span>
<time title="创建于" itemprop="dateCreated datePublished" datetime="2017-10-19T21:47:52+08:00">
2017-10-19
</time>
</span>
<span class="post-category" >
<span class="post-meta-divider">|</span>
<span class="post-meta-item-icon">
<i class="fa fa-folder-o"></i>
</span>
<span class="post-meta-item-text">分类于</span>
<span itemprop="about" itemscope itemtype="http://schema.org/Thing">
<a href="/categories/水滴石穿/" itemprop="url" rel="index">
<span itemprop="name">水滴石穿</span>
</a>
</span>
</span>
</div>
</header>
<div class="post-body" itemprop="articleBody">
<p>来自百度的ActivityNet Challenge 2017冠军论文 <code>Revisiting the Effectiveness of Off-the-shelf Temporal Modeling Approaches for Large-scale Video Classification</code>。由于只有短短的4页,内容很不详细,自己分析了一部分。</p>
<p>主要提出了一个<code>Multi-group Shifting Attention Network</code>模型用于视频检测,在Kinetics数据集上效果很好。</p>
<p><img src="http://wx2.sinaimg.cn/large/005CRBrHly1g2kjidz7nvj311u0cen0c.jpg" alt="60056469"></p>
<p>Multi-group Shifting Attention Network 的结构如下,其中最重要的便是shifting attention部分</p>
<p><img src="http://wx2.sinaimg.cn/large/005CRBrHly1g2kjj4gdicj314w0i4aej.jpg" alt="80339585"></p>
<p>下面是我的个人理解。</p>
<p>整个结构输入有三部分,RGB,Flow和Audio,分别经过shifting attention最后<br>三份输出concate作为整个视频的representation,进行常规的FC,softmax分类。</p>
<p>下面的SATT就是shifting attention结构的公式。输入X和输出都是矩阵。</p>