赞
踩
代码是结合代尔夫特理工大学的deep learning这门课的大作业来讲的。整体上一个分类的框架,但是用了srm噪声提取器,这个后来被RGBN作为双流fasterrcnn中的噪声流支路引用,srm在篡改检测中是比较常见的人工设计的算子。这篇文章的代码我跑过,本身还是有效果的,其中它里面数据预训练的分patch操作也在后续中被引进,但说实话,这种简单的网络设计其实跑不过不做任何设计的分类模型,比如res2net。篡改检测常用的基本都是自然场景数据集,比如CASIA1/2,中科院出的数据集,还有BHSig60,COVERAGE,NC16等,这些数据集的篡改手段包括了resize,压缩啊这些操作,其实和常规的文档类的数据集的ps还是有差别的,我们常说自然场景和文档篡改的差别挺大的,文档主要还是以ps这种操作为主。
上面这张图是网络设计,核心是第一组蓝色的cnn操作,这里面融合例如srm滤波器。srm滤波器最早出自于Rich models for steganalysis of digital images中,是Steganalysis Rich Model的缩写,富隐写分析模型,篡改操作会带来十分尖锐的边缘,尤其是拼接操作,会被高通滤波器很明显的体现出来。文章在cnn的结构里对第一层卷积的权重使用30个在srm中九三残差图的基本高通滤波器进行初始化,这些基础的滤波器对应了7个srm残差类别,分布如下:
个数 | 滤波器类别 |
---|---|
8 | 1st |
4 | 2nd |
8 | 3rd |
1 | SQUARE3x3 |
4 | EDGE3x3 |
1 | SQUARE5x5 |
4 | EDGE3x3 |
- from typing import Dict
-
- import numpy as np
- from torch import Tensor, stack
-
-
- def get_filters():
- """
- Function that return the required high pass SRM filters for the first convolutional layer of our implementation
- :return: A pytorch Tensor containing the 30x3x5x5 filter tensor with type
- [number_of_filters, input_channels, height, width]
- """
- filters: Dict[str, Tensor] = {}
-
- # 1st Order
- filters["1O1"] = Tensor(np.array([[0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, -1, 1, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]]))
- filters["1O2"] = Tensor(np.rot90(filters["1O1"]).copy())
- filters["1O3"] = Tensor(np.rot90(filters["1O2"]).copy())
- filters["1O4"] = Tensor(np.rot90(filters["1O3"]).copy())
- filters["1O5"] = Tensor(np.array([[0, 0, 0, 0, 0], [0, 0, 0, 1, 0], [0, 0, -1, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]]))
- filters["1O6"] = Tensor(np.rot90(filters["1O5"]).copy())
- filters["1O7"] = Tensor(np.rot90(filters["1O6"]).copy())
- filters["1O8"] = Tensor(np.rot90(filters["1O7"]).copy())
-
- # 2nd Order
- filters["2O1"] = Tensor(np.array([[0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 1, -2, 1, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]]))
- filters["2O2"] = Tensor(np.rot90(filters["2O1"]).copy())
- filters["2O3"] = Tensor(np.array([[0, 0, 0, 0, 0], [0, 1, 0, 0, 0], [0, 0, -2, 0, 0], [0, 0, 0, 1, 0], [0, 0, 0, 0, 0]]))
- filters["2O4"] = Tensor(np.rot90(filters["2O3"]).copy())
-
- # 3rd Order
- filters["3O1"] = Tensor(np.array([[0, 0, 0, 0, 0], [0, 0, 1, 0, 0], [0, 1, -3, 1, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]]))
- filters["3O2"] = Tensor(np.rot90(filters["3O1"]).copy())
- filters["3O3"] = Tensor(np.rot90(filters["3O2"]).copy())
- filters["3O4"] = Tensor(np.rot90(filters["3O3"]).copy())
- filters["3O5"] = Tensor(np.array([[0, 0, 0, 0, 0], [0, 1, 0, 1, 0], [0, 0, -3, 0, 0], [0, 1, 0, 0, 0], [0, 0, 0, 0, 0]]))
- filters["3O6"] = Tensor(np.rot90(filters["3O5"]).copy())
- filters["3O7"] = Tensor(np.rot90(filters["3O6"]).copy())
- filters["3O8"] = Tensor(np.rot90(filters["3O7"]).copy())
-
- # 3x3 SQUARE
- filters["3x3S"] = Tensor(np.array([[0, 0, 0, 0, 0], [0, -1, 2, -1, 0], [0, 2, -4, 2, 0], [0, -1, 2, -1, 0], [0, 0, 0, 0, 0]]))
-
- # 3x3 EDGE
- filters["3x3E1"] = Tensor(np.array([[0, 0, 0, 0, 0], [0, -1, 2, -1, 0], [0, 2, -4, 2, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]]))
- filters["3x3E2"] = Tensor(np.rot90(filters["3x3E1"]).copy())
- filters["3x3E3"] = Tensor(np.rot90(filters["3x3E2"]).copy())
- filters["3x3E4"] = Tensor(np.rot90(filters["3x3E3"]).copy())
-
- # 5X5 EDGE
- filters["5x5E1"] = Tensor(np.array([[-1, 2, -2, 2, -1], [2, -6, 8, -6, 2], [-2, 8, -12, 8, -2], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]]))
- filters["5x5E2"] = Tensor(np.rot90(filters["5x5E1"]).copy())
- filters["5x5E3"] = Tensor(np.rot90(filters["5x5E2"]).copy())
- filters["5x5E4"] = Tensor(np.rot90(filters["5x5E3"]).copy())
-
- # 5x5 SQUARE
- filters["5x5S"] = Tensor(np.array([[-1, 2, -2, 2, -1], [2, -6, 8, -6, 2], [-2, 8, -12, 8, -2], [2, -6, 8, -6, 2], [-1, 2, -2, 2, -1]]))
-
- return vectorize_filters(filters)
-
-
- def vectorize_filters(filters: dict):
- """
- Function that takes as input the 30x5x5 different SRM high pass filters and creates the 30x3x5x5 tensor with the
- following permutations 声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/羊村懒王/article/detail/414982推荐阅读
相关标签
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。