-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
1226 lines (825 loc) · 104 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 lang="zh-Hans,en,zh_CN,default">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 5.2.0">
<link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
<link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png">
<link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png">
<link rel="mask-icon" href="/images/logo.svg" color="#222">
<link rel="stylesheet" href="/css/main.css">
<link rel="stylesheet" href="//cdn.jsdelivr.net/npm/@fortawesome/[email protected]/css/all.min.css">
<link rel="stylesheet" href="//cdn.jsdelivr.net/npm/[email protected]/animate.min.css">
<script class="hexo-configurations">
var NexT = window.NexT || {};
var CONFIG = {"hostname":"yoursite.com","root":"/","scheme":"Muse","version":"8.0.0","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12},"copycode":false,"bookmark":{"enable":false,"color":"#222","save":"auto"},"fancybox":false,"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"fadeInDown","post_body":"fadeInDown","coll_header":"fadeInLeft","sidebar":"fadeInUp"}},"prism":false,"i18n":{"placeholder":"Searching...","empty":"We didn't find any results for the search: ${query}","hits_time":"${hits} results found in ${time} ms","hits":"${hits} results found"}};
</script>
<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">
<meta property="article:author" content="Chenxi">
<meta name="twitter:card" content="summary">
<link rel="canonical" href="http://yoursite.com/">
<script class="page-configurations">
// https://hexo.io/docs/variables.html
CONFIG.page = {
sidebar: "",
isHome : true,
isPost : false,
lang : 'zh-Hans'
};
</script>
<title>光</title>
<noscript>
<style>
body { margin-top: 2rem; }
.use-motion .menu-item,
.use-motion .sidebar,
.use-motion .post-block,
.use-motion .pagination,
.use-motion .comments,
.use-motion .post-header,
.use-motion .post-body,
.use-motion .collection-header {
visibility: visible;
}
.use-motion .header,
.use-motion .site-brand-container .toggle,
.use-motion .footer { opacity: initial; }
.use-motion .site-title,
.use-motion .site-subtitle,
.use-motion .custom-logo-image {
opacity: initial;
top: initial;
}
.use-motion .logo-line {
transform: scaleX(1);
}
.search-pop-overlay, .sidebar-nav { display: none; }
.sidebar-panel { display: block; }
</style>
</noscript>
<link rel="alternate" href="/atom.xml" title="光" type="application/atom+xml">
</head>
<body itemscope itemtype="http://schema.org/WebPage" class="use-motion">
<div class="headband"></div>
<main class="main">
<header class="header" itemscope itemtype="http://schema.org/WPHeader">
<div class="header-inner"><div class="site-brand-container">
<div class="site-nav-toggle">
<div class="toggle" aria-label="Toggle navigation bar">
</div>
</div>
<div class="site-meta">
<a href="/" class="brand" rel="start">
<i class="logo-line"></i>
<h1 class="site-title">光</h1>
<i class="logo-line"></i>
</a>
<p class="site-subtitle" itemprop="description">Life sucks, but you're gonna love it.</p>
</div>
<div class="site-nav-right">
<div class="toggle popup-trigger">
</div>
</div>
</div>
</div>
<div class="toggle sidebar-toggle">
<span class="toggle-line"></span>
<span class="toggle-line"></span>
<span class="toggle-line"></span>
</div>
<aside class="sidebar">
<div class="sidebar-inner sidebar-overview-active">
<ul class="sidebar-nav">
<li class="sidebar-nav-toc">
Table of Contents
</li>
<li class="sidebar-nav-overview">
Overview
</li>
</ul>
<!--noindex-->
<section class="post-toc-wrap sidebar-panel">
</section>
<!--/noindex-->
<section class="site-overview-wrap sidebar-panel">
<div class="site-author animated" itemprop="author" itemscope itemtype="http://schema.org/Person">
<p class="site-author-name" itemprop="name">Author</p>
<div class="site-description" itemprop="description"></div>
</div>
<div class="site-state-wrap animated">
<nav class="site-state">
<div class="site-state-item site-state-posts">
<a href="/archives">
<span class="site-state-item-count">61</span>
<span class="site-state-item-name">posts</span>
</a>
</div>
<div class="site-state-item site-state-categories">
<a href="/categories/">
<span class="site-state-item-count">7</span>
<span class="site-state-item-name">categories</span></a>
</div>
<div class="site-state-item site-state-tags">
<a href="/tags/">
<span class="site-state-item-count">52</span>
<span class="site-state-item-name">tags</span></a>
</div>
</nav>
</div>
</section>
</div>
</aside>
<div class="sidebar-dimmer"></div>
</header>
<div class="back-to-top">
<i class="fa fa-arrow-up"></i>
<span>0%</span>
</div>
<noscript>
<div class="noscript-warning">Theme NexT works best with JavaScript enabled</div>
</noscript>
<div class="main-inner index posts-expand">
<article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-Hans,en,zh_CN,default">
<link itemprop="mainEntityOfPage" href="http://yoursite.com/2021/01/24/Mac-brew-vscode-opencv/">
<span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
<meta itemprop="image" content="/images/avatar.gif">
<meta itemprop="name" content="Author">
<meta itemprop="description" content="">
</span>
<span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
<meta itemprop="name" content="光">
</span>
<header class="post-header">
<h2 class="post-title" itemprop="name headline">
<a href="/2021/01/24/Mac-brew-vscode-opencv/" class="post-title-link" itemprop="url">Mac使用brew在vscode下安装并配置【opencv】【g2o】【sophus】</a>
</h2>
<div class="post-meta-container">
<div class="post-meta">
<span class="post-meta-item">
<span class="post-meta-item-icon">
<i class="far fa-calendar"></i>
</span>
<span class="post-meta-item-text">Posted on</span>
<time title="Created: 2021-01-24 22:31:53" itemprop="dateCreated datePublished" datetime="2021-01-24T22:31:53+08:00">2021-01-24</time>
</span>
</div>
</div>
</header>
<div class="post-body" itemprop="articleBody">
<p>环境: Mac os linux</p>
<p>编译器:vscode</p>
<p>管理包:brew</p>
<p>安装包:</p>
<ul>
<li>opencv</li>
<li>eigen</li>
<li>g2o</li>
<li>sophus</li>
</ul>
<p>主要步骤</p>
<ol>
<li><p>opencv</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">brew search opencv <span class="comment">#可以搜索brew可以安装的opencv的version</span></span><br><span class="line"></span><br><span class="line">brew install opencv@2 <span class="comment">#选择要安装的opencv</span></span><br><span class="line"></span><br><span class="line">brew info opencv <span class="comment">#检查安装结果,若某个依赖包的后面没有✅,可以直接brew install安装这个包</span></span><br><span class="line"></span><br></pre></td></tr></table></figure>
<ul>
<li><p>安装完成之后会出现以下的提示,记得需要分别执行,这样可以把opencv的头文件和lib放到相应的位置以便随后配置</p>
<blockquote>
<p>If you need to have opencv@2 first in your PATH run:<br> echo ‘export PATH=”/usr/local/opt/opencv@2/bin:$PATH”‘ >> ~/.zshrc</p>
<p>For compilers to find opencv@2 you may need to set:<br> export LDFLAGS=”-L/usr/local/opt/opencv@2/lib”<br> export CPPFLAGS=”-I/usr/local/opt/opencv@2/include”</p>
<p>For pkg-config to find opencv@2 you may need to set:<br> export PKG_CONFIG_PATH=”/usr/local/opt/opencv@2/lib/pkgconfig”</p>
</blockquote>
</li>
<li><p>opencv@2 和 opencv@3有一些包有区别,所以有时候编译找不到其中一个包可以看一下版本是否有误</p>
</li>
</ul>
<p>这样安装好的opencv的include的内容是在 <code>/usr/local/opt/opencv@2/include</code></p>
<p>而link library是在当前文件夹 <code>/usr/local/opt/opencv@2/lib</code> </p>
</li>
<li><p>eigen</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">brew install eigen</span><br><span class="line"></span><br></pre></td></tr></table></figure>
<p>这样安装好的opencv的include的内容是在 <code>/usr/local/opt/eigen/include</code></p>
<p>而link library是在当前文件夹 <code>/usr/local/opt/eigen/lib</code> </p>
</li>
<li><p>Sophus</p>
<p><a target="_blank" rel="noopener" href="https://github.com/strasdat/Sophus">https://github.com/strasdat/Sophus</a></p>
<p>Sophus 是 应用在二维和三维问题中的李群方法的一个包,可以直接git clone下载然后按照网页提示步骤安装。</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">git <span class="built_in">clone</span> https://github.com/strasdat/Sophus.git <span class="comment">#下载包到本地</span></span><br><span class="line"></span><br><span class="line"><span class="built_in">cd</span> Sophus <span class="comment">#打开文件夹</span></span><br><span class="line"></span><br><span class="line">mkdir build <span class="comment">#创建build文件夹用于存放makefile</span></span><br><span class="line"></span><br><span class="line">cmake .. <span class="comment">#cmake上级的 cmakelist.txt</span></span><br><span class="line"></span><br><span class="line">make <span class="comment">#运行上一步在build文件夹中生成的makefile</span></span><br><span class="line"></span><br><span class="line">sudo install make <span class="comment">#在 /usr/local/include 中安装sophus的头文件之类的文件</span></span><br></pre></td></tr></table></figure>
<p>这样安装好的sophus的include的内容是在 <code>/usr/local/include/sophus</code></p>
<p>而link library是在当前文件夹 <code>../sophus</code> (就一个lib文件)</p>
<ul>
<li><p>在 <code>cmake ..</code> 这一步下,可能会出现以下错误:</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">/Users/wangcaimeng/Sophus/sophus/so2.cpp:32:24: error: expression is not assignable unit_complex_.real() = 1.;</span><br><span class="line">/Users/wangcaimeng/Sophus/sophus/so2.cpp:33:24: error: expression is not assignable unit_complex_.imag() = 0.; </span><br><span class="line">~~~~~~~~~~~~~~~~~~~~ ^ 2 errors generated. make[2]: *** [CMakeFiles/Sophus.dir/sophus/so2.cpp.o] Error 1 make[1]: *** [CMakeFiles/Sophus.dir/all] Error 2 make: *** [all] Error 2</span><br></pre></td></tr></table></figure>
<p>解决方案是:</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">将 so2.cpp 文件的32和33行改为:</span><br><span class="line"></span><br><span class="line">unit_complex_.real(1.);</span><br><span class="line">unit_complex_.imag(0.);</span><br><span class="line">参考自:https://github.com/gaoxiang12/slambook/issues/56#issuecomment-334946067</span><br></pre></td></tr></table></figure>
</li>
</ul>
</li>
<li><p>g2o</p>
<p><a target="_blank" rel="noopener" href="https://github.com/RainerKuemmerle/g2o">https://github.com/RainerKuemmerle/g2o</a></p>
<p>g2o是brewsci中的一个用于非线性优化的包,在官方git的readme.md文件中,提及到macos系统可以直接用</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">brew install brewsci/science/g2o</span><br></pre></td></tr></table></figure>
<p>来安装相关的包,但是我在安装的的过程中会涉及到 <code>Cannot tap brewsci/science</code> 的报错信息,这个问题没有查到明确的解法,所以就按照 sophus相同的办法安装了g2o。在官方的g2o文件的<strong>Compilation</strong> 部分也有具体提到安装的步骤:</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">git <span class="built_in">clone</span> https://github.com/RainerKuemmerle/g2o.git</span><br><span class="line"></span><br><span class="line"><span class="built_in">cd</span> g2o</span><br><span class="line"></span><br><span class="line">mkdir build</span><br><span class="line"></span><br><span class="line">cmake ..</span><br><span class="line"></span><br><span class="line">make</span><br><span class="line"></span><br><span class="line">sudo install make <span class="comment">#在 /usr/local/include 中安装g2o的头文件之类的文件</span></span><br></pre></td></tr></table></figure>
<p>这样安装好的g2o的include的内容是在 <code>/usr/local/include/g2o</code></p>
<p>而link library是在当前文件夹 <code>../g2o/lib</code> </p>
</li>
</ol>
<p><strong>由此可得,基于brew install 安装的包都比较统一地把include文件和lib文件放在 <code>/usr/local/opt/opencv@2/include</code> 和 <code>/usr/local/opt/opencv@2/lib</code>中,但是直接从git下载并且需要cmake的包需要自行确定include和lib文件夹在哪里。</strong></p>
<p>如果在安装过后都使用了 <code>sudo install make</code> 那么include的包会被安装在 <code>/usr/local/include/</code> 下</p>
<h1 id="vscode-配置"><a href="#vscode-配置" class="headerlink" title="vscode 配置"></a>vscode 配置</h1><p>vscode的配置文件又四个,分别是: <strong>launch.json, tasks.json, settngs.json, c_cpp_properties.json</strong></p>
<ol>
<li><p>lauch.json</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line">{</span><br><span class="line"> // Use IntelliSense to learn about possible attributes.</span><br><span class="line"> // Hover to view descriptions of existing attributes.</span><br><span class="line"> // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387</span><br><span class="line"> "version": "0.2.0",</span><br><span class="line"> "configurations": [</span><br><span class="line"> {</span><br><span class="line"> "name": "(lldb) Launch",</span><br><span class="line"> "type": "cppdbg",</span><br><span class="line"> "request": "launch",</span><br><span class="line"> "program": "${fileDirname}/a.out",</span><br><span class="line"> "args": [],</span><br><span class="line"> "stopAtEntry": true,</span><br><span class="line"> "cwd": "${workspaceFolder}",</span><br><span class="line"> "environment": [],</span><br><span class="line"> "externalConsole": false,</span><br><span class="line"> "MIMode": "lldb"</span><br><span class="line"> }</span><br><span class="line"> ]</span><br><span class="line">}</span><br></pre></td></tr></table></figure>
</li>
<li><p>settings.json</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br></pre></td><td class="code"><pre><span class="line">//settings.json</span><br><span class="line">{</span><br><span class="line"> "python.pythonPath": "usr/bin/python",</span><br><span class="line"> "code-runner.executorMap": {</span><br><span class="line"> "c": "cd $dir && make && ./$fileNameWithoutExt && make clean",</span><br><span class="line"> "cpp": "cd $dir && make && ./$fileNameWithoutExt && make clean"</span><br><span class="line"> },</span><br><span class="line"> "editor.renderWhitespace": "all",</span><br><span class="line"> "editor.renderLineHighlight": "all",</span><br><span class="line"> "editor.formatOnSave": true,</span><br><span class="line"> "code-runner.runInTerminal": true,</span><br><span class="line"> "code-runner.ignoreSelection": true,</span><br><span class="line"> "code-runner.enableAppInsights": false,</span><br><span class="line"> "C_Cpp.updateChannel": "Insiders",</span><br><span class="line"> "[makefile]": {</span><br><span class="line"> "editor.insertSpaces": true</span><br><span class="line"> },</span><br><span class="line"> "C_Cpp.default.includePath": [</span><br><span class="line"> "/usr/local/Cellar/opencv@2/2.4.13.7_11/include"</span><br><span class="line"> ]</span><br><span class="line">}</span><br></pre></td></tr></table></figure>
</li>
<li><p>tasks.json</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br></pre></td><td class="code"><pre><span class="line">{</span><br><span class="line"> "tasks": [</span><br><span class="line"> {</span><br><span class="line"> "type": "shell",</span><br><span class="line"> "label": "Build",</span><br><span class="line"> "command": "g++",</span><br><span class="line"> "args": [</span><br><span class="line"> //"main.cpp",</span><br><span class="line"> "${file}",</span><br><span class="line"> "-o",</span><br><span class="line"> "${fileDirname}/${fileBasenameNoExtension}.out",</span><br><span class="line"> "-I",</span><br><span class="line"> "/usr/local/Cellar/opencv@2/2.4.13.7_11/include/opencv",</span><br><span class="line"> "-I",</span><br><span class="line"> "/usr/local/Cellar/opencv@2/2.4.13.7_11/include",</span><br><span class="line"> "-L",</span><br><span class="line"> "/usr/local/Cellar/opencv@2/2.4.13.7_11/lib",</span><br><span class="line"> "-l",</span><br><span class="line"> "opencv_stitching",</span><br><span class="line"> "-l",</span><br><span class="line"> "opencv_superres",</span><br><span class="line"> "-l",</span><br><span class="line"> "opencv_videostab",</span><br><span class="line"> "-l",</span><br><span class="line"> "opencv_aruco",</span><br><span class="line"> "-l",</span><br><span class="line"> "opencv_bgsegm",</span><br><span class="line"> "-l",</span><br><span class="line"> "opencv_bioinspired",</span><br><span class="line"> "-l",</span><br><span class="line"> "opencv_ccalib",</span><br><span class="line"> "-l",</span><br><span class="line"> "opencv_dnn_objdetect",</span><br><span class="line"> "-l",</span><br><span class="line"> "opencv_dpm",</span><br><span class="line"> "-l",</span><br><span class="line"> "opencv_face",</span><br><span class="line"> "-l",</span><br><span class="line"> "opencv_fuzzy",</span><br><span class="line"> "-l",</span><br><span class="line"> "opencv_hfs",</span><br><span class="line"> "-l",</span><br><span class="line"> "opencv_img_hash",</span><br><span class="line"> "-l",</span><br><span class="line"> "opencv_line_descriptor",</span><br><span class="line"> "-l",</span><br><span class="line"> "opencv_optflow",</span><br><span class="line"> "-l",</span><br><span class="line"> "opencv_reg",</span><br><span class="line"> "-l",</span><br><span class="line"> "opencv_rgbd",</span><br><span class="line"> "-l",</span><br><span class="line"> "opencv_saliency",</span><br><span class="line"> "-l",</span><br><span class="line"> "opencv_stereo",</span><br><span class="line"> "-l",</span><br><span class="line"> "opencv_structured_light",</span><br><span class="line"> "-l",</span><br><span class="line"> "opencv_phase_unwrapping",</span><br><span class="line"> "-l",</span><br><span class="line"> "opencv_surface_matching",</span><br><span class="line"> "-l",</span><br><span class="line"> "opencv_tracking",</span><br><span class="line"> "-l",</span><br><span class="line"> "opencv_datasets",</span><br><span class="line"> "-l",</span><br><span class="line"> "opencv_dnn",</span><br><span class="line"> "-l",</span><br><span class="line"> "opencv_plot",</span><br><span class="line"> "-l",</span><br><span class="line"> "opencv_xfeatures2d",</span><br><span class="line"> "-l",</span><br><span class="line"> "opencv_shape",</span><br><span class="line"> "-l",</span><br><span class="line"> "opencv_video",</span><br><span class="line"> "-l",</span><br><span class="line"> "opencv_ml",</span><br><span class="line"> "-l",</span><br><span class="line"> "opencv_ximgproc",</span><br><span class="line"> "-l",</span><br><span class="line"> "opencv_xobjdetect",</span><br><span class="line"> "-l",</span><br><span class="line"> "opencv_objdetect",</span><br><span class="line"> "-l",</span><br><span class="line"> "opencv_calib3d",</span><br><span class="line"> "-l",</span><br><span class="line"> "opencv_features2d",</span><br><span class="line"> "-l",</span><br><span class="line"> "opencv_highgui",</span><br><span class="line"> "-l",</span><br><span class="line"> "opencv_videoio",</span><br><span class="line"> "-l",</span><br><span class="line"> "opencv_imgcodecs",</span><br><span class="line"> "-l",</span><br><span class="line"> "opencv_flann",</span><br><span class="line"> "-l",</span><br><span class="line"> "opencv_xphoto",</span><br><span class="line"> "-l",</span><br><span class="line"> "opencv_photo",</span><br><span class="line"> "-l",</span><br><span class="line"> "opencv_imgproc",</span><br><span class="line"> "-l",</span><br><span class="line"> "opencv_core",</span><br><span class="line"> "-g"</span><br><span class="line"></span><br><span class="line"> ],</span><br><span class="line"> </span><br><span class="line"> "group": {</span><br><span class="line"> "kind": "build",</span><br><span class="line"> "isDefault": true</span><br><span class="line"> },</span><br><span class="line"> "problemMatcher": [</span><br><span class="line"> "$gcc"</span><br><span class="line"> ]</span><br><span class="line"> }</span><br><span class="line"> ],</span><br><span class="line"> "version": "2.0.0"</span><br><span class="line">}</span><br></pre></td></tr></table></figure>
</li>
<li><p>c_cpp_properties.json</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br></pre></td><td class="code"><pre><span class="line">{</span><br><span class="line"> "configurations": [</span><br><span class="line"> {</span><br><span class="line"> "name": "Mac",</span><br><span class="line"> "includePath": [</span><br><span class="line"> "${workspaceFolder}/**",</span><br><span class="line"> "/usr/local/opt/opencv@2/include",</span><br><span class="line"> "/usr/local/Cellar/opencv@2/2.4.13.7_11/include"</span><br><span class="line"> ],</span><br><span class="line"> "defines": [],</span><br><span class="line"> "macFrameworkPath": [],</span><br><span class="line"> "compilerPath": "/usr/bin/g++",</span><br><span class="line"> "cStandard": "c11",</span><br><span class="line"> "cppStandard": "c++11",</span><br><span class="line"> "intelliSenseMode": "clang-x64",</span><br><span class="line"> "browse": {</span><br><span class="line"> "path": [</span><br><span class="line"> "/usr/local/Cellar/opencv@2/2.4.13.7_11/include"</span><br><span class="line"> ],</span><br><span class="line"> "limitSymbolsToIncludedHeaders": true,</span><br><span class="line"> "databaseFilename": ""</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> ],</span><br><span class="line"> "version": 4</span><br><span class="line">}</span><br></pre></td></tr></table></figure>
</li>
</ol>
<h1 id="cmakelist-配置"><a href="#cmakelist-配置" class="headerlink" title="cmakelist 配置"></a>cmakelist 配置</h1><p>cmake中主要配置的是 <strong>INCLUDE_DIRECTORIES , link_directoryies</strong></p>
<p>注意着两部分的路径药分别和之前安装的不同的包的路径相匹配,这样就可以运行cmake进行编译了</p>
</div>
<footer class="post-footer">
<div class="post-eof"></div>
</footer>
</article>
<article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-Hans,en,zh_CN,default">
<link itemprop="mainEntityOfPage" href="http://yoursite.com/2020/12/14/C-wk1-write-a-c-program/">
<span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
<meta itemprop="image" content="/images/avatar.gif">
<meta itemprop="name" content="Author">
<meta itemprop="description" content="">
</span>
<span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
<meta itemprop="name" content="光">
</span>
<header class="post-header">
<h2 class="post-title" itemprop="name headline">
<a href="/2020/12/14/C-wk1-write-a-c-program/" class="post-title-link" itemprop="url">C++ | wk1 write a c++ program</a>
</h2>
<div class="post-meta-container">
<div class="post-meta">
<span class="post-meta-item">
<span class="post-meta-item-icon">
<i class="far fa-calendar"></i>
</span>
<span class="post-meta-item-text">Posted on</span>
<time title="Created: 2020-12-14 19:55:12" itemprop="dateCreated datePublished" datetime="2020-12-14T19:55:12+08:00">2020-12-14</time>
</span>
</div>
</div>
</header>
<div class="post-body" itemprop="articleBody">
<h2 id="WK-1-Orientation-Write-a-c-program"><a href="#WK-1-Orientation-Write-a-c-program" class="headerlink" title="WK 1 | Orientation - Write a c++program"></a>WK 1 | Orientation - Write a c++program</h2><h1 id="WK-2-Understanding-the-C-memory"><a href="#WK-2-Understanding-the-C-memory" class="headerlink" title="WK 2 | Understanding the C++ memory"></a>WK 2 | Understanding the C++ memory</h1><h2 id="stack-memory"><a href="#stack-memory" class="headerlink" title="stack memory"></a>stack memory</h2><p>普通声明变量的时候占用的是stack memory</p>
<p>顺序是从位置最高的地方开始存,按顺序依次减小</p>
<h2 id="heap-memory"><a href="#heap-memory" class="headerlink" title="heap memory"></a>heap memory</h2><p>需要用关键字new来进行生命</p>
<p>顺序是从最低的位置开始从,按顺序依次增高</p>
<p>没有东西存的时候位置是空</p>
</div>
<footer class="post-footer">
<div class="post-eof"></div>
</footer>
</article>
<article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-Hans,en,zh_CN,default">
<link itemprop="mainEntityOfPage" href="http://yoursite.com/2020/10/27/PaddlePaddle-%E5%9B%BE%E5%83%8F%E5%88%86%E5%89%B2/">
<span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
<meta itemprop="image" content="/images/avatar.gif">
<meta itemprop="name" content="Author">
<meta itemprop="description" content="">
</span>
<span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
<meta itemprop="name" content="光">
</span>
<header class="post-header">
<h2 class="post-title" itemprop="name headline">
<a href="/2020/10/27/PaddlePaddle-%E5%9B%BE%E5%83%8F%E5%88%86%E5%89%B2/" class="post-title-link" itemprop="url">PaddlePaddle|图像分割</a>
</h2>
<div class="post-meta-container">
<div class="post-meta">
<span class="post-meta-item">
<span class="post-meta-item-icon">
<i class="far fa-calendar"></i>
</span>
<span class="post-meta-item-text">Posted on</span>
<time title="Created: 2020-10-27 15:40:08" itemprop="dateCreated datePublished" datetime="2020-10-27T15:40:08+08:00">2020-10-27</time>
</span>
</div>
</div>
</header>
<div class="post-body" itemprop="articleBody">
<h1 id="Python"><a href="#Python" class="headerlink" title="Python"></a>Python</h1><h2 id="pdb-python-自带调试器"><a href="#pdb-python-自带调试器" class="headerlink" title="pdb - python 自带调试器"></a>pdb - python 自带调试器</h2><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> pdb</span><br><span class="line">pdb.set_tract() <span class="comment">#添加断点</span></span><br><span class="line"></span><br><span class="line"><span class="comment">#运行之后会出现 (pdb)然后输入值</span></span><br><span class="line">运行下一行 - n</span><br><span class="line">打印 - p 变量名<span class="number">1</span> 变量名<span class="number">2</span></span><br><span class="line">退出调试 - q</span><br><span class="line">添加动态断点 - b 添加断点行数 ex. b <span class="number">23</span></span><br></pre></td></tr></table></figure>
<h1 id="Paddle-Paddle"><a href="#Paddle-Paddle" class="headerlink" title="Paddle Paddle"></a>Paddle Paddle</h1><h2 id="快速入门"><a href="#快速入门" class="headerlink" title="快速入门"></a>快速入门</h2><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> paddle.fluid</span><br><span class="line"><span class="keyword">import</span> numpy <span class="keyword">as</span> np</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="comment"># 定义两个constant张量</span></span><br><span class="line">x1 = fluid.layers.fill_constant(shape=[<span class="number">2</span>, <span class="number">2</span>], value=<span class="number">1</span>, dtype=<span class="string">'int64'</span>)</span><br><span class="line">x2 = fluid.layers.fill_constant(shape=[<span class="number">2</span>, <span class="number">2</span>], value=<span class="number">1</span>, dtype=<span class="string">'int64'</span>)</span><br><span class="line"><span class="comment"># 将两个张量求和</span></span><br><span class="line">y1 = fluid.layers.<span class="built_in">sum</span>(x=[x1, x2])</span><br><span class="line"></span><br><span class="line"><span class="comment">#定义两层的place holder为张量变量 variable name / tensor name</span></span><br><span class="line">a = fluid.layers.create_tensor(dtype=<span class="string">'int64'</span>, name=<span class="string">'c'</span>)</span><br><span class="line">b = fluid.layers.create_tensor(dtype=<span class="string">'int64'</span>, name=<span class="string">'d'</span>)</span><br><span class="line"></span><br><span class="line"><span class="comment">#定义y为两层之和</span></span><br><span class="line">y = fluid.layers.<span class="built_in">sum</span>(x=[a, b])</span><br><span class="line"></span><br><span class="line"><span class="comment"># 创建一个使用CPU的解释器</span></span><br><span class="line">place = fluid.CPUPlace()</span><br><span class="line">exe = fluid.executor.Executor(place)</span><br><span class="line"><span class="comment"># 进行参数初始化</span></span><br><span class="line">exe.run(fluid.default_startup_program())</span><br><span class="line"></span><br><span class="line"><span class="comment"># 创建一个使用CPU的解释器</span></span><br><span class="line">place = fluid.CPUPlace()</span><br><span class="line">exe = fluid.executor.Executor(place)</span><br><span class="line"><span class="comment"># 进行参数初始化</span></span><br><span class="line">exe.run(fluid.default_startup_program())</span><br><span class="line"></span><br><span class="line"><span class="comment"># 定义两个要计算的变量</span></span><br><span class="line">a1 = np.array([<span class="number">3</span>, <span class="number">2</span>]).astype(<span class="string">'int64'</span>)</span><br><span class="line">b1 = np.array([<span class="number">1</span>, <span class="number">1</span>]).astype(<span class="string">'int64'</span>)</span><br><span class="line"></span><br><span class="line"><span class="comment"># 进行运算,并把y的结果输出</span></span><br><span class="line"><span class="comment"># feed进去的需要标明是 层名字:变量名</span></span><br><span class="line"><span class="comment"># fetch list是层的variable name</span></span><br><span class="line">out_a, out_b, result = exe.run(program=fluid.default_main_program(),</span><br><span class="line"> feed={<span class="string">'c'</span>: a1, <span class="string">'d'</span>: b1},</span><br><span class="line"> fetch_list=[a, b, y])</span><br><span class="line">print(out_a, <span class="string">" + "</span>, out_b,<span class="string">" = "</span>, result)</span><br><span class="line"></span><br><span class="line"></span><br></pre></td></tr></table></figure>
<h2 id="定义简单网络"><a href="#定义简单网络" class="headerlink" title="定义简单网络"></a>定义简单网络</h2><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> paddle.fluid <span class="keyword">as</span> fluid</span><br><span class="line"><span class="keyword">import</span> paddle </span><br><span class="line"><span class="keyword">import</span> numpy <span class="keyword">as</span> np</span><br><span class="line"><span class="keyword">import</span> matplotlib.pyplot <span class="keyword">as</span> plt</span><br><span class="line"><span class="keyword">import</span> os</span><br><span class="line"></span><br><span class="line">BUF_SIZE = <span class="number">500</span></span><br><span class="line">BATCH_SIZE = <span class="number">20</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># preapare data</span></span><br><span class="line">trainer_reader = paddle.batch(paddle.reader.shuffle(paddle.uci.housing.train()), buf_size=BUF_SIZE)</span><br><span class="line">test_reader = paddle.batch(paddle.reader.shuffle(paddle.uci.housing.test()), buf_size=BUF_SIZE)</span><br><span class="line"></span><br><span class="line"><span class="comment"># build net</span></span><br><span class="line">x = fluid.layers.data(name=<span class="string">'x'</span>, shape=[<span class="number">13</span>], dtype=<span class="string">'float32'</span>)</span><br><span class="line">y_predict=fluid.layers.fc(<span class="built_in">input</span>=x,size=<span class="number">1</span>,act=<span class="literal">None</span>) <span class="comment">#定义一个简单的线性网络,连接输入和输出的全连接层</span></span><br><span class="line"></span><br><span class="line">y = fluid.layers.data(name=<span class="string">'y'</span>, shape=[<span class="number">1</span>], dtype=<span class="string">'float32'</span>) <span class="comment">#定义张量y,表示目标值</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># define cost function</span></span><br><span class="line">cost = fluid.layers.square_error_cost(<span class="built_in">input</span>=y_predict, label=y) <span class="comment">#求一个batch的损失值</span></span><br><span class="line">avg_cost = fluid.layers.mean(cost) <span class="comment">#对损失值求平均值</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># define optimization function</span></span><br><span class="line">optimizer = fluid.optimizer.SGDOptimizer(learning_rate=<span class="number">0.001</span>)</span><br><span class="line">opts = optimizer.minimize(avg_cost)</span><br><span class="line">test_program = fluid.default_main_program().clone(for_test=<span class="literal">True</span>)</span><br><span class="line"></span><br><span class="line"><span class="comment"># model training</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># build exector</span></span><br><span class="line">use_cuda = <span class="literal">False</span> <span class="comment">#use_cuda为False,表示运算场所为CPU;use_cuda为True,表示运算场所为GPU </span></span><br><span class="line">place = fluid.CUDAPlace(<span class="number">0</span>) <span class="keyword">if</span> use_cuda <span class="keyword">else</span> fluid.CPUPlace()</span><br><span class="line">exe = fluid.Executor(place) <span class="comment">#创建一个Executor实例exe</span></span><br><span class="line">exe.run(fluid.default_startup_program()) <span class="comment">#Executor的run()方法执行startup_program(),进行参数初始化</span></span><br><span class="line"></span><br><span class="line">feeder = fluid.DataFeeder(place=place, feed_list=[x, y])<span class="comment">#feed_list:向模型输入的变量表或变量表名</span></span><br><span class="line"></span><br><span class="line"><span class="built_in">iter</span>=<span class="number">0</span>;</span><br><span class="line">iters=[]</span><br><span class="line">train_costs=[]</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">draw_train_process</span>(<span class="params">iters,train_costs</span>):</span></span><br><span class="line"> title=<span class="string">"training cost"</span></span><br><span class="line"> plt.title(title, fontsize=<span class="number">24</span>)</span><br><span class="line"> plt.xlabel(<span class="string">"iter"</span>, fontsize=<span class="number">14</span>)</span><br><span class="line"> plt.ylabel(<span class="string">"cost"</span>, fontsize=<span class="number">14</span>)</span><br><span class="line"> plt.plot(iters, train_costs,color=<span class="string">'red'</span>,label=<span class="string">'training cost'</span>) </span><br><span class="line"> plt.grid()</span><br><span class="line"> plt.show()</span><br><span class="line"> </span><br><span class="line"><span class="comment"># save model </span></span><br><span class="line">EPOCH_NUM=<span class="number">50</span></span><br><span class="line">model_save_dir = <span class="string">"/home/aistudio/work/fit_a_line.inference.model"</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">for</span> pass_id <span class="keyword">in</span> <span class="built_in">range</span>(EPOCH_NUM): <span class="comment">#训练EPOCH_NUM轮</span></span><br><span class="line"> <span class="comment"># 开始训练并输出最后一个batch的损失值</span></span><br><span class="line"> train_cost = <span class="number">0</span></span><br><span class="line"> <span class="keyword">for</span> batch_id, data <span class="keyword">in</span> <span class="built_in">enumerate</span>(train_reader()): <span class="comment">#遍历train_reader迭代器</span></span><br><span class="line"> train_cost = exe.run(program=fluid.default_main_program(),<span class="comment">#运行主程序</span></span><br><span class="line"> feed=feeder.feed(data), <span class="comment">#喂入一个batch的训练数据,根据feed_list和data提供的信息,将输入数据转成一种特殊的数据结构</span></span><br><span class="line"> fetch_list=[avg_cost]) </span><br><span class="line"> <span class="keyword">if</span> batch_id % <span class="number">40</span> == <span class="number">0</span>:</span><br><span class="line"> print(<span class="string">"Pass:%d, Cost:%0.5f"</span> % (pass_id, train_cost[<span class="number">0</span>][<span class="number">0</span>])) <span class="comment">#打印最后一个batch的损失值</span></span><br><span class="line"> <span class="built_in">iter</span>=<span class="built_in">iter</span>+BATCH_SIZE</span><br><span class="line"> iters.append(<span class="built_in">iter</span>)</span><br><span class="line"> train_costs.append(train_cost[<span class="number">0</span>][<span class="number">0</span>])</span><br><span class="line"> </span><br><span class="line"> </span><br><span class="line"> <span class="comment"># 开始测试并输出最后一个batch的损失值</span></span><br><span class="line"> test_cost = <span class="number">0</span></span><br><span class="line"> <span class="keyword">for</span> batch_id, data <span class="keyword">in</span> <span class="built_in">enumerate</span>(test_reader()): <span class="comment">#遍历test_reader迭代器</span></span><br><span class="line"> test_cost= exe.run(program=test_program, <span class="comment">#运行测试cheng</span></span><br><span class="line"> feed=feeder.feed(data), <span class="comment">#喂入一个batch的测试数据</span></span><br><span class="line"> fetch_list=[avg_cost]) <span class="comment">#fetch均方误差</span></span><br><span class="line"> print(<span class="string">'Test:%d, Cost:%0.5f'</span> % (pass_id, test_cost[<span class="number">0</span>][<span class="number">0</span>])) <span class="comment">#打印最后一个batch的损失值</span></span><br><span class="line"> </span><br><span class="line"> <span class="comment">#保存模型</span></span><br><span class="line"> <span class="comment"># 如果保存路径不存在就创建</span></span><br><span class="line"><span class="keyword">if</span> <span class="keyword">not</span> os.path.exists(model_save_dir):</span><br><span class="line"> os.makedirs(model_save_dir)</span><br><span class="line"><span class="built_in">print</span> (<span class="string">'save models to %s'</span> % (model_save_dir))</span><br><span class="line">fluid.io.save_inference_model(model_save_dir, <span class="comment">#保存推理model的路径</span></span><br><span class="line"> [<span class="string">'x'</span>], <span class="comment">#推理(inference)需要 feed 的数据</span></span><br><span class="line"> [y_predict], <span class="comment">#保存推理(inference)结果的 Variables</span></span><br><span class="line"> exe) <span class="comment">#exe 保存 inference model</span></span><br><span class="line">draw_train_process(iters,train_costs)</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="comment"># model prediction </span></span><br><span class="line"></span><br><span class="line">infer_exe = fluid.Executor(place) <span class="comment">#创建推测用的executor</span></span><br><span class="line">inference_scope = fluid.core.Scope() <span class="comment">#Scope指定作用域</span></span><br><span class="line"></span><br><span class="line">infer_results=[]</span><br><span class="line">groud_truths=[]</span><br><span class="line"></span><br><span class="line"><span class="comment">#绘制真实值和预测值对比图</span></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">draw_infer_result</span>(<span class="params">groud_truths,infer_results</span>):</span></span><br><span class="line"> title=<span class="string">'Boston'</span></span><br><span class="line"> plt.title(title, fontsize=<span class="number">24</span>)</span><br><span class="line"> x = np.arange(<span class="number">1</span>,<span class="number">20</span>) </span><br><span class="line"> y = x</span><br><span class="line"> plt.plot(x, y)</span><br><span class="line"> plt.xlabel(<span class="string">'ground truth'</span>, fontsize=<span class="number">14</span>)</span><br><span class="line"> plt.ylabel(<span class="string">'infer result'</span>, fontsize=<span class="number">14</span>)</span><br><span class="line"> plt.scatter(groud_truths, infer_results,color=<span class="string">'green'</span>,label=<span class="string">'training cost'</span>) </span><br><span class="line"> plt.grid()</span><br><span class="line"> plt.show()</span><br><span class="line"> </span><br><span class="line"><span class="keyword">with</span> fluid.scope_guard(inference_scope):<span class="comment">#修改全局/默认作用域(scope), 运行时中的所有变量都将分配给新的scope。</span></span><br><span class="line"> <span class="comment">#从指定目录中加载 推理model(inference model)</span></span><br><span class="line"> [inference_program, <span class="comment">#推理的program</span></span><br><span class="line"> feed_target_names, <span class="comment">#需要在推理program中提供数据的变量名称</span></span><br><span class="line"> fetch_targets] = fluid.io.load_inference_model(<span class="comment">#fetch_targets: 推断结果</span></span><br><span class="line"> model_save_dir, <span class="comment">#model_save_dir:模型训练路径 </span></span><br><span class="line"> infer_exe) <span class="comment">#infer_exe: 预测用executor</span></span><br><span class="line"> <span class="comment">#获取预测数据</span></span><br><span class="line"> infer_reader = paddle.batch(paddle.dataset.uci_housing.test(), <span class="comment">#获取uci_housing的测试数据</span></span><br><span class="line"> batch_size=<span class="number">200</span>) <span class="comment">#从测试数据中读取一个大小为200的batch数据</span></span><br><span class="line"> <span class="comment">#从test_reader中分割x</span></span><br><span class="line"> test_data = <span class="built_in">next</span>(infer_reader())</span><br><span class="line"> test_x = np.array([data[<span class="number">0</span>] <span class="keyword">for</span> data <span class="keyword">in</span> test_data]).astype(<span class="string">"float32"</span>)</span><br><span class="line"> test_y= np.array([data[<span class="number">1</span>] <span class="keyword">for</span> data <span class="keyword">in</span> test_data]).astype(<span class="string">"float32"</span>)</span><br><span class="line"> results = infer_exe.run(inference_program, <span class="comment">#预测模型</span></span><br><span class="line"> feed={feed_target_names[<span class="number">0</span>]: np.array(test_x)}, <span class="comment">#喂入要预测的x值</span></span><br><span class="line"> fetch_list=fetch_targets) <span class="comment">#得到推测结果 </span></span><br><span class="line"> </span><br><span class="line"> print(<span class="string">"infer results: (House Price)"</span>)</span><br><span class="line"> <span class="keyword">for</span> idx, val <span class="keyword">in</span> <span class="built_in">enumerate</span>(results[<span class="number">0</span>]):</span><br><span class="line"> print(<span class="string">"%d: %.2f"</span> % (idx, val))</span><br><span class="line"> infer_results.append(val)</span><br><span class="line"> print(<span class="string">"ground truth:"</span>)</span><br><span class="line"> <span class="keyword">for</span> idx, val <span class="keyword">in</span> <span class="built_in">enumerate</span>(test_y):</span><br><span class="line"> print(<span class="string">"%d: %.2f"</span> % (idx, val))</span><br><span class="line"> groud_truths.append(val)</span><br><span class="line"> draw_infer_result(groud_truths,infer_results)</span><br></pre></td></tr></table></figure>
<h1 id="Class-1-语义分割-intro"><a href="#Class-1-语义分割-intro" class="headerlink" title="Class 1 语义分割 intro"></a>Class 1 语义分割 intro</h1><p>图像分割的类型</p>
<ol>
<li>Image Segmentation</li>
<li>Image Semantic Segmentation - 给每个pixel分类</li>
<li>Image Instance Segmentation - 检测相关,给每个object 分mask cat1 cat2</li>
<li>Image Panomic Segmentation - 背景pixel分类+框里mask</li>
<li>Video Object Segmentation - 通常会给定目标mask</li>
<li>Video Instance Segmentation</li>
</ol>
<h2 id="语义分割算法的基本概念"><a href="#语义分割算法的基本概念" class="headerlink" title="语义分割算法的基本概念"></a>语义分割算法的基本概念</h2><p><strong>语义分割算法的根本目的:像素级分类</strong></p>
<h3 id="语义分割算法的基本流程"><a href="#语义分割算法的基本流程" class="headerlink" title="语义分割算法的基本流程"></a>语义分割算法的基本流程</h3><ol>
<li>输入:图像(rgb) - dataloader imread batchsize</li>
<li>算法:深度学习模型</li>
<li>输出:分类结果 (与输入大小一致的单通道图像)</li>
<li>训练过程:<ol>
<li>输入: image + label</li>
<li>前向:out = model(inage)</li>
<li>计算损失</li>
<li>反向</li>
<li>更新权重</li>
</ol>
</li>
</ol>
<h3 id="语义分割性能指标"><a href="#语义分割性能指标" class="headerlink" title="语义分割性能指标"></a>语义分割性能指标</h3><ul>
<li>mIoU:分割每一类别的交并比</li>
<li>mAcc:pred 和gt 对应位置的“分类”标准率,更趋近于各种不同灰度</li>
</ul>
<p>为什么acc不够 还要有iou呢?忽略了很重要的一类</p>
<h2 id="实践部分"><a href="#实践部分" class="headerlink" title="实践部分"></a>实践部分</h2><h2 id="basic-net"><a href="#basic-net" class="headerlink" title="basic net"></a>basic net</h2><h2 id="basic-DataLoader"><a href="#basic-DataLoader" class="headerlink" title="basic DataLoader"></a>basic DataLoader</h2><h1 id="Fully-Convolutional-Network-FCN-全卷积网络"><a href="#Fully-Convolutional-Network-FCN-全卷积网络" class="headerlink" title="Fully Convolutional Network. (FCN 全卷积网络)"></a>Fully Convolutional Network. (FCN 全卷积网络)</h1><h2 id="为什么要用FCN"><a href="#为什么要用FCN" class="headerlink" title="为什么要用FCN"></a>为什么要用FCN</h2><p>卷积神经网络首先被分类卷积网络 - 全卷积网络</p>
<p>变大feature map - 上采样/反卷积/unpooling</p>
<h2 id="什么是fcn"><a href="#什么是fcn" class="headerlink" title="什么是fcn"></a>什么是fcn</h2><h3 id="双线插值-(bilinear-interpolation)"><a href="#双线插值-(bilinear-interpolation)" class="headerlink" title="双线插值 (bilinear interpolation)"></a>双线插值 (bilinear interpolation)</h3><p>Nchw - nch’w’ 图像放大:简单,快 </p>
<h3 id="un-pooling"><a href="#un-pooling" class="headerlink" title="un-pooling"></a>un-pooling</h3><h3 id="transpose-conv"><a href="#transpose-conv" class="headerlink" title="transpose conv"></a>transpose conv</h3><h2 id="如何建立一个fcn"><a href="#如何建立一个fcn" class="headerlink" title="如何建立一个fcn"></a>如何建立一个fcn</h2>
</div>
<footer class="post-footer">
<div class="post-eof"></div>
</footer>
</article>
<article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-Hans,en,zh_CN,default">
<link itemprop="mainEntityOfPage" href="http://yoursite.com/2020/07/25/Paper-Reading-Deep-Residual-Learning-for-Image-Recognition/">
<span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
<meta itemprop="image" content="/images/avatar.gif">
<meta itemprop="name" content="Author">
<meta itemprop="description" content="">
</span>
<span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
<meta itemprop="name" content="光">
</span>
<header class="post-header">
<h2 class="post-title" itemprop="name headline">
<a href="/2020/07/25/Paper-Reading-Deep-Residual-Learning-for-Image-Recognition/" class="post-title-link" itemprop="url">Paper Reading | Deep Residual Learning for Image Recognition</a>
</h2>
<div class="post-meta-container">
<div class="post-meta">
<span class="post-meta-item">
<span class="post-meta-item-icon">
<i class="far fa-calendar"></i>
</span>
<span class="post-meta-item-text">Posted on</span>
<time title="Created: 2020-07-25 00:18:53" itemprop="dateCreated datePublished" datetime="2020-07-25T00:18:53+08:00">2020-07-25</time>
</span>
<span class="post-meta-item">
<span class="post-meta-item-icon">
<i class="far fa-folder"></i>
</span>
<span class="post-meta-item-text">In</span>
<span itemprop="about" itemscope itemtype="http://schema.org/Thing">
<a href="/categories/%E8%AE%BA%E6%96%87%E9%98%85%E8%AF%BB/" itemprop="url" rel="index"><span itemprop="name">论文阅读</span></a>
</span>
</span>
</div>
</div>
</header>
<div class="post-body" itemprop="articleBody">
<p>这部分我们来看看这个经典结构ResNet首先被提出的文章。</p>
<ul>
<li>论文链接:<a target="_blank" rel="noopener" href="https://arxiv.org/pdf/1512.03385.pdf">https://arxiv.org/pdf/1512.03385.pdf</a></li>
</ul>
<h1 id="Abstract"><a href="#Abstract" class="headerlink" title="Abstract"></a>Abstract</h1><p>深度神经网络现在变得越来越难训练了。我们呈现了一种残差网络的框架来解决这个问题。我们重新搭建了网络模型,利用layer的input作为参考,学习残差方程,而不是直接学习没有参考的方程。</p>
<h1 id="Introduction"><a href="#Introduction" class="headerlink" title="Introduction"></a>Introduction</h1><p>深度卷积神经网络在图片分类上带来了很大的突破。深度神经网络综合了从低到高的feature和端到端分类器,以及可以通过扩大训练层数而增加的feature的个数。近期的神经网络展现出来的网络结构的深度有着至关重要的作用,并且在ImageNet分类上,分类效果好的神经网络的层数都是在16-30之间。有很多其他的视觉方面的任务同样也受益于深度的网络结构。</p>
<p>那么急于网络深度的重要性,我们不禁要问:训练更好的神经网络真得就如同叠加积木一样简单吗?一个摆在这个问题之前的障碍是梯度爆炸和梯度消失的问题,但是梯度爆炸和小时大部分可以被BN来解决。</p>
<p>【这里应该是说,再深的神经网络,如果出现了梯度消失的问题,我们大可以用归一化输入和归一化每一层的feature来解决。】</p>
<p>当更多层的神经网络开始收敛的时候,一个网络退化的问题就暴露了:随着网络深度的增加,准确率开始趋于饱和然后开始急速下降。但这种退化并不是由于过拟合造成的,添加更多的层数不仅会使测试的准确率降低,训练的准确率也会降低。</p>
<p>【这里举了一个例子,是一个20层网络和一个56层网络的例子,通过增加神经网络的层数(深度)我们得到的网络分类效果并没有变得很好,而是训练和测试准确率变得更差了,所以不是简单的过拟合的问题。】</p>
<p>更深度的神经网络在训练数据集上的效果退化说明,并不是所有的系统都很好优化。让我们来考虑一个浅层的结构和一个在这个浅层结构的基础上增加量更多层的结构。如果我们新添加的这些层只是做简单的对应变化,也就是新添加的几层网络什么都不做,只是单纯的复制浅层网络的输出,那么我的这个深层的网络怎么着误差也应该和浅层网络的误差一样,那如果后面新添加的几层学到了更多的特征,得到的结果应该比浅层网络得到的结果更好才对。但之前的实验显示,新增加的几层并不能很好的体现这个理论。</p>
<p>在这篇文章里,我们利用深度残差网络解决了这个退化的问题。我们这里利用残差map来代替利用几个叠加的layer拟合出来一个mapping的方法。直观来讲,如果我们将理想情况下的mapping方程记做$\mathcal H(x)$, 现在我们对非线性叠加层定义一个新的map $\mathcal F(\bf x) := \mathcal H(\bf x) - x$, 这样一来之前的map就变成了 $\mathcal F(\bf x) + \bf x$ 我们现在的假设是,优化得到残差mapping比得到之前的mapping更加容易。在极端的角度上来讲,如果identity mapping是最优解,那么得到残差mapping的0比得到identity mapping更加容易。</p>
<p> $\mathcal F(\bf x) + \bf x$ 的结构就通过短接得到。短接的意思就是跳过一层或多层,在我们的这个方法里,短接的直接是通过identity mapping,然后得到的结果直接连在之前正常输出的结果上。</p>
<p><img src="../images/Screen%20Shot%202020-07-24%20at%2021.54.23.png" alt="Screen Shot 2020-07-24 at 21.54.23"></p>
<p>我们在ImageNet数据上面证明了退化的问题以及测试了我们的网络。我们证明了:1. 在残差结构下的很深的深度网络还是很好被优化的,但是很深的只是简单叠加的深度网络的误差会随着层数的增加而增加; 2. 我们很深的残差网络可以在增长网络深度的条件下继续提高精度。</p>
<h1 id="Deep-Residual-Learning"><a href="#Deep-Residual-Learning" class="headerlink" title="Deep Residual Learning"></a>Deep Residual Learning</h1><h2 id="Residual-Learning"><a href="#Residual-Learning" class="headerlink" title="Residual Learning"></a>Residual Learning</h2><p>让我们假设 $\mathcal H(\bf x)$ 是正常叠加一些卷积层(一个stack)的网络对应的underlying mapping. 这里的 $\bf x$ 代表的是通过这一小堆第一层的input。如果我们假设一系列的非线性层可以为我们得出复杂函数的估计,那么我们同样也可以用这一系列的非线性ceng</p>
</div>
<footer class="post-footer">
<div class="post-eof"></div>
</footer>
</article>
<article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-Hans,en,zh_CN,default">
<link itemprop="mainEntityOfPage" href="http://yoursite.com/2020/07/23/%E5%B9%B2%E8%B4%A7-%E5%87%A0%E7%A7%8D%E7%9B%AE%E6%A0%87%E6%A3%80%E6%B5%8B%E7%9A%84%E7%BD%91%E7%BB%9C/">
<span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
<meta itemprop="image" content="/images/avatar.gif">
<meta itemprop="name" content="Author">
<meta itemprop="description" content="">
</span>
<span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
<meta itemprop="name" content="光">
</span>
<header class="post-header">
<h2 class="post-title" itemprop="name headline">
<a href="/2020/07/23/%E5%B9%B2%E8%B4%A7-%E5%87%A0%E7%A7%8D%E7%9B%AE%E6%A0%87%E6%A3%80%E6%B5%8B%E7%9A%84%E7%BD%91%E7%BB%9C/" class="post-title-link" itemprop="url">干货 | 几种目标检测的网络和变化</a>
</h2>
<div class="post-meta-container">
<div class="post-meta">
<span class="post-meta-item">
<span class="post-meta-item-icon">
<i class="far fa-calendar"></i>
</span>
<span class="post-meta-item-text">Posted on</span>
<time title="Created: 2020-07-23 03:42:46" itemprop="dateCreated datePublished" datetime="2020-07-23T03:42:46+08:00">2020-07-23</time>
</span>
<span class="post-meta-item">
<span class="post-meta-item-icon">
<i class="far fa-folder"></i>
</span>
<span class="post-meta-item-text">In</span>
<span itemprop="about" itemscope itemtype="http://schema.org/Thing">
<a href="/categories/%E5%B9%B2%E8%B4%A7/" itemprop="url" rel="index"><span itemprop="name">干货</span></a>
</span>
</span>
</div>
</div>
</header>
<div class="post-body" itemprop="articleBody">
<h1 id="Selective-Search"><a href="#Selective-Search" class="headerlink" title="Selective Search"></a>Selective Search</h1><h1 id="RCNN"><a href="#RCNN" class="headerlink" title="RCNN"></a>RCNN</h1><h1 id="Fast-RCNN"><a href="#Fast-RCNN" class="headerlink" title="Fast-RCNN"></a>Fast-RCNN</h1><p>为了改进之前RCNN结构中,生成的conv feature需要通过SVM,造成大量的时间损耗。Girshick又改进了之前的网络结构,提出了Fast RCNN。</p>
<p>Fast RCNN是在SPP和RCNN的基础上提出的。</p>
<p>RCNN我们在上个部分已经提过了,那么SPP网络是什么呢?</p>
<ul>
<li><p>SPP的全称是Spatial Parimid Pooling,主要是在不同的空间尺度上进行池化,提取不同空间尺度的特征,防止Proposal在进入RCNN网络时rescale到固定尺寸(224 x 224)时图形产生的形变和图片的变化。</p>
</li>
<li><p>SPP在使用的过程中是将全图划分成不同尺寸的grid(比如 1 x 1的grid的就是原图本身, 2x 2的grid是将原图分为4份,其中每一份cell的长宽都是原图长宽的一半), 然后将每一个grid生成的pooling之后的结果组合在一起,产生一个固定大小的feature作为SPP的输出。对于输入的每一个channel都会生成grid。</p>
</li>
<li><p>举个例子,假如现在我们输入是一个 256 x 256 x 3 的feature</p>
<ol>
<li><p>针对每一层,生成 1x1 的grid,然后做max pooling,得到一个 1 x 3 的feature</p>
</li>
<li><p>针对每一层,生成 2 x 2的grid,然后做max pooling,得到一个 4 x 3的feature</p>
</li>
<li><p>针对每一层,生成 4 x 4的grid,然后做max pooling,得到一个 16 x 3 的feature</p>
<p>…</p>
</li>
</ol>
<p>最后将这些feature拼接起来生成的整个feature是固定大小的输出。(因为我们grid的大小是固定的,所以如果输入feature的尺寸发生变化,那么只有grid中每个cell的大小会发生变化,但是gird中cell的个数是固定不变的,所以最后通过ROI pooling的生成结果的尺寸是不变的。)</p>
</li>
</ul>
<p>那么对于Fast RCNN来说,它的输入是一张图片,以及一些proposal,这些proposal的大小各不相同,我们用(r, c, h, w) 来表示每一个proposal region。 r c表示左上角的坐标点,h w 表示这个框的长宽。</p>
<p>Fast RCNN的主要过程是,我们将原图通过特征提取网络,生成一个conv feature map,然后在这个map上面根据之前所说的proposal的信息,提取出proposal的位置,并对其进行ROI pooling。生成的ROI pooling是一个长度固定的feature,并且这里我们只用一次 H x W 的grid提取,也就是说通过ROI pooling之后生成的feature的长度是 H x W x d (这里d是输入ROI pooling之前的feature的维度)。生成的feature之后会通过两个网络,一个连接到softmax用来确定我这张图片上有哪些物体,另一个用来确定预测出的物体的bounding box是什么。</p>
<p>(receptive field为什么会更大)</p>
<h1 id="Faster-RCNN"><a href="#Faster-RCNN" class="headerlink" title="Faster RCNN"></a>Faster RCNN</h1><p>目标检测的网络发展至此,还有一个重要的需要依靠外界实现的输入,那就是proposal</p>
<p>Faster RCNN的出现解决了需要依靠外界条件得到proposal region的情况,实际上Faster RCNN就是一个Region Proposal Network + Fast RCNN的网络结构。那么就主要介绍一下生成proposal的网络: RPN</p>
<p>RPN的主要目的就是寻找proposal,这时候我们就建立一个sliding window,然后以这个sliding window为中心,构建不同尺寸和长宽比的anchor来找到合适的proposal region。</p>
<p>训练RPN的时候,主要分为两个方面的cost,一方面是二维向量表示所圈到的proposal是否是一个物体,另一个是四维向量来表示所圈到的坐标信息。proposal是否为物体主要是根据proposal和target的IoU来判定,如果IoU大于0.7或者IoU是这些anchor里面最大的,那么这个anchor就被称作是positive的结果;反之如果IoU小于0.3就是negative的结果。bounding box的预测值是输入在regression网络中进行训练的。</p>
<p>文章中使用的anchor为9个。</p>
<p>但是使用RPN还存在一个问题就是因为我们的anchor的大小都是固定的,那么一个特别大或者特别小的物体就可能无法被估计(在感受野外)或者被找到。这时候可以通过训练不同的RPN在不同的尺度下进行proposal的估计,在这样产生的proposal的感受野也不同。</p>
<p>(感受野是怎么确定的)</p>
<h1 id="MTCNN"><a href="#MTCNN" class="headerlink" title="MTCNN"></a>MTCNN</h1><p>MTCNN的全称是multi-task cascaded convolutional neural network,主要是用来进行人脸的detection的。</p>
</div>
<footer class="post-footer">
<div class="post-eof"></div>
</footer>
</article>
<article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-Hans,en,zh_CN,default">
<link itemprop="mainEntityOfPage" href="http://yoursite.com/2020/07/20/%E5%B9%B2%E8%B4%A7-%E5%87%A0%E7%A7%8D%E5%B8%B8%E8%A7%81%E7%9A%84%E7%89%B9%E5%BE%81%E6%A3%80%E6%B5%8B%E5%AD%90/">
<span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
<meta itemprop="image" content="/images/avatar.gif">
<meta itemprop="name" content="Author">
<meta itemprop="description" content="">
</span>
<span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
<meta itemprop="name" content="光">
</span>
<header class="post-header">
<h2 class="post-title" itemprop="name headline">
<a href="/2020/07/20/%E5%B9%B2%E8%B4%A7-%E5%87%A0%E7%A7%8D%E5%B8%B8%E8%A7%81%E7%9A%84%E7%89%B9%E5%BE%81%E6%A3%80%E6%B5%8B%E5%AD%90/" class="post-title-link" itemprop="url">干货 | 几种常见的特征检测子</a>
</h2>
<div class="post-meta-container">
<div class="post-meta">
<span class="post-meta-item">
<span class="post-meta-item-icon">
<i class="far fa-calendar"></i>
</span>
<span class="post-meta-item-text">Posted on</span>
<time title="Created: 2020-07-20 20:59:51" itemprop="dateCreated datePublished" datetime="2020-07-20T20:59:51+08:00">2020-07-20</time>
</span>
</div>
</div>
</header>
<div class="post-body" itemprop="articleBody">
<h1 id="HOG-SVM"><a href="#HOG-SVM" class="headerlink" title="HOG + SVM"></a>HOG + SVM</h1><p>我们常常会选取一些图片中的特征来代表这个图片中的内容,图片中物体的edge是很有力的特征。这样来说,我们可以用canny找到图片中的物体的edge。但是找到的edge只是大小,并没有gradient的信息。所以在这里我们提取gradient,生成它的特征信息。</p>
<ol>
<li><p>输入图片</p>
</li>
<li><p>对图片进行颜色和对比度的归一化处理</p>
</li>
<li><p>计算gradient:</p>
<p>这一项稍微复杂一些,我们分开来说。</p>
<ul>
<li>首先将图片分割成一个个 $8 \times 8$ pixel大小的cell,这样的话,一个长度为height, 宽度为 width的图片能生成的cell的个数就是 $\frac{height}{8} \times \frac{width}{8}$. </li>
<li>对于每一个cell中的每一个pixel都有我们计算的gradient的方向,将0-360划分为8个方向,然后将 $8 \times 8$ pixel中每一个pixel的方向都统计在这八个方向上,这样一来,我们的这64个pixel就可以保存为一个 $1\times 8$ 的histogram vector;</li>
<li>由于 $8 \times 8$ pixel 的感受面积还是比较小,可能无法感知到光线的变化,所以我们进一步将一个 $2 \times 2$ 的cell当做一个block,这样,对于一个block中的每一个cell,他都有一个 $1 \times8$的vector,这样四个cell的histogram放在一起就是一个 $ 1 \times 32$ 的histogram vector。</li>
<li>然后将这个$ 1 \times 32$ 的histogram vector进行归一化处理,就得到了这一张图的一个特征。对于整个图来讲,我们就得到了一个 $(\frac{height}{8} \times \frac{width}{8}\times32)$ 的特征。</li>
</ul>
</li>
<li><p>我们将histogram vector拿出来作为图片是否是某种物体的特征,然后将这些特征放入一个SVM中,设置一个score,来判定是否有我们想要的物体。</p>
</li>
</ol>
<h1 id="Viola-Jones-face-detector-Harr-Adaboost"><a href="#Viola-Jones-face-detector-Harr-Adaboost" class="headerlink" title="Viola - Jones face detector (Harr+Adaboost)"></a>Viola - Jones face detector (Harr+Adaboost)</h1><ol>
<li>Harr-like feature</li>
<li>Integral of image</li>
<li>Adaboost</li>
<li>Concatenate classifier</li>
</ol>
<h1 id="SIFT"><a href="#SIFT" class="headerlink" title="SIFT"></a>SIFT</h1><ol>
<li><p>Space - Scale Extrema detection</p>
<p>SIFT算子的第一步要先重视这里的scale invariant,我们希望SIFT能找到的特征是在各种尺度的情况下都可以成立的。因此,我们需要构建不同的尺度来寻找特征点。</p>
<ul>
<li><p>使用DOG来代替LOG</p>
<p>通常情况下,我们用Laplacian of Gaussian来寻找图片中的边缘信息(先平滑,再二次求导),但是用LOG的话计算量会比较大而且复杂,于是我们就发现,可以用两个不同sigma值平滑的gaussian分布做差,得到和LOG类似的形状,也可以实现边缘检测。</p>
<p>提取不同的高斯平滑后的边缘,我们可以得到一个octave。</p>
<p>那为什么我们要octave呢,可能是因为在不同的高斯平滑下,我们找到的边缘是不同的。平滑程度大,找到的边界就会少一些,平滑程度小,产生的噪声就会强一些。不同的平滑程度下,我们得到的是不同的边界。</p>
</li>
<li><p>改变尺度,寻找边缘</p>
<p>在不同尺度下,找相同的特征这个思路很直观。比如说一棵树,我们在远处模糊的看到他的时候,他是一棵树;当我们走进之后,这个数会变得更加清晰,我们还能看出来他是一棵树。这就说明有一些特征信息是具有尺度不变性的。</p>
<p>所以,除了在原图上做blur,我们还需要改变原图的resolution,然后再做一系列的blur。这样对于一张图,我们会得到不同的几个octaves</p>
</li>
</ul>
</li>
<li><p>Keypoint Localization</p>
<p>确定keypoint的步骤分为两步,找到key point,去掉contrast比较弱的key point</p>
<ul>
<li>找到key point,</li>
</ul>
</li>
<li><p>Orientation Assignment</p>
</li>
<li><p>Local Descriptor Creation</p>
</li>
</ol>
</div>
<footer class="post-footer">
<div class="post-eof"></div>
</footer>
</article>
<article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-Hans,en,zh_CN,default">
<link itemprop="mainEntityOfPage" href="http://yoursite.com/2020/07/20/%E5%B9%B2%E8%B4%A7-Canny-Edge-Detector/">
<span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
<meta itemprop="image" content="/images/avatar.gif">
<meta itemprop="name" content="Author">
<meta itemprop="description" content="">
</span>
<span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
<meta itemprop="name" content="光">
</span>
<header class="post-header">
<h2 class="post-title" itemprop="name headline">
<a href="/2020/07/20/%E5%B9%B2%E8%B4%A7-Canny-Edge-Detector/" class="post-title-link" itemprop="url">干货 | Canny Edge Detector</a>
</h2>
<div class="post-meta-container">
<div class="post-meta">
<span class="post-meta-item">
<span class="post-meta-item-icon">
<i class="far fa-calendar"></i>
</span>
<span class="post-meta-item-text">Posted on</span>
<time title="Created: 2020-07-20 10:15:18" itemprop="dateCreated datePublished" datetime="2020-07-20T10:15:18+08:00">2020-07-20</time>
</span>
</div>
</div>
</header>
<div class="post-body" itemprop="articleBody">
</div>
<footer class="post-footer">
<div class="post-eof"></div>
</footer>
</article>
<article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-Hans,en,zh_CN,default">
<link itemprop="mainEntityOfPage" href="http://yoursite.com/2020/07/15/Machine-Learning-2020-Lecture-5-Convolutional-Neural-Network/">
<span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
<meta itemprop="image" content="/images/avatar.gif">
<meta itemprop="name" content="Author">
<meta itemprop="description" content="">
</span>
<span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
<meta itemprop="name" content="光">
</span>
<header class="post-header">
<h2 class="post-title" itemprop="name headline">
<a href="/2020/07/15/Machine-Learning-2020-Lecture-5-Convolutional-Neural-Network/" class="post-title-link" itemprop="url">Machine-Learning-2020 | Lecture#5 Convolutional Neural Network</a>
</h2>
<div class="post-meta-container">
<div class="post-meta">
<span class="post-meta-item">
<span class="post-meta-item-icon">
<i class="far fa-calendar"></i>
</span>
<span class="post-meta-item-text">Posted on</span>
<time title="Created: 2020-07-15 22:32:54" itemprop="dateCreated datePublished" datetime="2020-07-15T22:32:54+08:00">2020-07-15</time>
</span>
<span class="post-meta-item">
<span class="post-meta-item-icon">
<i class="far fa-folder"></i>
</span>
<span class="post-meta-item-text">In</span>
<span itemprop="about" itemscope itemtype="http://schema.org/Thing">
<a href="/categories/%E8%AF%BE%E5%A0%82%E7%AC%94%E8%AE%B0/" itemprop="url" rel="index"><span itemprop="name">课堂笔记</span></a>
</span>
</span>
</div>
</div>
</header>
<div class="post-body" itemprop="articleBody">
<p>首先就迎来了深度神经网络的第一个基础的部分:CNN</p>
</div>
<footer class="post-footer">
<div class="post-eof"></div>
</footer>
</article>
<article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-Hans,en,zh_CN,default">
<link itemprop="mainEntityOfPage" href="http://yoursite.com/2020/07/06/Machine-Learning-2020-Lecture-4-Deep-Learning-Preparation-Backpropagation/">
<span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
<meta itemprop="image" content="/images/avatar.gif">
<meta itemprop="name" content="Author">
<meta itemprop="description" content="">
</span>
<span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
<meta itemprop="name" content="光">
</span>
<header class="post-header">
<h2 class="post-title" itemprop="name headline">
<a href="/2020/07/06/Machine-Learning-2020-Lecture-4-Deep-Learning-Preparation-Backpropagation/" class="post-title-link" itemprop="url">Machine-Learning-2020 | Lecture#4 Deep Learning Preparation - Backpropagation</a>
</h2>
<div class="post-meta-container">
<div class="post-meta">
<span class="post-meta-item">
<span class="post-meta-item-icon">
<i class="far fa-calendar"></i>
</span>
<span class="post-meta-item-text">Posted on</span>
<time title="Created: 2020-07-06 05:07:44" itemprop="dateCreated datePublished" datetime="2020-07-06T05:07:44+08:00">2020-07-06</time>
</span>
<span class="post-meta-item">
<span class="post-meta-item-icon">
<i class="far fa-folder"></i>
</span>
<span class="post-meta-item-text">In</span>
<span itemprop="about" itemscope itemtype="http://schema.org/Thing">
<a href="/categories/%E8%AF%BE%E5%A0%82%E7%AC%94%E8%AE%B0/" itemprop="url" rel="index"><span itemprop="name">课堂笔记</span></a>
</span>
</span>
</div>
</div>
</header>
<div class="post-body" itemprop="articleBody">
<p>这一部分还是deep learning的准备课程,就是反向传播。</p>
<p>在更新神经网络参数的过程中,反向传播是很重要的一步。那么如何有效得计算反向传播也同样重要。</p>
<h1 id="正向传播"><a href="#正向传播" class="headerlink" title="正向传播"></a>正向传播</h1><p>首先我们来捋一捋神经网络的正向传播过程。</p>
<ul>
<li>输入 $\bf x = \left[\begin{equation}\begin{array}{c}\bf x<em>1\\bf x_2\end{array}\end{equation}\right] $ ,第$i$ 层的权重为 $\bf w = \left[\begin{equation}\begin{array}{c|c}\bf w</em>{11} \ w<em>{12}\ \bf w</em>{21} \ w_{22} \end{array}\end{equation}\right] $, 激活函数为 $\sigma(z)$, 通过激活函数的结果为 $\bf a$, 然后$\bf a$ 再作为下一层的输入通过神经元,通过激活函数,直到最后一层得到Loss function $\bf L$</li>
<li>图</li>
</ul>