Eigen D., Puhrsch C. and Fergus R. Depth Map Prediction from a Single Image using a Multi-Scale Deep Network. NIPS 2014.

看这篇文章单纯是为了看一看这个scale-invariant error.

主要内容

我们时常通过平方误差来衡量两个图片的差异, 但是这个损失是很依赖与scale的.

比如, 有两个图片\(\bm{x}, \bm{x}'\), 则其误差为

\[\|\bm{x} - \bm{x}'\|_2^2 = \sum_{i=1}^n (\bm{x}_i - \bm{x}_i')^2,
\]

倘若此时\(x\)的每一个元素都增加了\(c\), 则变成了

\[\|\bm{x} + c - \bm{x}'\|_2^2,
\]

这个实际不是非常友好的, 我们是希望这个损失最好是Scale-Invariant的, 所以我们在损失的部分加入一个值

\[\| \bm{x} - \bm{x}' + \alpha \|_2^2,
\]

注意, 这里的\(\bm{x}\)可以理解为\(\bm{x} + c\), 那么选择一个怎样的\(\alpha\)能够使得上述的误差最小呢(关于特定的\(\bm{x}, \bm{x}'\)).

\[2(\bm{x} - \bm{x}' + \alpha)^T \bm{1} = 0 \Rightarrow
\alpha = \frac{1}{n} (\bm{x}'- \bm{x})^T \bm{1} = \frac{1}{n}\sum_{i=1}^n (x_i' - x_i).
\]

故, 最后的损失函数是

\[\| \bm{x} - \bm{x}' + \frac{1}{n}(\bm{x} - \bm{x}')^T \bm{1}\|_2^2 = \|\bm{x} - \bm{x}'\|_2^2 - \frac{1}{n} ((\bm{x} - \bm{x}')^T \bm{1})^2.
\]

注: 如果我们将像素置于对数空间, 即考虑\(\log \bm{x}\), 则上述实际上考虑的\(c \cdot \bm{x}\) 的scale.

代码

import torch
import torch.nn as nn
import torch.nn.functional as F def scale_invariant_loss(outs: torch.Tensor, targets: torch.Tensor, reduction="mean"):
"""
outs: N ( x C) x H x W
targets: N ( x C) x H x W
reduction: ...
"""
outs = outs.flatten(start_dim=1)
targets = targets.flatten(start_dim=1)
alpha = (targets - outs).mean(dim=1, keepdim=True)
return F.mse_loss(outs + alpha, targets, reduction=reduction)

Scale-Invariant Error的更多相关文章

  1. Computer Vision_33_SIFT:TILDE: A Temporally Invariant Learned DEtector——2014

    此部分是计算机视觉部分,主要侧重在底层特征提取,视频分析,跟踪,目标检测和识别方面等方面.对于自己不太熟悉的领域比如摄像机标定和立体视觉,仅仅列出上google上引用次数比较多的文献.有一些刚刚出版的 ...

  2. Image Processing and Computer Vision_Review:Local Invariant Feature Detectors: A Survey——2007.11

    翻译 局部不变特征探测器:一项调查 摘要 -在本次调查中,我们概述了不变兴趣点探测器,它们如何随着时间的推移而发展,它们如何工作,以及它们各自的优点和缺点.我们首先定义理想局部特征检测器的属性.接下来 ...

  3. 【尺度不变性】An Analysis of Scale Invariance in Object Detection – SNIP 论文解读

    前言 本来想按照惯例来一个overview的,结果看到1篇十分不错而且详细的介绍,因此copy过来,自己在前面大体总结一下论文,细节不做赘述,引用文章讲得很详细,另外这篇paper引用十分详细,如果做 ...

  4. {ICIP2014}{收录论文列表}

    This article come from HEREARS-L1: Learning Tuesday 10:30–12:30; Oral Session; Room: Leonard de Vinc ...

  5. Computer Graphics Research Software

    Computer Graphics Research Software Helping you avoid re-inventing the wheel since 2009! Last update ...

  6. 卷积神经网络CNN

    卷积神经网络,在图像识别和自然语言处理中有很大的作用,讲cnn的中文博客也不少,但是个人感觉说的脉络清晰清晰易懂的不多. 无意中看到这篇博客,写的很好,图文并茂.建议英文好的直接去看原文.英文不好的就 ...

  7. Introduction to debugging neural networks

    http://russellsstewart.com/notes/0.html The following advice is targeted at beginners to neural netw ...

  8. [转]An Intuitive Explanation of Convolutional Neural Networks

    An Intuitive Explanation of Convolutional Neural Networks https://ujjwalkarn.me/2016/08/11/intuitive ...

  9. SIFT(Scale-invariant feature transform) & HOG(histogram of oriented gradients)

    SIFT :scale invariant feature transform HOG:histogram of oriented gradients 这两种方法都是基于图像中梯度的方向直方图的特征提 ...

  10. 记录Debug神经网络的方法

    debugNNIntroduction to debugging neural networksThe following advice is targeted at beginners to neu ...

随机推荐

  1. MapReduce02 序列化

    目录 MapReduce 序列化 概述 自定义序列化 常用数据序列化类型 int与IntWritable转化 Text与String 序列化读写方法 自定义bean对象实现序列化接口(Writable ...

  2. 12-gauge/bore shotgun

    12-gauge/bore shotgun不是弹夹(magazine)容量为12发的霰(xian)弹枪.[LDOCE]gauge - a measurement of the width or thi ...

  3. A Child's History of England.6

    It was a British Prince named Vortigern who took this resolution, and who made a treaty of friendshi ...

  4. day12 查找文件

    day12 查找文件 find命令:查找文件 find命令:在linux系统中,按照我们的要求去查询文件. 格式: find [查询的路径] [匹配模式] [匹配规则] 匹配模式: -name : 按 ...

  5. hadoop-uber作业模式

    如果作业很小,就选择和自己在同一个JVM上运行任务,与在一个节点上顺序运行这些任务相比,当application master 判断在新的容器中的分配和运行任务的开销大于并行运行它们的开销时,就会发生 ...

  6. Shell学习(八)——dd命令

    一.dd命令的解释 dd:用指定大小的块拷贝一个文件,并在拷贝的同时进行指定的转换. 注意:指定数字的地方若以下列字符结尾,则乘以相应的数字:b=512:c=1:k=1024:w=2 参数注释: 1. ...

  7. When do we pass arguments by reference or pointer?

    在C++中,基于以下如下我们通过以引用reference的形式传递变量. (1)To modify local variables of the caller function A reference ...

  8. 数据源(Data Source

    数据源(Data Source)顾名思义,数据的来源,是提供某种所需要数据的器件或原始媒体.在数据源中存储了所有建立数据库连接的信息.就像通过指定文件名称可以在文件系统中找到文件一样,通过提供正确的数 ...

  9. 【Services】【Web】【Nginx】静态下载页面的安装与配置

    1. 拓扑 F5有自动探活机制,如果一台机器宕机,请求会转发到另外一台,省去了IPVS漂移的麻烦 F5使用轮询算法,向两台服务器转发请求,实现了负载均衡 2. 版本: 2.1 服务器版本:RHEL7. ...

  10. GET传参数方式

    controller:/getDetail/{id} /getDetail?id1234567 /getDetail?id=id1234567