-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
286 lines (252 loc) · 40.2 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
<!DOCTYPE html><html lang="zh-CN" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"><title>张恩硕的网站 - 个人证券交易记录</title><meta name="keywords" content="证券交易"><meta name="author" content="张恩硕,zhangensure@foxmail.com"><meta name="copyright" content="张恩硕"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta name="description" content="Inner Peace">
<meta property="og:type" content="website">
<meta property="og:title" content="张恩硕的网站">
<meta property="og:url" content="https://yuwenyin.xyz/index.html">
<meta property="og:site_name" content="张恩硕的网站">
<meta property="og:description" content="Inner Peace">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://yuwenyin.xyz/photo/head.jpg">
<meta property="article:author" content="张恩硕">
<meta property="article:tag" content="证券交易">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://yuwenyin.xyz/photo/head.jpg"><link rel="shortcut icon" href="/img/favicon.png"><link rel="canonical" href="https://yuwenyin.xyz/"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="preconnect" href="//www.google-analytics.com" crossorigin=""/><link rel="preconnect" href="//busuanzi.ibruce.info"/><link rel="stylesheet" href="/css/index.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free/css/all.min.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox.min.css" media="print" onload="this.media='all'"><script async="async" src="https://www.googletagmanager.com/gtag/js?id=G-F56P0PX7NX"></script><script>window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-F56P0PX7NX');
</script><script>const GLOBAL_CONFIG = {
root: '/',
algolia: undefined,
localSearch: {"path":"/search.xml","preload":true,"languages":{"hits_empty":"找不到您查询的内容:${query}"}},
translate: undefined,
noticeOutdate: undefined,
highlight: {"plugin":"highlighjs","highlightCopy":true,"highlightLang":true,"highlightHeightLimit":false},
copy: {
success: '复制成功',
error: '复制错误',
noSupport: '浏览器不支持'
},
relativeDate: {
homepage: false,
post: false
},
runtime: '天',
date_suffix: {
just: '刚刚',
min: '分钟前',
hour: '小时前',
day: '天前',
month: '个月前'
},
copyright: undefined,
lightbox: 'fancybox',
Snackbar: undefined,
source: {
justifiedGallery: {
js: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery/dist/fjGallery.min.js',
css: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery/dist/fjGallery.min.css'
}
},
isPhotoFigcaption: false,
islazyload: false,
isAnchor: true
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = {
title: '张恩硕的网站',
isPost: false,
isHome: true,
isHighlightShrink: false,
isToc: false,
postUpdate: '2023-09-07 13:04:12'
}</script><noscript><style type="text/css">
#nav {
opacity: 1
}
.justified-gallery img {
opacity: 1
}
#recent-posts time,
#post-meta time {
display: inline !important
}
</style></noscript><script>(win=>{
win.saveToLocal = {
set: function setWithExpiry(key, value, ttl) {
if (ttl === 0) return
const now = new Date()
const expiryDay = ttl * 86400000
const item = {
value: value,
expiry: now.getTime() + expiryDay,
}
localStorage.setItem(key, JSON.stringify(item))
},
get: function getWithExpiry(key) {
const itemStr = localStorage.getItem(key)
if (!itemStr) {
return undefined
}
const item = JSON.parse(itemStr)
const now = new Date()
if (now.getTime() > item.expiry) {
localStorage.removeItem(key)
return undefined
}
return item.value
}
}
win.getScript = url => new Promise((resolve, reject) => {
const script = document.createElement('script')
script.src = url
script.async = true
script.onerror = reject
script.onload = script.onreadystatechange = function() {
const loadState = this.readyState
if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
script.onload = script.onreadystatechange = null
resolve()
}
document.head.appendChild(script)
})
win.activateDarkMode = function () {
document.documentElement.setAttribute('data-theme', 'dark')
if (document.querySelector('meta[name="theme-color"]') !== null) {
document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
}
}
win.activateLightMode = function () {
document.documentElement.setAttribute('data-theme', 'light')
if (document.querySelector('meta[name="theme-color"]') !== null) {
document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
}
}
const t = saveToLocal.get('theme')
if (t === 'dark') activateDarkMode()
else if (t === 'light') activateLightMode()
const asideStatus = saveToLocal.get('aside-status')
if (asideStatus !== undefined) {
if (asideStatus === 'hide') {
document.documentElement.classList.add('hide-aside')
} else {
document.documentElement.classList.remove('hide-aside')
}
}
const detectApple = () => {
if(/iPad|iPhone|iPod|Macintosh/.test(navigator.userAgent)){
document.documentElement.classList.add('apple')
}
}
detectApple()
})(window)</script><meta name="generator" content="Hexo 6.2.0"></head><body><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="avatar-img is-center"><img src="/photo/head.jpg" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="sidebar-site-data site-data is-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">17</div></a><a href="/tags/"><div class="headline">标签</div><div class="length-num">10</div></a><a href="/categories/"><div class="headline">分类</div><div class="length-num">2</div></a></div><hr/><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fas fa-archive"></i><span> 时间轴</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page group" href="javascript:void(0);"><i class="fa-fw fas fa-list"></i><span> 清单</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/music/"><i class="fa-fw fas fa-music"></i><span> 音乐</span></a></li><li><a class="site-page child" href="/Gallery/"><i class="fa-fw fas fa-images"></i><span> 照片</span></a></li><li><a class="site-page child" href="/movies/"><i class="fa-fw fas fa-video"></i><span> 电影</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw fas fa-link"></i><span> 友链</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fas fa-heart"></i><span> 关于</span></a></div></div></div></div><div class="page" id="body-wrap"><header class="full_page" id="page-header" style="background-image: url('https://s3.bmp.ovh/imgs/2022/11/15/521e563def1a94ae.jpg')"><nav id="nav"><span id="blog_name"><a id="site-name" href="/">张恩硕的网站</a></span><div id="menus"><div id="search-button"><a class="site-page social-icon search"><i class="fas fa-search fa-fw"></i><span> 搜索</span></a></div><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fas fa-archive"></i><span> 时间轴</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page group" href="javascript:void(0);"><i class="fa-fw fas fa-list"></i><span> 清单</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/music/"><i class="fa-fw fas fa-music"></i><span> 音乐</span></a></li><li><a class="site-page child" href="/Gallery/"><i class="fa-fw fas fa-images"></i><span> 照片</span></a></li><li><a class="site-page child" href="/movies/"><i class="fa-fw fas fa-video"></i><span> 电影</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw fas fa-link"></i><span> 友链</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fas fa-heart"></i><span> 关于</span></a></div></div><div id="toggle-menu"><a class="site-page"><i class="fas fa-bars fa-fw"></i></a></div></div></nav><div id="site-info"><h1 id="site-title">张恩硕的网站</h1><div id="site-subtitle"><span id="subtitle"></span></div><div id="site_social_icons"><a class="social-icon" href="https://github.com/ZhangEnsure" target="_blank" title="Github"><i class="fab fa-github"></i></a><a class="social-icon" href="mailto:zhangensure@foxmail.com" target="_blank" title="Email"><i class="fas fa-envelope"></i></a><a class="social-icon" href="https://blog.csdn.net/Mr_Yuwen_Yin" target="_blank" title="CSDN"><i class="fas fa-browser"></i></a></div></div><div id="scroll-down"><i class="fas fa-angle-down scroll-down-effects"></i></div></header><main class="layout" id="content-inner"><div class="recent-posts" id="recent-posts"><div class="recent-post-item"><div class="post_cover left"><a href="/2023/09/07/test/" title="test"><img class="post_bg" src="https://s3.bmp.ovh/imgs/2023/08/30/9d03b5efd2101975.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="test"></a></div><div class="recent-post-info"><a class="article-title" href="/2023/09/07/test/" title="test">test</a><div class="article-meta-wrap"><span class="post-meta-date"><i class="far fa-calendar-alt"></i><span class="article-meta-label">发表于</span><time datetime="2023-09-07T03:21:37.000Z" title="发表于 2023-09-07 11:21:37">2023-09-07</time></span></div><div class="content">12345678910111213141516171819202122232425262728293031323334353637383940414243444546class TimeEmbedding(nn.Module): """ ### Embeddings for $t$ """ def __init__(self, n_channels: int): """ * `n_channels` is the number of dimensions in the embedding """ super().__init__() self.n_channels = n_channels # First linear layer self.lin1 = nn.Linear(self.n_channels // 4, self.n_channels ...</div></div></div><div class="recent-post-item"><div class="post_cover right"><a href="/2023/08/31/python%E4%B8%8Etorch/" title="python与torch"><img class="post_bg" src="https://s3.bmp.ovh/imgs/2023/08/31/c49a0718de6a7fbe.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="python与torch"></a></div><div class="recent-post-info"><a class="article-title" href="/2023/08/31/python%E4%B8%8Etorch/" title="python与torch">python与torch</a><div class="article-meta-wrap"><span class="post-meta-date"><i class="far fa-calendar-alt"></i><span class="article-meta-label">发表于</span><time datetime="2023-08-31T02:31:42.000Z" title="发表于 2023-08-31 10:31:42">2023-08-31</time></span></div><div class="content">一名柏柏尔人带领骆驼队穿越撒哈拉沙漠,摄于摩洛哥。
python用法
map()函数
map 的作用是依次将可迭代对象里的元素传给 map 中的函数,返回一个迭代器。
一个参数的情况
1234567891011121314# 定义一个函数def square(x): return x**2 # 序列nums = [1, 2, 3, 4, 5] # 对nums序列每个数求平方,返回迭代器nums_squared = map(square, nums) # 输出结果for num in nums_squared: print(num)
输出结果:
123451491625
当然我们也可以将上面例子中的 square 函数用 lambda 代码,例子如下:
1234567nums = [1, 2, 3, 4, 5] nums_squared = map(lambda x: x*x, nums) for num in nums_squared: print(num)
多个参数情况
12345678910111213141516# 定义一个函数# 该函数必须采用两个参数 ...</div></div></div><div class="recent-post-item"><div class="post_cover left"><a href="/2023/08/30/%E5%AE%9E%E7%8E%B0ddpm%E4%B8%AD%E5%AD%A6%E4%B9%A0%E5%88%B0%E7%9A%84%E7%9F%A5%E8%AF%86/" title="实现ddpm中学习到的知识"><img class="post_bg" src="https://s3.bmp.ovh/imgs/2023/08/30/9d03b5efd2101975.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="实现ddpm中学习到的知识"></a></div><div class="recent-post-info"><a class="article-title" href="/2023/08/30/%E5%AE%9E%E7%8E%B0ddpm%E4%B8%AD%E5%AD%A6%E4%B9%A0%E5%88%B0%E7%9A%84%E7%9F%A5%E8%AF%86/" title="实现ddpm中学习到的知识">实现ddpm中学习到的知识</a><div class="article-meta-wrap"><span class="post-meta-date"><i class="far fa-calendar-alt"></i><span class="article-meta-label">发表于</span><time datetime="2023-08-30T07:12:57.000Z" title="发表于 2023-08-30 15:12:57">2023-08-30</time></span></div><div class="content">斯洛文尼亚布莱德湖上的布莱德岛鸟瞰图。
前言
在实现 DDPM 代码的过程中,发现了很多可以补充自己代码能力的知识点,在此简单记录一下,顺带也是自己加深印象,不至于学完就忘。然后也借着这个文章,梳理一下在实现 DDPM 中很多自己遇到的困难,以及我自己的解决方案。
参考资料
1. 微信公众号文章:深入浅出扩散模型,代码篇
2. 科学空间:生成扩散模型漫谈(三):DDPM = 贝叶斯 + 去噪
3. Labml 复现 DDPM 代码
其他
torch 数据类型转换
1. gather()函数
先学习一个小知识,torch.gather 用法,对于 Tensor 中的数据进行切片的一个方式。
torch.gather(input, dim, index, *, sparse_grad=False, out=None) → Tensor
含义:对于输入 input 的 dim 维度取 index 对应的元素。
输入:可以是 torch.gather() ,也可以是某个实例化张量调用 tensor.gather(),省去了 input 参数。
输出:对 input 张量进行数据切片的结果 ...</div></div></div><div class="recent-post-item"><div class="post_cover right"><a href="/2023/08/27/ViT/" title="ViT"><img class="post_bg" src="https://s3.bmp.ovh/imgs/2023/08/27/af07242648c36a30.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="ViT"></a></div><div class="recent-post-info"><a class="article-title" href="/2023/08/27/ViT/" title="ViT">ViT</a><div class="article-meta-wrap"><span class="post-meta-date"><i class="far fa-calendar-alt"></i><span class="article-meta-label">发表于</span><time datetime="2023-08-27T03:54:49.000Z" title="发表于 2023-08-27 11:54:49">2023-08-27</time></span></div><div class="content">盖朗厄尔峡湾位于挪威,两岸耸立着海拔1500米以上的群山。
前言
在阅读相关 diffusion 论文时,经常会遇见许多自己之前不了解的知识,这是很正常的现象。既不用过度担心,也不要躺平,而是要在空闲的时候把不会的知识补上。
这里学习的是关于 Attention is all you need. 论文在视觉方向的应用 ViT。关于 Attention,最主要学习的内容就是 self-attention 实现细节,以及 Multi-Head self-attention。
这里的学习内容主要参考的是:
【李宏毅】讲解Attention论文
【霹雳啪啦】使用pytorch搭建ViT模型
Attention 回顾
self-attention 回顾
在这里首先回顾一下 self-attention 的实现。图片参考文章。
首先我们要在脑海中始终清楚一件事:self-attention 信息处理流程:
借助矩阵并行化,我们可以把权重矩阵 q k v 实现上写作一个矩阵 W,并且 W 针对不同的序列而言是共享的存在,例子中的两个序列 a1a_1a1 和 a2a_2a2 与 W 作矩阵 ...</div></div></div><div class="recent-post-item"><div class="post_cover left"><a href="/2023/06/03/Diffusion%E7%9B%B8%E5%85%B3%E5%8F%82%E8%80%83/" title="Diffusion相关参考"><img class="post_bg" src="https://s2.loli.net/2023/06/03/VCYQTDvd3RHOoUw.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="Diffusion相关参考"></a></div><div class="recent-post-info"><a class="article-title" href="/2023/06/03/Diffusion%E7%9B%B8%E5%85%B3%E5%8F%82%E8%80%83/" title="Diffusion相关参考">Diffusion相关参考</a><div class="article-meta-wrap"><span class="post-meta-date"><i class="far fa-calendar-alt"></i><span class="article-meta-label">发表于</span><time datetime="2023-06-03T09:25:27.000Z" title="发表于 2023-06-03 17:25:27">2023-06-03</time></span></div><div class="content">日出时可多帕西火山,厄瓜多尔科多帕希国家公园。
Diffusion Model 相关文章参考
【知乎】Diffusion Models必读的10篇经典论文
【综述】Diffusion Models发展
【知乎】DDPM与DDIN
提问:怎么理解ELOB公式?
ELBO(Evidence Lower Bound)是VAE模型中优化的目标函数,它可以用来近似原始的对数似然函数(log-likelihood),从而进行模型的训练。
ELBO的公式为:
Eqϕ(z∣x)[logp(x,z)qϕ(z∣x)]\mathbb{E}_{q \phi(z|x)}\left[\log\frac{p(x,z)}{q_\phi(z|x)}\right]
Eqϕ(z∣x)[logqϕ(z∣x)p(x,z)]
其中,p(x,z)p(x,z)p(x,z)表示联合分布,qϕ(z∣x)q_\phi(z|x)qϕ(z∣x)表示后验分布,即在给定输入数据xxx的情况下,潜在变量zzz的分布。ELBO可以理解为对数似然函数的下界,它的计算过程如下:
首先,将联合分布p(x,z)p(x,z)p(x,z)拆开,得到: ...</div></div></div><div class="recent-post-item"><div class="post_cover right"><a href="/2022/11/14/%E6%8D%9F%E5%A4%B1%E5%87%BD%E6%95%B0/" title="损失函数"><img class="post_bg" src="https://s3.bmp.ovh/imgs/2022/11/14/9e3329cec56a83cd.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="损失函数"></a></div><div class="recent-post-info"><a class="article-title" href="/2022/11/14/%E6%8D%9F%E5%A4%B1%E5%87%BD%E6%95%B0/" title="损失函数">损失函数</a><div class="article-meta-wrap"><span class="post-meta-date"><i class="far fa-calendar-alt"></i><span class="article-meta-label">发表于</span><time datetime="2022-11-14T14:16:56.000Z" title="发表于 2022-11-14 22:16:56">2022-11-14</time></span></div><div class="content">损失函数
极大似然估计法
什么是似然值?似然值是现实情况已经发生,接着我们假设现实情况对应着有许多理论模型的概率分布,在某一个理论上的概率模型下,求得的现实情况发生概率。
既然有了似然值,最大似然估计法就应运而生了。既然在现实情况的已经发生的情况下,如何用现实情况推导理论总结?如何使用现实主义估测理论主义的结果?虽然我们没法永远准确地确定理论世界的事情发生的概率分布,但是根据求得的不同似然值中,选择似然值最大的模型,是一种理智的做法。
总结一下,当我们已知现实事情发生的结果,进而去反推产生此结果的概率模型的时候,往往用到极大似然估计法。
分类问题的损失函数
在这里以二分类的例子为切入点进行理解,例如设计一个神经网络尝试去分辨图片中的生物是不是猫。
假设我们的训练样本是 (xi,yi)(x_i,y_i)(xi,yi),神经网络的输出经过 sigmoid 归一化后的输出是 yi^\hat{y_i}yi^,我们可以这样认为:yi^\hat{y_i}yi^ 的值是神经网络认为输入的 xix_ixi 是一只猫(yiy_iyi=1)的概率,这样的话,1−yi^1-\hat{y_i} ...</div></div></div><div class="recent-post-item"><div class="post_cover left"><a href="/2022/11/02/%E8%B0%B7%E6%AD%8C%E8%BD%BB%E9%87%8F%E5%8C%96%E7%BD%91%E7%BB%9CMobileNetV1/" title="谷歌轻量化网络MobileNetV1"><img class="post_bg" src="https://s3.bmp.ovh/imgs/2022/11/02/51dc14470cfd9bfa.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="谷歌轻量化网络MobileNetV1"></a></div><div class="recent-post-info"><a class="article-title" href="/2022/11/02/%E8%B0%B7%E6%AD%8C%E8%BD%BB%E9%87%8F%E5%8C%96%E7%BD%91%E7%BB%9CMobileNetV1/" title="谷歌轻量化网络MobileNetV1">谷歌轻量化网络MobileNetV1</a><div class="article-meta-wrap"><span class="post-meta-date"><i class="far fa-calendar-alt"></i><span class="article-meta-label">发表于</span><time datetime="2022-11-02T12:46:41.000Z" title="发表于 2022-11-02 20:46:41">2022-11-02</time></span><span class="article-meta"><span class="article-meta-separator">|</span><i class="fas fa-inbox"></i><a class="article-meta__categories" href="/categories/%E5%9B%BE%E5%83%8F%E5%88%86%E7%B1%BB/">图像分类</a><i class="fas fa-angle-right article-meta-link"></i><a class="article-meta__categories" href="/categories/%E5%9B%BE%E5%83%8F%E5%88%86%E7%B1%BB/%E8%BD%BB%E9%87%8F%E5%8C%96%E7%BD%91%E7%BB%9C/">轻量化网络</a></span></div><div class="content">秋天的图林根森林与瓦特堡城堡,德国 (© ezypix/Getty Images)
MobileNet V1
适用于移动端本地进行实时边缘计算,不需要上传到云服务器中。一来是保障了实时性,二是保障了一些隐私的信息。在终端需要更大的计算能力,同时我们的模型也要更加的轻量化,这就对我们的软硬件都提出了较高的要求。端云结合,云端训练模型,得到的模型部署在终端。那么轻量化网络可以优化的具体方向有哪些呢?例如对深度学习框架进行CUDA加速、因为轻量化网络比较精简,所以该模型会不会被欺骗?这就引入了对抗学习。
Depthwise separable convolution
MobileNet 基于深度可分离卷积对卷积层进行优化和改进,从而降低参数量减少计算量,使网络更加轻量化,这是 MobileNet 核心思想。深度可分离卷积的图示如下:
正常的卷积是卷积核是w∗h∗cin∗coutw*h*c_{in}*c_{out}w∗h∗cin∗cout,在这张图片的cinc_{in}cin是3。每一次卷积都生成 feature_map 中的一个值,最后将 coutc_{out}cout 个 f ...</div></div></div><div class="recent-post-item"><div class="post_cover right"><a href="/2022/10/28/%E8%BF%81%E7%A7%BB%E5%AD%A6%E4%B9%A0/" title="迁移学习"><img class="post_bg" src="https://s3.bmp.ovh/imgs/2022/10/28/357ddf11693458cb.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="迁移学习"></a></div><div class="recent-post-info"><a class="article-title" href="/2022/10/28/%E8%BF%81%E7%A7%BB%E5%AD%A6%E4%B9%A0/" title="迁移学习">迁移学习</a><div class="article-meta-wrap"><span class="post-meta-date"><i class="far fa-calendar-alt"></i><span class="article-meta-label">发表于</span><time datetime="2022-10-28T11:29:46.000Z" title="发表于 2022-10-28 19:29:46">2022-10-28</time></span></div><div class="content">迁移学习与fine tuning
这里记录一下在 bilibili up同济子豪兄迁移学习视频笔记。迁移学习是指,把他人已经训练好的模型,泛化到我们自己的数据集上,也就是训练一个 CNN 网络并不是非要需要大量的数据集。
当我们的数据集比较小,而且与 ImageNet 数据集的数据分布十分相像(例如我们的数据集也是动物、生活用品),而不是特殊场景(例如工业钢轨缺陷检测)时,我们可以仅修改分类器的最后一层并训练更新其参数,同时冻结其他所有的层(保留结构和参数),
当我们的数据集很大,数据分布相似,我们可以解冻分类器的 FC 层,冻结特征提取网络,最后更新解冻层的参数即可。
当我们的数据集很大,但是数据很不相似,例如医疗数据的诊断,我们需要往前训练更多的层,同时预训练权重可以是 ImageNet 数据集上已有的权重,在我们自己的数据集上更新我们的参数权重。
常见的可供迁移学习的优秀主干网络取下。也就是说,无论是 ImageNet 还是皮肤癌图像分类等等问题,我们认为,以下这些主干网络提取到的特征都是通用的,我们借助提取到的通用的特征之后,在分类器上做处理。
</div></div></div><div class="recent-post-item"><div class="post_cover left"><a href="/2022/10/27/%E5%8A%A8%E6%80%81%E8%A7%84%E5%88%92/" title="动态规划"><img class="post_bg" src="https://s3.bmp.ovh/imgs/2022/10/27/bf1a95fd40fd0de4.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="动态规划"></a></div><div class="recent-post-info"><a class="article-title" href="/2022/10/27/%E5%8A%A8%E6%80%81%E8%A7%84%E5%88%92/" title="动态规划">动态规划</a><div class="article-meta-wrap"><span class="post-meta-date"><i class="far fa-calendar-alt"></i><span class="article-meta-label">发表于</span><time datetime="2022-10-27T08:51:55.000Z" title="发表于 2022-10-27 16:51:55">2022-10-27</time></span></div><div class="content">银河下的哈纳雷湾 背景主题图源自美国夏威夷·哈纳雷
动态规划
动态规划这个概念十分有趣。举一个例子来说,在我本科学习“栈的应用”这部分内容的时候,提到了可以用栈实现“走迷宫”的问题。也就是在代码中,如果我们发现某一条路径进入死胡同的时候,要按原路回退。回退的前提是我们有一个数据结构——栈,用它来保存我们之前的行走路径。如果没有栈应用在迷宫问题,那不得不回退到起点再重新执行,这将很麻烦。所以,这里提到了一个重要的思想:保留之前运算的结果,不进行重复冗余的计算。
动态规划在我的理解而言,可以想象为:有某种问题看似很复杂,但是可以分解为较小的子问题进行求解。最小的子问题是方便求解的,同时存储中间子问题的计算结果。当然最重要的是,可以寻找到“该问题”和“分解的子问题”之间的递推关系表达式。
上面是我自己的理解,下面的内容摘录自书中规范化表述
和分治法一样,动态规划(dynamic programming)是通过组合子问题的解而解决整个问题的。(此处“programming”是指–种规划,而不是指写计算机代码)。分治法算法是指将问题划分成一些独立的子问题,递归地求解各子问题,然后合并子问题 ...</div></div></div><div class="recent-post-item"><div class="post_cover right"><a href="/2022/10/25/%E6%A0%91/" title="树"><img class="post_bg" src="https://s3.bmp.ovh/imgs/2022/10/25/bddb1e7faf4feba8.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="树"></a></div><div class="recent-post-info"><a class="article-title" href="/2022/10/25/%E6%A0%91/" title="树">树</a><div class="article-meta-wrap"><span class="post-meta-date"><i class="far fa-calendar-alt"></i><span class="article-meta-label">发表于</span><time datetime="2022-10-25T04:30:16.000Z" title="发表于 2022-10-25 12:30:16">2022-10-25</time></span></div><div class="content">红黑树
为何引入红黑树(RBT)
平衡二叉树AVL:插入/删除很容易破坏“平衡”特性,需要频繁调整树的形态。如:插入操作导致不平衡,则需要先计算平衡因子,找到最小不平衡子树(时间开销大),再进行LL/RR/LR/RL调整。
红黑树RBT:插入/删除很多时候不会破坏“红黑”特性,无需频繁调整树的形态。即便需要调整,一般都可以在常数级时间内完成
RBT定义
首先,红黑树是一个二叉排序树。其次,需要满足以下的条件:
①每个结点或是红色,或是黑色的
②根节点是黑色的
③叶结点(外部结点、NULL结点、失败结点)均是黑色的
④不存在两个相邻的红结点(即红结点的父节点和孩子结点均是黑色)
⑤对每个结点,从该节点到任一叶结点的简单路径上,所含黑结点的数目相同
这里需要注意的是,我们所说的第三条指的是查找失败的节点均是黑色的,如下图所示:
RBT的插入规则
先查找,确定插入位置(原理同二叉排序树)。
插入新结点是根——染为黑色;新结点非根——染为红色。
若插入新结点后依然满足红黑树定义,则插入结束。
若插入新结点后不满足红黑树定义,需要调整,使其重新满足红黑树定义。
叔叔结点是黑色:旋转+ ...</div></div></div><nav id="pagination"><div class="pagination"><span class="page-number current">1</span><a class="page-number" href="/page/2/#content-inner">2</a><a class="extend next" rel="next" href="/page/2/#content-inner"><i class="fas fa-chevron-right fa-fw"></i></a></div></nav></div><div class="aside-content" id="aside-content"><div class="card-widget card-info"><div class="is-center"><div class="avatar-img"><img src="/photo/head.jpg" onerror="this.onerror=null;this.src='/img/friend_404.gif'" alt="avatar"/></div><div class="author-info__name">张恩硕</div><div class="author-info__description">Inner Peace</div></div><div class="card-info-data site-data is-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">17</div></a><a href="/tags/"><div class="headline">标签</div><div class="length-num">10</div></a><a href="/categories/"><div class="headline">分类</div><div class="length-num">2</div></a></div><a id="card-info-btn" target="_blank" rel="noopener" href="https://github.com/ZhangEnsure"><i class="fab fa-github"></i><span>Follow Me</span></a><div class="card-info-social-icons is-center"><a class="social-icon" href="https://github.com/ZhangEnsure" target="_blank" title="Github"><i class="fab fa-github"></i></a><a class="social-icon" href="mailto:zhangensure@foxmail.com" target="_blank" title="Email"><i class="fas fa-envelope"></i></a><a class="social-icon" href="https://blog.csdn.net/Mr_Yuwen_Yin" target="_blank" title="CSDN"><i class="fas fa-browser"></i></a></div></div><div class="card-widget card-announcement"><div class="item-headline"><i class="fas fa-bullhorn fa-shake"></i><span>公告</span></div><div class="announcement_content">仅作为个人交易的心得和体会,不构成任何投资建议。</div></div><div class="sticky_layout"><div class="card-widget card-recent-post"><div class="item-headline"><i class="fas fa-history"></i><span>最新文章</span></div><div class="aside-list"><div class="aside-list-item"><a class="thumbnail" href="/2023/09/07/test/" title="test"><img src="https://s3.bmp.ovh/imgs/2023/08/30/9d03b5efd2101975.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="test"/></a><div class="content"><a class="title" href="/2023/09/07/test/" title="test">test</a><time datetime="2023-09-07T03:21:37.000Z" title="发表于 2023-09-07 11:21:37">2023-09-07</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/2023/08/31/python%E4%B8%8Etorch/" title="python与torch"><img src="https://s3.bmp.ovh/imgs/2023/08/31/c49a0718de6a7fbe.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="python与torch"/></a><div class="content"><a class="title" href="/2023/08/31/python%E4%B8%8Etorch/" title="python与torch">python与torch</a><time datetime="2023-08-31T02:31:42.000Z" title="发表于 2023-08-31 10:31:42">2023-08-31</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/2023/08/30/%E5%AE%9E%E7%8E%B0ddpm%E4%B8%AD%E5%AD%A6%E4%B9%A0%E5%88%B0%E7%9A%84%E7%9F%A5%E8%AF%86/" title="实现ddpm中学习到的知识"><img src="https://s3.bmp.ovh/imgs/2023/08/30/9d03b5efd2101975.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="实现ddpm中学习到的知识"/></a><div class="content"><a class="title" href="/2023/08/30/%E5%AE%9E%E7%8E%B0ddpm%E4%B8%AD%E5%AD%A6%E4%B9%A0%E5%88%B0%E7%9A%84%E7%9F%A5%E8%AF%86/" title="实现ddpm中学习到的知识">实现ddpm中学习到的知识</a><time datetime="2023-08-30T07:12:57.000Z" title="发表于 2023-08-30 15:12:57">2023-08-30</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/2023/08/27/ViT/" title="ViT"><img src="https://s3.bmp.ovh/imgs/2023/08/27/af07242648c36a30.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="ViT"/></a><div class="content"><a class="title" href="/2023/08/27/ViT/" title="ViT">ViT</a><time datetime="2023-08-27T03:54:49.000Z" title="发表于 2023-08-27 11:54:49">2023-08-27</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/2023/06/03/Diffusion%E7%9B%B8%E5%85%B3%E5%8F%82%E8%80%83/" title="Diffusion相关参考"><img src="https://s2.loli.net/2023/06/03/VCYQTDvd3RHOoUw.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="Diffusion相关参考"/></a><div class="content"><a class="title" href="/2023/06/03/Diffusion%E7%9B%B8%E5%85%B3%E5%8F%82%E8%80%83/" title="Diffusion相关参考">Diffusion相关参考</a><time datetime="2023-06-03T09:25:27.000Z" title="发表于 2023-06-03 17:25:27">2023-06-03</time></div></div></div></div><div class="card-widget card-categories"><div class="item-headline">
<i class="fas fa-folder-open"></i>
<span>分类</span>
</div>
<ul class="card-category-list" id="aside-cat-list">
<li class="card-category-list-item "><a class="card-category-list-link" href="/categories/%E5%9B%BE%E5%83%8F%E5%88%86%E7%B1%BB/"><span class="card-category-list-name">图像分类</span><span class="card-category-list-count">1</span></a><ul class="card-category-list child"><li class="card-category-list-item "><a class="card-category-list-link" href="/categories/%E5%9B%BE%E5%83%8F%E5%88%86%E7%B1%BB/%E8%BD%BB%E9%87%8F%E5%8C%96%E7%BD%91%E7%BB%9C/"><span class="card-category-list-name">轻量化网络</span><span class="card-category-list-count">1</span></a></li></ul></li>
</ul></div><div class="card-widget card-tags"><div class="item-headline"><i class="fas fa-tags"></i><span>标签</span></div><div class="card-tag-cloud"><a href="/tags/DDPM/" style="font-size: 1.2em; color: #999da3">DDPM</a> <a href="/tags/%E5%9F%BA%E9%87%91/" style="font-size: 1.1em; color: #999">基金</a> <a href="/tags/%E5%AD%A6%E4%B9%A0/" style="font-size: 1.5em; color: #99a9bf">学习</a> <a href="/tags/%E6%9C%BA%E5%99%A8%E5%AD%A6%E4%B9%A0/" style="font-size: 1.2em; color: #999da3">机器学习</a> <a href="/tags/%E6%B7%B1%E5%BA%A6%E5%AD%A6%E4%B9%A0/" style="font-size: 1.4em; color: #99a5b6">深度学习</a> <a href="/tags/%E7%A5%9E%E7%BB%8F%E7%BD%91%E7%BB%9C/" style="font-size: 1.1em; color: #999">神经网络</a> <a href="/tags/%E7%AE%97%E6%B3%95%E5%88%86%E6%9E%90%E4%B8%8E%E8%AE%BE%E8%AE%A1/" style="font-size: 1.3em; color: #99a1ac">算法分析与设计</a> <a href="/tags/%E8%82%A1%E7%A5%A8/" style="font-size: 1.1em; color: #999">股票</a> <a href="/tags/%E8%87%AA%E7%84%B6%E8%AF%AD%E8%A8%80%E5%A4%84%E7%90%86/" style="font-size: 1.1em; color: #999">自然语言处理</a> <a href="/tags/%E8%AE%A1%E7%AE%97%E6%9C%BA%E4%BD%93%E7%B3%BB%E7%BB%93%E6%9E%84/" style="font-size: 1.1em; color: #999">计算机体系结构</a></div></div><div class="card-widget card-archives"><div class="item-headline"><i class="fas fa-archive"></i><span>归档</span></div><ul class="card-archive-list"><li class="card-archive-list-item"><a class="card-archive-list-link" href="/archives/2023/09/"><span class="card-archive-list-date">九月 2023</span><span class="card-archive-list-count">1</span></a></li><li class="card-archive-list-item"><a class="card-archive-list-link" href="/archives/2023/08/"><span class="card-archive-list-date">八月 2023</span><span class="card-archive-list-count">3</span></a></li><li class="card-archive-list-item"><a class="card-archive-list-link" href="/archives/2023/06/"><span class="card-archive-list-date">六月 2023</span><span class="card-archive-list-count">1</span></a></li><li class="card-archive-list-item"><a class="card-archive-list-link" href="/archives/2022/11/"><span class="card-archive-list-date">十一月 2022</span><span class="card-archive-list-count">2</span></a></li><li class="card-archive-list-item"><a class="card-archive-list-link" href="/archives/2022/10/"><span class="card-archive-list-date">十月 2022</span><span class="card-archive-list-count">8</span></a></li><li class="card-archive-list-item"><a class="card-archive-list-link" href="/archives/2022/09/"><span class="card-archive-list-date">九月 2022</span><span class="card-archive-list-count">1</span></a></li><li class="card-archive-list-item"><a class="card-archive-list-link" href="/archives/2022/08/"><span class="card-archive-list-date">八月 2022</span><span class="card-archive-list-count">1</span></a></li></ul></div><div class="card-widget card-webinfo"><div class="item-headline"><i class="fas fa-chart-line"></i><span>网站资讯</span></div><div class="webinfo"><div class="webinfo-item"><div class="item-name">文章数目 :</div><div class="item-count">17</div></div><div class="webinfo-item"><div class="item-name">已运行时间 :</div><div class="item-count" id="runtimeshow" data-publishDate="2022-08-15T06:00:00.000Z"><i class="fa-solid fa-spinner fa-spin"></i></div></div><div class="webinfo-item"><div class="item-name">本站访客数 :</div><div class="item-count" id="busuanzi_value_site_uv"><i class="fa-solid fa-spinner fa-spin"></i></div></div><div class="webinfo-item"><div class="item-name">本站总访问量 :</div><div class="item-count" id="busuanzi_value_site_pv"><i class="fa-solid fa-spinner fa-spin"></i></div></div><div class="webinfo-item"><div class="item-name">最后更新时间 :</div><div class="item-count" id="last-push-date" data-lastPushDate="2023-09-07T05:04:12.635Z"><i class="fa-solid fa-spinner fa-spin"></i></div></div></div></div></div></div></main><footer id="footer" style="background-image: url('/photo/foot.jpg')"><div id="footer-wrap"><div class="copyright">©2022 - 2023 By 张恩硕</div><div class="framework-info"><span>框架 </span><a target="_blank" rel="noopener" href="https://hexo.io">Hexo</a><span class="footer-separator">|</span><span>主题 </span><a target="_blank" rel="noopener" href="https://github.com/jerryc127/hexo-theme-butterfly">Butterfly</a></div><div class="footer_custom_text">鲁ICP备2022014577号-1</div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="darkmode" type="button" title="浅色和深色模式转换"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="单栏和双栏切换"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside_config" type="button" title="设置"><i class="fas fa-cog fa-spin"></i></button><button id="go-up" type="button" title="回到顶部"><i class="fas fa-arrow-up"></i></button></div></div><div id="local-search"><div class="search-dialog"><nav class="search-nav"><span class="search-dialog-title">搜索</span><span id="loading-status"></span><button class="search-close-button"><i class="fas fa-times"></i></button></nav><div class="is-center" id="loading-database"><i class="fas fa-spinner fa-pulse"></i><span> 数据库加载中</span></div><div class="search-wrap"><div id="local-search-input"><div class="local-search-box"><input class="local-search-box--input" placeholder="搜索文章" type="text"/></div></div><hr/><div id="local-search-results"></div></div></div><div id="search-mask"></div></div><div><script src="/js/utils.js"></script><script src="/js/main.js"></script><script src="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox.umd.min.js"></script><script src="/js/search/local-search.js"></script><div class="js-pjax"><script>function subtitleType () {
if (true) {
window.typed = new Typed("#subtitle", {
strings: ["Inner Peace","内心平静"],
startDelay: 300,
typeSpeed: 150,
loop: true,
backSpeed: 50
})
} else {
document.getElementById("subtitle").innerHTML = 'Inner Peace'
}
}
if (true) {
if (typeof Typed === 'function') {
subtitleType()
} else {
getScript('https://cdn.jsdelivr.net/npm/typed.js/lib/typed.min.js').then(subtitleType)
}
} else {
subtitleType()
}</script></div><script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script></div></body></html>