-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
1784 lines (611 loc) · 84 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 mist 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.4" rel="stylesheet" type="text/css" />
<link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png?v=5.1.4">
<link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png?v=5.1.4">
<link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png?v=5.1.4">
<link rel="mask-icon" href="/images/logo.svg?v=5.1.4" color="#222">
<meta name="keywords" content="Hexo, NexT" />
<meta property="og:type" content="website">
<meta property="og:title" content="学习之路">
<meta property="og:url" content="http://example.com/index.html">
<meta property="og:site_name" content="学习之路">
<meta property="og:locale">
<meta property="article:author" content="叽里咕噜">
<meta name="twitter:card" content="summary">
<script type="text/javascript" id="hexo.configurations">
var NexT = window.NexT || {};
var CONFIG = {
root: '',
scheme: 'Mist',
version: '5.1.4',
sidebar: {"position":"left","display":"hide","offset":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","sidebar":"slideUpIn"}},
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://example.com/"/>
<title>学习之路</title>
<meta name="generator" content="Hexo 5.2.0"></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="/%20" rel="section">
<i class="menu-item-icon fa fa-fw fa-home"></i> <br />
首页
</a>
</li>
<li class="menu-item menu-item-about">
<a href="/about/%20" rel="section">
<i class="menu-item-icon fa fa-fw fa-user"></i> <br />
关于
</a>
</li>
<li class="menu-item menu-item-tags">
<a href="/tags/%20" rel="section">
<i class="menu-item-icon fa fa-fw fa-tags"></i> <br />
标签
</a>
</li>
<li class="menu-item menu-item-categories">
<a href="/categories/%20" rel="section">
<i class="menu-item-icon fa fa-fw fa-th"></i> <br />
分类
</a>
</li>
<li class="menu-item menu-item-archives">
<a href="/archives/%20" rel="section">
<i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
归档
</a>
</li>
<li class="menu-item menu-item-commonweal">
<a href="/404/%20" rel="section">
<i class="menu-item-icon fa fa-fw fa-heartbeat"></i> <br />
公益404
</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://example.com/2020/11/17/VCForPython27%E7%9A%84%E5%AE%89%E8%A3%85%E8%B7%AF%E5%BE%84/">
<span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
<meta itemprop="name" content="">
<meta itemprop="description" content="">
<meta itemprop="image" content="/images/avatar.jpg">
</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="/2020/11/17/VCForPython27%E7%9A%84%E5%AE%89%E8%A3%85%E8%B7%AF%E5%BE%84/" itemprop="url">VCForPython27的安装路径</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="2020-11-17T16:48:10+08:00">
2020-11-17
</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/%E7%B3%BB%E7%BB%9F%E6%90%AD%E5%BB%BA/" itemprop="url" rel="index">
<span itemprop="name">系统搭建</span>
</a>
</span>
</span>
</div>
</header>
<div class="post-body" itemprop="articleBody">
<p><code>VCForPython27(Microsoft Visual C++ Compiler for Python 2.7)</code></p>
<p><code>C:\Users\hss\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python\9.0\VC</code></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://example.com/2020/11/17/pip%E6%BA%90%E9%85%8D%E7%BD%AE%E4%BF%AE%E6%94%B9/">
<span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
<meta itemprop="name" content="">
<meta itemprop="description" content="">
<meta itemprop="image" content="/images/avatar.jpg">
</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="/2020/11/17/pip%E6%BA%90%E9%85%8D%E7%BD%AE%E4%BF%AE%E6%94%B9/" itemprop="url">pip源修改</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="2020-11-17T16:48:10+08:00">
2020-11-17
</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/%E7%B3%BB%E7%BB%9F%E6%90%AD%E5%BB%BA/" itemprop="url" rel="index">
<span itemprop="name">系统搭建</span>
</a>
</span>
</span>
</div>
</header>
<div class="post-body" itemprop="articleBody">
<h3 id="Mac"><a href="#Mac" class="headerlink" title="Mac"></a>Mac</h3><p>使用Terminal在当前用户目录下通过命令<code>mkdir .pip</code>新建一个**.pip<strong>文件夹,然后在</strong>.pip<strong>文件夹内使用命令<code>touch pip.conf</code>新建一个文件</strong>pip.conf<strong>,在文件</strong>pip.conf**中以下内容:</p>
<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></pre></td><td class="code"><pre><span class="line">[<span class="keyword">global</span>]</span><br><span class="line">index-url = http://pypi.douban.com/simple</span><br><span class="line">[install]</span><br><span class="line">trusted-host=pypi.douban.com</span><br></pre></td></tr></table></figure>
<h3 id="Windows"><a href="#Windows" class="headerlink" title="Windows"></a>Windows</h3><p>在当前用户目录下<code>C:\Users\hss</code>新建一个<strong>pip</strong>文件夹,然后在该文件夹内新家一个文件<strong>pip.ini</strong> ,并在文件<strong>pip.ini</strong>中写入以下内容:</p>
<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></pre></td><td class="code"><pre><span class="line">[<span class="keyword">global</span>]</span><br><span class="line">index-url = http://pypi.douban.com/simple</span><br><span class="line">[install]</span><br><span class="line">trusted-host=pypi.douban.com</span><br></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://example.com/2020/11/17/hello-world/">
<span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
<meta itemprop="name" content="">
<meta itemprop="description" content="">
<meta itemprop="image" content="/images/avatar.jpg">
</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="/2020/11/17/hello-world/" itemprop="url">Hello World</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="2020-11-17T14:42:31+08:00">
2020-11-17
</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/%E7%B3%BB%E7%BB%9F%E6%90%AD%E5%BB%BAQuick-Start/" itemprop="url" rel="index">
<span itemprop="name">系统搭建Quick Start</span>
</a>
</span>
</span>
</div>
</header>
<div class="post-body" itemprop="articleBody">
<h3 id="Create-a-new-post"><a href="#Create-a-new-post" class="headerlink" title="Create a new post"></a>Create a new post</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$ hexo new <span class="string">"My New Post"</span></span><br></pre></td></tr></table></figure>
<p>More info: <a target="_blank" rel="noopener" href="https://hexo.io/docs/writing.html">Writing</a></p>
<h3 id="Run-server"><a href="#Run-server" class="headerlink" title="Run server"></a>Run server</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$ hexo server</span><br></pre></td></tr></table></figure>
<p>More info: <a target="_blank" rel="noopener" href="https://hexo.io/docs/server.html">Server</a></p>
<h3 id="Generate-static-files"><a href="#Generate-static-files" class="headerlink" title="Generate static files"></a>Generate static files</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$ hexo generate</span><br></pre></td></tr></table></figure>
<p>More info: <a target="_blank" rel="noopener" href="https://hexo.io/docs/generating.html">Generating</a></p>
<h3 id="Deploy-to-remote-sites"><a href="#Deploy-to-remote-sites" class="headerlink" title="Deploy to remote sites"></a>Deploy to remote sites</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$ hexo deploy</span><br></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://example.com/2016/12/18/OpenCV+Python+Windows%E4%B8%8B%E7%9A%84%E7%8E%AF%E5%A2%83%E6%90%AD%E5%BB%BA/">
<span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
<meta itemprop="name" content="">
<meta itemprop="description" content="">
<meta itemprop="image" content="/images/avatar.jpg">
</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="/2016/12/18/OpenCV+Python+Windows%E4%B8%8B%E7%9A%84%E7%8E%AF%E5%A2%83%E6%90%AD%E5%BB%BA/" itemprop="url">OpenCV+Python+Windows下的环境搭建</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="2016-12-18T18:52:00+08:00">
2016-12-18
</time>
</span>
</div>
</header>
<div class="post-body" itemprop="articleBody">
<p>直接下载 安装OpenCV-2.4.5.exe ,实际上就是解压缩的过程。进入OpenCV的安装目录下找到:<code>\build\python\2.7\cv2.pyd</code>,将<strong>cv2.pyd</strong>复制到<strong>Python</strong>的子目录下:<code>\Lib\site-packages\</code>,至此环境就搭建好了。</p>
<p>OpenCV自带了很多示例程序,进入OpenCV安装目录下的子目录:<code>\samples\python2\</code> ,可以看到很多以.py为后缀名的文件;用python随便打开一个.py文件,按F5键运行,看看效果</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://example.com/2016/10/10/%E5%AE%9E%E9%AA%8C%E6%B5%81%E7%A8%8B%E5%88%86%E6%9E%90/">
<span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
<meta itemprop="name" content="">
<meta itemprop="description" content="">
<meta itemprop="image" content="/images/avatar.jpg">
</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="/2016/10/10/%E5%AE%9E%E9%AA%8C%E6%B5%81%E7%A8%8B%E5%88%86%E6%9E%90/" 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="2016-10-10T15:38:14+08:00">
2016-10-10
</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/%E5%9B%BE%E5%83%8F%E5%A4%84%E7%90%86/" itemprop="url" rel="index">
<span itemprop="name">图像处理</span>
</a>
</span>
</span>
</div>
</header>
<div class="post-body" itemprop="articleBody">
<h2 id="准备数据集"><a href="#准备数据集" class="headerlink" title="准备数据集"></a>准备数据集</h2><h2 id="训练集"><a href="#训练集" class="headerlink" title="训练集"></a>训练集</h2><pre><code>使用SRCNN论文中的**generate_train.m**和直接生成。只需加一句`image = image*2-1`将数据归一化到(-1,1)之间。最后生成的数据结构为**train.h5[data,label]**:</code></pre>
<h2 id="测试集"><a href="#测试集" class="headerlink" title="测试集"></a>测试集</h2><pre><code>由于只对一张图像进行测试,因此需要自己写程序进行测试集的构造。大致流程与训练集的构造过程相仿。都是提取灰度值、归一化像素值到(-1,1)之间、放大倍数的剪切、放大倍数的缩放、开始提取`33×33、21×21`的图像块。最后形成的数据结构为:`data(:, :, 1, count)、label(:, :, 1, count)`。程序为**im2patch_test.m**,代码如下所示:</code></pre>
<figure class="highlight c++"><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></pre></td><td class="code"><pre><span class="line"></span><br><span class="line">clc,clear all;</span><br><span class="line"></span><br><span class="line">%% 初始化参数</span><br><span class="line">filename = 'C:\Users\hss\Documents\MATLAB\SR\data\Test\Set5\butterfly_GT.bmp'</span><br><span class="line">scale = <span class="number">3</span>;</span><br><span class="line">size_patch = <span class="number">33</span>;</span><br><span class="line">size_label = <span class="number">21</span>;</span><br><span class="line">padding = <span class="built_in">abs</span>(size_patch - size_label)/<span class="number">2</span>;</span><br><span class="line">stride = <span class="number">14</span>;</span><br><span class="line"></span><br><span class="line">%% 读取图像、进行切割、转化为灰度图、像素值归一化到(<span class="number">-1</span>,<span class="number">1</span>)</span><br><span class="line">image = imread(filename);</span><br><span class="line">image = modcrop(image, scale);</span><br><span class="line">image = rgb2ycbcr(image);</span><br><span class="line">image = image(:,:,<span class="number">1</span>);</span><br><span class="line">image = im2double(image);</span><br><span class="line">image = image*<span class="number">2</span><span class="number">-1</span>;</span><br><span class="line"></span><br><span class="line">%% 进行放缩得到与原来大小一致的低分辨图像(插值图像)</span><br><span class="line">[m,n] = size(image);</span><br><span class="line">im_b = imresize(imresize(image,1/scale,'bicubic'),[m,n],'bicubic');</span><br><span class="line"></span><br><span class="line">%% 对清晰图像和插值图像进行外扩以便于构建测试集、并获取外扩图像的尺寸</span><br><span class="line">im_input = padarray(im_b,[padding,padding],'symmetric');</span><br><span class="line">im_label = padarray(image,[padding,padding],'symmetric');</span><br><span class="line">[hei,wid] = size(im_input);</span><br><span class="line"></span><br><span class="line">%% 初始化数据块、标签块、标签块矩阵(存放所有的标签块权值)、计数器</span><br><span class="line">data = zeros(size_patch,size_patch,<span class="number">1</span>,<span class="number">1</span>);</span><br><span class="line">label = zeros(size_label,size_label,<span class="number">1</span>,<span class="number">1</span>);</span><br><span class="line">count = <span class="number">0</span>;</span><br><span class="line"></span><br><span class="line">%% 开始循环</span><br><span class="line">temp_x = <span class="number">1</span>:stride:hei-size_patch + <span class="number">1</span>;</span><br><span class="line">x = [temp_x hei-size_patch+<span class="number">1</span>];</span><br><span class="line">temp_y = <span class="number">1</span>:stride:wid-size_patch + <span class="number">1</span>;</span><br><span class="line">y = [temp_y wid-size_patch+<span class="number">1</span>];</span><br><span class="line">count = <span class="number">1</span>;</span><br><span class="line"><span class="keyword">for</span> i = <span class="number">1</span>:size(x,<span class="number">2</span>)</span><br><span class="line"> <span class="keyword">for</span> j = <span class="number">1</span>:size(y,<span class="number">2</span>) </span><br><span class="line"> data(:, :, <span class="number">1</span>, count) = im_input(x(i) : x(i)+size_patch<span class="number">-1</span>, y(j) : y(j)+size_patch<span class="number">-1</span>);</span><br><span class="line"> label(:, :, <span class="number">1</span>, count) = im_label(x(i)+padding : x(i)+padding+size_label<span class="number">-1</span>, y(j)+padding : y(j)+padding+size_label<span class="number">-1</span>);</span><br><span class="line"> count = count + <span class="number">1</span>;</span><br><span class="line"> end</span><br><span class="line">end</span><br><span class="line"></span><br><span class="line">%% 将数据、标签、标签权值矩阵进行持久化存储,image像素值归一化到(<span class="number">0</span>,<span class="number">255</span>)</span><br><span class="line">save('test_butterfly.mat','data','label');</span><br><span class="line">image = (image+<span class="number">1</span>)/<span class="number">2</span>; </span><br><span class="line">image = uint8(image * <span class="number">255</span>);</span><br><span class="line">save('ground_image_butterfly.mat','image')</span><br><span class="line">imshow(image)</span><br></pre></td></tr></table></figure>
<h2 id="图像的恢复"><a href="#图像的恢复" class="headerlink" title="图像的恢复"></a>图像的恢复</h2><pre><code>一边训练一边恢复、因此恢复图像的程序使用python编写。大致思路与构造测试集时相仿。为了方便使用将其写成一个函数,该函数需要接收预测数据`pred_patch`、图像的剪切后大小`image_size`。具体程序如下:</code></pre>
<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></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">patch2im</span>(<span class="params">pred_patch,image_size</span>):</span> </span><br><span class="line"> size_patch=<span class="number">33</span></span><br><span class="line"> size_label=<span class="number">21</span></span><br><span class="line"> stride=<span class="number">14</span> </span><br><span class="line"> <span class="comment"># 初始化参数</span></span><br><span class="line"> <span class="keyword">from</span> numpy <span class="keyword">import</span> zeros</span><br><span class="line"> padding = <span class="built_in">abs</span>(size_patch - size_label)/<span class="number">2</span> </span><br><span class="line"> hei = image_size[<span class="number">0</span>] + <span class="number">2</span>*padding</span><br><span class="line"> wid = image_size[<span class="number">1</span>] + <span class="number">2</span>*padding </span><br><span class="line"> </span><br><span class="line"> <span class="comment">#开始处理图像块</span></span><br><span class="line"> count = <span class="number">0</span></span><br><span class="line"> x = <span class="built_in">range</span>(<span class="number">0</span>, hei - size_patch, stride)</span><br><span class="line"> x.append(hei - size_patch)</span><br><span class="line"> y = <span class="built_in">range</span>(<span class="number">0</span>, wid - size_patch , stride) </span><br><span class="line"> y.append(wid - size_patch)</span><br><span class="line"> x = <span class="built_in">sorted</span>(x)</span><br><span class="line"> y = <span class="built_in">sorted</span>(y)</span><br><span class="line"> </span><br><span class="line"> sum_patch = zeros([hei ,wid])</span><br><span class="line"> weight = zeros([hei, wid])</span><br><span class="line"> </span><br><span class="line"> <span class="keyword">for</span> i <span class="keyword">in</span> <span class="built_in">range</span>(<span class="built_in">len</span>(x)):</span><br><span class="line"> <span class="keyword">for</span> j <span class="keyword">in</span> <span class="built_in">range</span>(<span class="built_in">len</span>(y)): </span><br><span class="line"> im_patch = zeros([hei,wid]) </span><br><span class="line"> im_patch[x[i]+padding : x[i]+padding+size_label, y[j]+padding : y[j]+padding+size_label] = pred_patch[:,:,count].reshape([size_label,size_label])</span><br><span class="line"> sum_patch = sum_patch + im_patch </span><br><span class="line"> count = count +<span class="number">1</span></span><br><span class="line"></span><br><span class="line"> weight_temp = zeros([hei, wid])</span><br><span class="line"> weight_temp[x[i]+padding : x[i]+padding+size_label, y[j]+padding : y[j]+padding+size_label]=<span class="number">1</span></span><br><span class="line"> weight = weight + weight_temp </span><br><span class="line"> </span><br><span class="line"> im = (sum_patch/weight)</span><br><span class="line"> im = shave(im,[padding,padding]) </span><br><span class="line"> </span><br><span class="line"> <span class="keyword">return</span> im</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></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">shave</span>(<span class="params">I,border=<span class="literal">None</span></span>):</span></span><br><span class="line"> I = I[border[<span class="number">0</span>]:I.shape[<span class="number">0</span>]-border[<span class="number">0</span>],border[<span class="number">1</span>]:I.shape[<span class="number">1</span>]-border[<span class="number">1</span>]]</span><br><span class="line"> <span class="keyword">return</span> I</span><br></pre></td></tr></table></figure>
<h2 id="计算PSNR的函数"><a href="#计算PSNR的函数" class="headerlink" title="计算PSNR的函数"></a>计算PSNR的函数</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></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">compute_psnr</span>(<span class="params">im1,im2</span>):</span></span><br><span class="line"> <span class="keyword">from</span> numpy <span class="keyword">import</span> sqrt, square, mean, log10</span><br><span class="line"> diff = (im1 - im2).reshape(<span class="number">-1</span>,<span class="number">1</span>)</span><br><span class="line"> rmse = sqrt(mean(square(diff)))</span><br><span class="line"> psnr = <span class="number">20</span>*log10(<span class="number">255.0</span>/rmse)</span><br><span class="line"> <span class="keyword">return</span> psnr</span><br></pre></td></tr></table></figure>
<h2 id="网络的构建"><a href="#网络的构建" class="headerlink" title="网络的构建"></a>网络的构建</h2><pre><code>网络输入层接收`shape=(None,1,33,33)`类型的输入,4层中间层采用`tanh`函数,输出层采用441输出,激活函数仍是`tanh`。具体代码如下:</code></pre>
<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></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">build_mlp</span>(<span class="params">input_var = <span class="literal">None</span></span>):</span></span><br><span class="line"> l_in = InputLayer(shape=(<span class="literal">None</span>,<span class="number">1</span>,<span class="number">33</span>,<span class="number">33</span>),input_var=input_var)</span><br><span class="line"> l_hid1 = batch_norm(DenseLayer(l_in,num_units=<span class="number">1024</span>,nonlinearity=lasagne.nonlinearities.tanh)) </span><br><span class="line"> l_hid2 = batch_norm(DenseLayer(l_hid1,num_units=<span class="number">1024</span>,nonlinearity=lasagne.nonlinearities.tanh))</span><br><span class="line"> l_hid3 = batch_norm(DenseLayer(l_hid2,num_units=<span class="number">1024</span>,nonlinearity=lasagne.nonlinearities.tanh))</span><br><span class="line"> l_hid4 = batch_norm(DenseLayer(l_hid3,num_units=<span class="number">1024</span>,nonlinearity=lasagne.nonlinearities.tanh))</span><br><span class="line"> l_out = DenseLayer(l_hid4, num_units=<span class="number">441</span>,nonlinearity=lasagne.nonlinearities.tanh)</span><br><span class="line"> <span class="keyword">return</span> l_out</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></pre></td><td class="code"><pre><span class="line">input_var = theano.tensor.ftensor4(<span class="string">'inputs'</span>)</span><br><span class="line">target_var = theano.tensor.fmatrix(<span class="string">'targets'</span>)</span><br><span class="line"></span><br><span class="line"><span class="built_in">print</span> <span class="string">"Building model and compiling functions..."</span></span><br><span class="line">network = build_mlp(input_var)</span><br><span class="line"></span><br><span class="line">prediction = lasagne.layers.get_output(network)</span><br><span class="line">loss = lasagne.objectives.squared_error(prediction,target_var).mean()</span><br><span class="line"></span><br><span class="line">learning_rate = <span class="number">0.01</span> </span><br><span class="line">Layers=lasagne.layers.get_all_layers(network)</span><br><span class="line"><span class="comment">#updates={}</span></span><br><span class="line">updates = collections.OrderedDict()</span><br><span class="line">updates.update(lasagne.updates.sgd(</span><br><span class="line"> loss, </span><br><span class="line"> Layers[<span class="number">-1</span>].get_params(trainable=<span class="literal">True</span>),</span><br><span class="line"> learning_rate*<span class="number">0.1</span></span><br><span class="line"> ))</span><br><span class="line"><span class="keyword">for</span> i <span class="keyword">in</span> <span class="built_in">range</span>(<span class="built_in">len</span>(Layers)<span class="number">-1</span>): </span><br><span class="line"> updates.update(lasagne.updates.sgd(</span><br><span class="line"> loss, </span><br><span class="line"> Layers[i].get_params(trainable=<span class="literal">True</span>),</span><br><span class="line"> learning_rate</span><br><span class="line"> ))</span><br><span class="line"></span><br><span class="line">train_fn = theano.function([input_var,target_var],loss,updates = updates)</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></pre></td><td class="code"><pre><span class="line"></span><br></pre></td></tr></table></figure>
<pre><code>使用SRCNN论文中的程序(generate_train.m)直接上生成训练集(train.h5)。数据结构为[data,label]。同样的利用generate_test.m、generate_val.m依次生成测试集(test.h5)和验证集(val.h5)。本次实验中并不需要验证集和测试集。而是利用im2patch.m来构造测试集。</code></pre>
<p>‘网络的输出结果为(-1,1),因此在恢复图像时需要将恢复的图像进行加一除二其映射回来’</p>
<p>构造的训练集</p>
<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><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></pre></td><td class="code"><pre><span class="line">network = build_mlp(input_var)</span><br><span class="line"></span><br><span class="line">prediction = lasagne.layers.get_output(network)</span><br><span class="line">loss = lasagne.objectives.squared_error(prediction,target_var).mean()</span><br><span class="line"></span><br><span class="line">learning_rate = 0.01 </span><br><span class="line">Layers=lasagne.layers.get_all_layers(network)</span><br><span class="line">#updates={}</span><br><span class="line">updates = collections.OrderedDict()</span><br><span class="line">updates.update(lasagne.updates.sgd(</span><br><span class="line"> loss, </span><br><span class="line"> Layers[-1].get_params(trainable=True),</span><br><span class="line"> learning_rate*0.1</span><br><span class="line"> ))</span><br><span class="line">for i in range(len(Layers)-1): </span><br><span class="line"> updates.update(lasagne.updates.sgd(</span><br><span class="line"> loss, </span><br><span class="line"> Layers[i].get_params(trainable=True),</span><br><span class="line"> learning_rate</span><br><span class="line"> ))</span><br><span class="line"></span><br><span class="line">train_fn = theano.function([input_var,target_var],loss,updates = updates)</span><br></pre></td></tr></table></figure>
<p>用python打印灰度图像</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">import matplotlib.pyplot as plt</span><br><span class="line">plt.imshow(img, cmap = plt.get_cmap('gray'))</span><br></pre></td></tr></table></figure>