惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

雷峰网
雷峰网
T
The Blog of Author Tim Ferriss
Scott Helme
Scott Helme
P
Proofpoint News Feed
D
Docker
The Hacker News
The Hacker News
云风的 BLOG
云风的 BLOG
Vercel News
Vercel News
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Project Zero
Project Zero
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
GbyAI
GbyAI
Jina AI
Jina AI
P
Proofpoint News Feed
P
Privacy & Cybersecurity Law Blog
T
Threat Research - Cisco Blogs
C
CERT Recently Published Vulnerability Notes
博客园 - 叶小钗
U
Unit 42
博客园_首页
Apple Machine Learning Research
Apple Machine Learning Research
Latest news
Latest news
T
The Exploit Database - CXSecurity.com
博客园 - 三生石上(FineUI控件)
博客园 - 聂微东
T
Threatpost
V
Vulnerabilities – Threatpost
C
Cisco Blogs
Spread Privacy
Spread Privacy
Cisco Talos Blog
Cisco Talos Blog
C
Cyber Attacks, Cyber Crime and Cyber Security
V
Visual Studio Blog
G
GRAHAM CLULEY
Microsoft Azure Blog
Microsoft Azure Blog
博客园 - Franky
G
Google Developers Blog
Know Your Adversary
Know Your Adversary
F
Fortinet All Blogs
H
Hackread – Cybersecurity News, Data Breaches, AI and More
NISL@THU
NISL@THU
N
Netflix TechBlog - Medium
Y
Y Combinator Blog
L
Lohrmann on Cybersecurity
C
CXSECURITY Database RSS Feed - CXSecurity.com
Recent Announcements
Recent Announcements
量子位
S
Schneier on Security
I
Intezer
酷 壳 – CoolShell
酷 壳 – CoolShell
D
Darknet – Hacking Tools, Hacker News & Cyber Security

编程与诗|飒白的个人博客|飒白的闲话仓库|一位主播和程序员的奇妙组合体

侯捷c++笔记:c++泛型与高级用法 侯捷c++笔记:c++面向对象的指针类 侯捷c++笔记:c++面向对象的无指针类 03《穷查理宝典》 查理·芒格丨读书笔记 02《穷爸爸富爸爸》 罗伯特·清崎丨读书笔记 01《影响力》罗伯特・西奥迪尼丨读书笔记 基于结构光投影三维重建:格雷码编码与解码 三维重建论文笔记 DeMoN:Depth and Motion Network for Learning Monocular Stereo 三维扫描系列 点云绪论 修改DCNN使其输入从无监督变为有监督模型 茫茫摄影路:好照片的基本三要素 pytorch学习日记:创建Tensor pytorch学习日记:张量数据类型 研究生涯005 利用蒙特卡洛方法实现21点问题的最优解 研究生涯004 基于深度学习的水质图像分类 研究生涯003 基于最近邻法手写数字识别设计 研究生涯002 汽车模糊推理系统实验 研究生涯001 浅析机器视觉在医疗影像处理中的应用 人工智能问答NO.8 决策树与随机森林
给CNN添加TVloss的随记
飒白 · 2021-03-31 · via 编程与诗|飒白的个人博客|飒白的闲话仓库|一位主播和程序员的奇妙组合体

接了导师的活,要求把TVloss加入到已经写好的DnCNN里,下面是tvloss代码:

class TVLoss(nn.Module):
    def __init__(self, TVLoss_weight=1):
        super(TVLoss, self).__init__()
        self.TVLoss_weight = TVLoss_weight


    def forward(self, x):
        batch_size = x.size()[0]
        h_x = x.size()[2]
        w_x = x.size()[3]
        count_h = self._tensor_size(x[:, :, 1:, :])  # 算出总共求了多少次差
        count_w = self._tensor_size(x[:, :, :, 1:])
        h_tv = torch.pow((x[:, :, 1:, :] - x[:, :, :h_x - 1, :]), 2).sum()
        # x[:,:,1:,:]-x[:,:,:h_x-1,:]就是对原图进行错位,分成两张像素位置差1的图片,第一张图片
        # 从像素点1开始(原图从0开始),到最后一个像素点,第二张图片从像素点0开始,到倒数第二个
        # 像素点,这样就实现了对原图进行错位,分成两张图的操作,做差之后就是原图中每个像素点与相
        # 邻的下一个像素点的差。
        w_tv = torch.pow((x[:, :, :, 1:] - x[:, :, :, :w_x - 1]), 2).sum()
        return self.TVLoss_weight * 2 * (h_tv / count_h + w_tv / count_w) / batch_size


    def _tensor_size(self, t):
        return t.size()[1] * t.size()[2] * t.size()[3]

可以看出返回的是一个数,使用方法为:

addition = TVLoss() # 初始化
loss = addition(model(batch_y)) # 输入为经过模型得出的fakex
loss = Variable(loss, requires_grad=True)

实验——TV Loss解决over fitting的问题,tvloss在深度学习里不可以单独的作为loss,需要配合其他loss使用,在这里我们引入sum_squared_error 误差平方和:

criterion = sum_squared_error()
loss2 = criterion(model(batch_y), batch_y - batch_x)
loss = (loss * args.tvlosspr) + loss2 # args.tvlosspr为事先定义好的tvloss参数

如上,就把TVloss嵌入进程序里了(好不好用我也不知道)

如果不好用的话我会回来改一下,如果过去一个月了这篇文章还没有改那就证明这个方法成功了(至少没失败)


2021年4月21日更新

发现更为简便的加loss方法


my = model(batch_y)
loss2 = criterion(my, batch_y - batch_x)
tvloss = 1e-6 * (torch.sum(torch.abs(my[:, :, :, :-1] - my[:, :, :, 1:])) + torch.sum(torch.abs(my[:, :, :-1, :] - my[:, :, 1:, :]))) #1e-6为参数
loss =   tvloss + loss2 

这个方法我也没试验过

等有时间再实验吧

EOF