From 1a7e9e208ea9ae384e4918dc98788bb1a4200a19 Mon Sep 17 00:00:00 2001 From: Kkkae <1536803768@qq.com> Date: Tue, 30 Nov 2021 12:04:06 +0800 Subject: [PATCH] =?UTF-8?q?MindSpore=E6=A1=86=E6=9E=B6=E5=A4=8D=E7=8E=B0De?= =?UTF-8?q?epSteganography,=20=E5=B9=B6=E4=BD=BF=E7=94=A8=E5=85=89?= =?UTF-8?q?=E5=AD=A6=E9=81=A5=E6=84=9F=E5=9B=BE=E5=83=8F=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E9=9B=86FAIR1M=E8=BF=9B=E8=A1=8C=E8=AE=AD=E7=BB=83=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../README.md | 11 + .../analyze_fail.dat | 388 ++++++++++++++++++ .../config/Config.yaml | 30 ++ .../config/__init__.py | 5 + .../config/yamlparser.py | 34 ++ .../data/__init__.py | 5 + .../data/analyze_fail.dat | 229 +++++++++++ .../data/calculate_mean_std.py | 58 +++ .../data/create_datasets.py | 125 ++++++ .../data/crop_image.py | 45 ++ .../data/random_select_image.py | 145 +++++++ .../data/rename_images.py | 33 ++ .../models/__init__.py | 5 + .../models/networks.py | 256 ++++++++++++ .../test.py | 145 +++++++ .../train.py | 182 ++++++++ 16 files changed, 1696 insertions(+) create mode 100644 code/2021_autumn/2021202130071-Mindspore-DeepSteganography/README.md create mode 100644 code/2021_autumn/2021202130071-Mindspore-DeepSteganography/analyze_fail.dat create mode 100644 code/2021_autumn/2021202130071-Mindspore-DeepSteganography/config/Config.yaml create mode 100644 code/2021_autumn/2021202130071-Mindspore-DeepSteganography/config/__init__.py create mode 100644 code/2021_autumn/2021202130071-Mindspore-DeepSteganography/config/yamlparser.py create mode 100644 code/2021_autumn/2021202130071-Mindspore-DeepSteganography/data/__init__.py create mode 100644 code/2021_autumn/2021202130071-Mindspore-DeepSteganography/data/analyze_fail.dat create mode 100644 code/2021_autumn/2021202130071-Mindspore-DeepSteganography/data/calculate_mean_std.py create mode 100644 code/2021_autumn/2021202130071-Mindspore-DeepSteganography/data/create_datasets.py create mode 100644 code/2021_autumn/2021202130071-Mindspore-DeepSteganography/data/crop_image.py create mode 100644 code/2021_autumn/2021202130071-Mindspore-DeepSteganography/data/random_select_image.py create mode 100644 code/2021_autumn/2021202130071-Mindspore-DeepSteganography/data/rename_images.py create mode 100644 code/2021_autumn/2021202130071-Mindspore-DeepSteganography/models/__init__.py create mode 100644 code/2021_autumn/2021202130071-Mindspore-DeepSteganography/models/networks.py create mode 100644 code/2021_autumn/2021202130071-Mindspore-DeepSteganography/test.py create mode 100644 code/2021_autumn/2021202130071-Mindspore-DeepSteganography/train.py diff --git a/code/2021_autumn/2021202130071-Mindspore-DeepSteganography/README.md b/code/2021_autumn/2021202130071-Mindspore-DeepSteganography/README.md new file mode 100644 index 0000000..9df378a --- /dev/null +++ b/code/2021_autumn/2021202130071-Mindspore-DeepSteganography/README.md @@ -0,0 +1,11 @@ +# 神经网络与深度学习课程 2021秋季 +## 课程大作业:使用Mindspore框架复现DeepSteganographymox +### 学生: 饶可奕(2021202130071) +### 提交时间:2021年11月30日 + +### 内容申明 +- 复现Bujalu于2017年发表的基于深度学习的图像隐写术[1],简称DeepSteganography([1] Baluja S. Hiding images in plain sight: Deep steganography[J].Advances in Neural Information Processing Systems, 2017, 30: 2069-2079. +) +- 使用FAIR1M数据集[2],该数据集是ISPRS(国际摄影测量与遥感学会)提供的大规模数据集。包括3或者4通道的遥感光学图像,主要采集自高分卫星。在这个数据集中有15000 多幅遥感图像。每张图像的大小在 1000 × 1000到 10000 × 10000 像素之间,空间分辨率为 0.3 米-0.6米,辐射分辨率范围为0-255。(Xian Sun, Peijin Wang, Zhiyuan Yan, Feng Xu, Ruiping Wang, Wenhui Diao, Jin Chen, Jihao Li, Yingchao Feng, Tao Xu, Martin Weinmann, Stefan Hinz, Cheng Wang, and Kun Fu. Fair1m: A benchmark dataset for fine-grained object recognition in high-resolution remote sensing imagery, 2021. ) +- 代码由本人自主写出,参考了华为Mindspore官网的各类指南和API文档(如:https://www.mindspore.cn/tutorial/training/zh-CN/r1.2/quick_start/quick_start.html ) +- 因为代金券发放的晚,所以先使用Linux系统1080显卡进行GPU训练。(但是,后面也没有改成使用华为云ModelArts训练。) diff --git a/code/2021_autumn/2021202130071-Mindspore-DeepSteganography/analyze_fail.dat b/code/2021_autumn/2021202130071-Mindspore-DeepSteganography/analyze_fail.dat new file mode 100644 index 0000000..d528bfc --- /dev/null +++ b/code/2021_autumn/2021202130071-Mindspore-DeepSteganography/analyze_fail.dat @@ -0,0 +1,388 @@ +# [No.1] construct_wrapper.25 +# In file C:\ProgramData\Anaconda3\envs\mindspore_py37_CPU\lib\site-packages\mindspore\nn\wrap\cell_wrapper.py(376)/ def construct(self, *inputs):/ +funcgraph fg_25( + %para1 : Tensor(F32)[2, 3, 224, 224] # inputs0 + , %para2 : Tensor(F32)[2, 3, 224, 224] # inputs1 + , %para3 : Ref[Tensor(I32)][] # step + , %para4 : Ref[Tensor(F32)][50, 3, 3, 3] # m1.initialP3.0.weight + , %para5 : Ref[Tensor(F32)][50, 50, 3, 3] # m1.initialP3.2.weight + , %para6 : Ref[Tensor(F32)][50, 50, 3, 3] # m1.initialP3.4.weight + , %para7 : Ref[Tensor(F32)][50, 50, 3, 3] # m1.initialP3.6.weight + , %para8 : Ref[Tensor(F32)][50, 3, 4, 4] # m1.initialP4.0.weight + , %para9 : Ref[Tensor(F32)][50, 50, 4, 4] # m1.initialP4.2.weight + , %para10 : Ref[Tensor(F32)][50, 50, 4, 4] # m1.initialP4.4.weight + , %para11 : Ref[Tensor(F32)][50, 50, 4, 4] # m1.initialP4.6.weight + , %para12 : Ref[Tensor(F32)][50, 3, 5, 5] # m1.initialP5.0.weight + , %para13 : Ref[Tensor(F32)][50, 50, 5, 5] # m1.initialP5.2.weight + , %para14 : Ref[Tensor(F32)][50, 50, 5, 5] # m1.initialP5.4.weight + , %para15 : Ref[Tensor(F32)][50, 50, 5, 5] # m1.initialP5.6.weight + , %para16 : Ref[Tensor(F32)][50, 150, 3, 3] # m1.finalP3.0.weight + , %para17 : Ref[Tensor(F32)][50, 150, 4, 4] # m1.finalP4.0.weight + , %para18 : Ref[Tensor(F32)][50, 50, 4, 4] # m1.finalP4.2.weight + , %para19 : Ref[Tensor(F32)][50, 150, 5, 5] # m1.finalP5.0.weight + , %para20 : Ref[Tensor(F32)][50, 153, 3, 3] # m2.initialH3.0.weight + , %para21 : Ref[Tensor(F32)][50, 50, 3, 3] # m2.initialH3.2.weight + , %para22 : Ref[Tensor(F32)][50, 50, 3, 3] # m2.initialH3.4.weight + , %para23 : Ref[Tensor(F32)][50, 50, 3, 3] # m2.initialH3.6.weight + , %para24 : Ref[Tensor(F32)][50, 153, 4, 4] # m2.initialH4.0.weight + , %para25 : Ref[Tensor(F32)][50, 50, 4, 4] # m2.initialH4.2.weight + , %para26 : Ref[Tensor(F32)][50, 50, 4, 4] # m2.initialH4.4.weight + , %para27 : Ref[Tensor(F32)][50, 50, 4, 4] # m2.initialH4.6.weight + , %para28 : Ref[Tensor(F32)][50, 153, 5, 5] # m2.initialH5.0.weight + , %para29 : Ref[Tensor(F32)][50, 50, 5, 5] # m2.initialH5.2.weight + , %para30 : Ref[Tensor(F32)][50, 50, 5, 5] # m2.initialH5.4.weight + , %para31 : Ref[Tensor(F32)][50, 50, 5, 5] # m2.initialH5.6.weight + , %para32 : Ref[Tensor(F32)][50, 150, 3, 3] # m2.finalH3.0.weight + , %para33 : Ref[Tensor(F32)][50, 150, 4, 4] # m2.finalH4.0.weight + , %para34 : Ref[Tensor(F32)][50, 50, 4, 4] # m2.finalH4.2.weight + , %para35 : Ref[Tensor(F32)][50, 150, 5, 5] # m2.finalH5.0.weight + , %para36 : Ref[Tensor(F32)][3, 150, 1, 1] # m2.finalH.0.weight + , %para37 : Ref[Tensor(F32)][50, 3, 3, 3] # m3.initialR3.0.weight + , %para38 : Ref[Tensor(F32)][50, 50, 3, 3] # m3.initialR3.2.weight + , %para39 : Ref[Tensor(F32)][50, 50, 3, 3] # m3.initialR3.4.weight + , %para40 : Ref[Tensor(F32)][50, 50, 3, 3] # m3.initialR3.6.weight + , %para41 : Ref[Tensor(F32)][50, 3, 4, 4] # m3.initialR4.0.weight + , %para42 : Ref[Tensor(F32)][50, 50, 4, 4] # m3.initialR4.2.weight + , %para43 : Ref[Tensor(F32)][50, 50, 4, 4] # m3.initialR4.4.weight + , %para44 : Ref[Tensor(F32)][50, 50, 4, 4] # m3.initialR4.6.weight + , %para45 : Ref[Tensor(F32)][50, 3, 5, 5] # m3.initialR5.0.weight + , %para46 : Ref[Tensor(F32)][50, 50, 5, 5] # m3.initialR5.2.weight + , %para47 : Ref[Tensor(F32)][50, 50, 5, 5] # m3.initialR5.4.weight + , %para48 : Ref[Tensor(F32)][50, 50, 5, 5] # m3.initialR5.6.weight + , %para49 : Ref[Tensor(F32)][50, 150, 3, 3] # m3.finalR3.0.weight + , %para50 : Ref[Tensor(F32)][50, 150, 4, 4] # m3.finalR4.0.weight + , %para51 : Ref[Tensor(F32)][50, 50, 4, 4] # m3.finalR4.2.weight + , %para52 : Ref[Tensor(F32)][50, 150, 5, 5] # m3.finalR5.0.weight + , %para53 : Ref[Tensor(F32)][3, 150, 1, 1] # m3.finalR.weight + , %para54 : Ref[Tensor(F32)][1] # beta1_power + , %para55 : Ref[Tensor(F32)][1] # beta2_power + , %para56 : Ref[Tensor(F32)][50, 3, 3, 3] # moment1.m1.initialP3.0.weight + , %para57 : Ref[Tensor(F32)][50, 50, 3, 3] # moment1.m1.initialP3.2.weight + , %para58 : Ref[Tensor(F32)][50, 50, 3, 3] # moment1.m1.initialP3.4.weight + , %para59 : Ref[Tensor(F32)][50, 50, 3, 3] # moment1.m1.initialP3.6.weight + , %para60 : Ref[Tensor(F32)][50, 3, 4, 4] # moment1.m1.initialP4.0.weight + , %para61 : Ref[Tensor(F32)][50, 50, 4, 4] # moment1.m1.initialP4.2.weight + , %para62 : Ref[Tensor(F32)][50, 50, 4, 4] # moment1.m1.initialP4.4.weight + , %para63 : Ref[Tensor(F32)][50, 50, 4, 4] # moment1.m1.initialP4.6.weight + , %para64 : Ref[Tensor(F32)][50, 3, 5, 5] # moment1.m1.initialP5.0.weight + , %para65 : Ref[Tensor(F32)][50, 50, 5, 5] # moment1.m1.initialP5.2.weight + , %para66 : Ref[Tensor(F32)][50, 50, 5, 5] # moment1.m1.initialP5.4.weight + , %para67 : Ref[Tensor(F32)][50, 50, 5, 5] # moment1.m1.initialP5.6.weight + , %para68 : Ref[Tensor(F32)][50, 150, 3, 3] # moment1.m1.finalP3.0.weight + , %para69 : Ref[Tensor(F32)][50, 150, 4, 4] # moment1.m1.finalP4.0.weight + , %para70 : Ref[Tensor(F32)][50, 50, 4, 4] # moment1.m1.finalP4.2.weight + , %para71 : Ref[Tensor(F32)][50, 150, 5, 5] # moment1.m1.finalP5.0.weight + , %para72 : Ref[Tensor(F32)][50, 153, 3, 3] # moment1.m2.initialH3.0.weight + , %para73 : Ref[Tensor(F32)][50, 50, 3, 3] # moment1.m2.initialH3.2.weight + , %para74 : Ref[Tensor(F32)][50, 50, 3, 3] # moment1.m2.initialH3.4.weight + , %para75 : Ref[Tensor(F32)][50, 50, 3, 3] # moment1.m2.initialH3.6.weight + , %para76 : Ref[Tensor(F32)][50, 153, 4, 4] # moment1.m2.initialH4.0.weight + , %para77 : Ref[Tensor(F32)][50, 50, 4, 4] # moment1.m2.initialH4.2.weight + , %para78 : Ref[Tensor(F32)][50, 50, 4, 4] # moment1.m2.initialH4.4.weight + , %para79 : Ref[Tensor(F32)][50, 50, 4, 4] # moment1.m2.initialH4.6.weight + , %para80 : Ref[Tensor(F32)][50, 153, 5, 5] # moment1.m2.initialH5.0.weight + , %para81 : Ref[Tensor(F32)][50, 50, 5, 5] # moment1.m2.initialH5.2.weight + , %para82 : Ref[Tensor(F32)][50, 50, 5, 5] # moment1.m2.initialH5.4.weight + , %para83 : Ref[Tensor(F32)][50, 50, 5, 5] # moment1.m2.initialH5.6.weight + , %para84 : Ref[Tensor(F32)][50, 150, 3, 3] # moment1.m2.finalH3.0.weight + , %para85 : Ref[Tensor(F32)][50, 150, 4, 4] # moment1.m2.finalH4.0.weight + , %para86 : Ref[Tensor(F32)][50, 50, 4, 4] # moment1.m2.finalH4.2.weight + , %para87 : Ref[Tensor(F32)][50, 150, 5, 5] # moment1.m2.finalH5.0.weight + , %para88 : Ref[Tensor(F32)][3, 150, 1, 1] # moment1.m2.finalH.0.weight + , %para89 : Ref[Tensor(F32)][50, 3, 3, 3] # moment1.m3.initialR3.0.weight + , %para90 : Ref[Tensor(F32)][50, 50, 3, 3] # moment1.m3.initialR3.2.weight + , %para91 : Ref[Tensor(F32)][50, 50, 3, 3] # moment1.m3.initialR3.4.weight + , %para92 : Ref[Tensor(F32)][50, 50, 3, 3] # moment1.m3.initialR3.6.weight + , %para93 : Ref[Tensor(F32)][50, 3, 4, 4] # moment1.m3.initialR4.0.weight + , %para94 : Ref[Tensor(F32)][50, 50, 4, 4] # moment1.m3.initialR4.2.weight + , %para95 : Ref[Tensor(F32)][50, 50, 4, 4] # moment1.m3.initialR4.4.weight + , %para96 : Ref[Tensor(F32)][50, 50, 4, 4] # moment1.m3.initialR4.6.weight + , %para97 : Ref[Tensor(F32)][50, 3, 5, 5] # moment1.m3.initialR5.0.weight + , %para98 : Ref[Tensor(F32)][50, 50, 5, 5] # moment1.m3.initialR5.2.weight + , %para99 : Ref[Tensor(F32)][50, 50, 5, 5] # moment1.m3.initialR5.4.weight + , %para100 : Ref[Tensor(F32)][50, 50, 5, 5] # moment1.m3.initialR5.6.weight + , %para101 : Ref[Tensor(F32)][50, 150, 3, 3] # moment1.m3.finalR3.0.weight + , %para102 : Ref[Tensor(F32)][50, 150, 4, 4] # moment1.m3.finalR4.0.weight + , %para103 : Ref[Tensor(F32)][50, 50, 4, 4] # moment1.m3.finalR4.2.weight + , %para104 : Ref[Tensor(F32)][50, 150, 5, 5] # moment1.m3.finalR5.0.weight + , %para105 : Ref[Tensor(F32)][3, 150, 1, 1] # moment1.m3.finalR.weight + , %para106 : Ref[Tensor(F32)][50, 3, 3, 3] # moment2.m1.initialP3.0.weight + , %para107 : Ref[Tensor(F32)][50, 50, 3, 3] # moment2.m1.initialP3.2.weight + , %para108 : Ref[Tensor(F32)][50, 50, 3, 3] # moment2.m1.initialP3.4.weight + , %para109 : Ref[Tensor(F32)][50, 50, 3, 3] # moment2.m1.initialP3.6.weight + , %para110 : Ref[Tensor(F32)][50, 3, 4, 4] # moment2.m1.initialP4.0.weight + , %para111 : Ref[Tensor(F32)][50, 50, 4, 4] # moment2.m1.initialP4.2.weight + , %para112 : Ref[Tensor(F32)][50, 50, 4, 4] # moment2.m1.initialP4.4.weight + , %para113 : Ref[Tensor(F32)][50, 50, 4, 4] # moment2.m1.initialP4.6.weight + , %para114 : Ref[Tensor(F32)][50, 3, 5, 5] # moment2.m1.initialP5.0.weight + , %para115 : Ref[Tensor(F32)][50, 50, 5, 5] # moment2.m1.initialP5.2.weight + , %para116 : Ref[Tensor(F32)][50, 50, 5, 5] # moment2.m1.initialP5.4.weight + , %para117 : Ref[Tensor(F32)][50, 50, 5, 5] # moment2.m1.initialP5.6.weight + , %para118 : Ref[Tensor(F32)][50, 150, 3, 3] # moment2.m1.finalP3.0.weight + , %para119 : Ref[Tensor(F32)][50, 150, 4, 4] # moment2.m1.finalP4.0.weight + , %para120 : Ref[Tensor(F32)][50, 50, 4, 4] # moment2.m1.finalP4.2.weight + , %para121 : Ref[Tensor(F32)][50, 150, 5, 5] # moment2.m1.finalP5.0.weight + , %para122 : Ref[Tensor(F32)][50, 153, 3, 3] # moment2.m2.initialH3.0.weight + , %para123 : Ref[Tensor(F32)][50, 50, 3, 3] # moment2.m2.initialH3.2.weight + , %para124 : Ref[Tensor(F32)][50, 50, 3, 3] # moment2.m2.initialH3.4.weight + , %para125 : Ref[Tensor(F32)][50, 50, 3, 3] # moment2.m2.initialH3.6.weight + , %para126 : Ref[Tensor(F32)][50, 153, 4, 4] # moment2.m2.initialH4.0.weight + , %para127 : Ref[Tensor(F32)][50, 50, 4, 4] # moment2.m2.initialH4.2.weight + , %para128 : Ref[Tensor(F32)][50, 50, 4, 4] # moment2.m2.initialH4.4.weight + , %para129 : Ref[Tensor(F32)][50, 50, 4, 4] # moment2.m2.initialH4.6.weight + , %para130 : Ref[Tensor(F32)][50, 153, 5, 5] # moment2.m2.initialH5.0.weight + , %para131 : Ref[Tensor(F32)][50, 50, 5, 5] # moment2.m2.initialH5.2.weight + , %para132 : Ref[Tensor(F32)][50, 50, 5, 5] # moment2.m2.initialH5.4.weight + , %para133 : Ref[Tensor(F32)][50, 50, 5, 5] # moment2.m2.initialH5.6.weight + , %para134 : Ref[Tensor(F32)][50, 150, 3, 3] # moment2.m2.finalH3.0.weight + , %para135 : Ref[Tensor(F32)][50, 150, 4, 4] # moment2.m2.finalH4.0.weight + , %para136 : Ref[Tensor(F32)][50, 50, 4, 4] # moment2.m2.finalH4.2.weight + , %para137 : Ref[Tensor(F32)][50, 150, 5, 5] # moment2.m2.finalH5.0.weight + , %para138 : Ref[Tensor(F32)][3, 150, 1, 1] # moment2.m2.finalH.0.weight + , %para139 : Ref[Tensor(F32)][50, 3, 3, 3] # moment2.m3.initialR3.0.weight + , %para140 : Ref[Tensor(F32)][50, 50, 3, 3] # moment2.m3.initialR3.2.weight + , %para141 : Ref[Tensor(F32)][50, 50, 3, 3] # moment2.m3.initialR3.4.weight + , %para142 : Ref[Tensor(F32)][50, 50, 3, 3] # moment2.m3.initialR3.6.weight + , %para143 : Ref[Tensor(F32)][50, 3, 4, 4] # moment2.m3.initialR4.0.weight + , %para144 : Ref[Tensor(F32)][50, 50, 4, 4] # moment2.m3.initialR4.2.weight + , %para145 : Ref[Tensor(F32)][50, 50, 4, 4] # moment2.m3.initialR4.4.weight + , %para146 : Ref[Tensor(F32)][50, 50, 4, 4] # moment2.m3.initialR4.6.weight + , %para147 : Ref[Tensor(F32)][50, 3, 5, 5] # moment2.m3.initialR5.0.weight + , %para148 : Ref[Tensor(F32)][50, 50, 5, 5] # moment2.m3.initialR5.2.weight + , %para149 : Ref[Tensor(F32)][50, 50, 5, 5] # moment2.m3.initialR5.4.weight + , %para150 : Ref[Tensor(F32)][50, 50, 5, 5] # moment2.m3.initialR5.6.weight + , %para151 : Ref[Tensor(F32)][50, 150, 3, 3] # moment2.m3.finalR3.0.weight + , %para152 : Ref[Tensor(F32)][50, 150, 4, 4] # moment2.m3.finalR4.0.weight + , %para153 : Ref[Tensor(F32)][50, 50, 4, 4] # moment2.m3.finalR4.2.weight + , %para154 : Ref[Tensor(F32)][50, 150, 5, 5] # moment2.m3.finalR5.0.weight + , %para155 : Ref[Tensor(F32)][3, 150, 1, 1] # moment2.m3.finalR.weight + , %para156 : Ref[Tensor(F32)][] # learning_rate + ) { + %1 : Tuple[Tensor(F32)*2] = Primitive::MakeTuple{prim_type=1}(%para1, %para2) #(Tensor(F32)[2, 3, 224, 224], Tensor(F32)[2, 3, 224, 224]) #scope: Default + # #[CNode]37 + +#------------------------> 0 + %2 = UnpackCall::unpack_call(FuncGraph::fg_38, %1) #(Func, Tuple[Tensor(F32)*2]) # fg_38=construct.38 #scope: Default + # In file C:\ProgramData\Anaconda3\envs\mindspore_py37_CPU\lib\site-packages\mindspore\nn\wrap\cell_wrapper.py(377)/ if self.freeze:/#[CNode]39 + Primitive::Return{prim_type=1}(%2) #(Undefined) #scope: Default + # In file C:\ProgramData\Anaconda3\envs\mindspore_py37_CPU\lib\site-packages\mindspore\nn\wrap\cell_wrapper.py(377)/ if self.freeze:/#[CNode]40 +} +# order: +# 1: construct_wrapper.25:[CNode]39{[0]: ValueNode unpack_call, [1]: ValueNode construct.38, [2]: [CNode]37} +# 2: construct_wrapper.25:[CNode]40{[0]: ValueNode Return, [1]: [CNode]39} + + +# [No.2] UnpackCall.26 +# +funcgraph fg_26( + %para157 : Func # 27 + , %para158 : Tuple[Tensor(F32)*2] # 28 + ) { + %1 : Tensor(F32)[2, 3, 224, 224] = Primitive::TupleGetItem{prim_type=1}(%para158, I64(0)) #(Tuple[Tensor(F32)*2], I64) #scope: Default + # #41 + %2 : Tensor(F32)[2, 3, 224, 224] = Primitive::TupleGetItem{prim_type=1}(%para158, I64(1)) #(Tuple[Tensor(F32)*2], I64) #scope: Default + # #42 + +#------------------------> 1 + %3 = %para157(%1, %2) #(Tensor(F32)[2, 3, 224, 224], Tensor(F32)[2, 3, 224, 224]) #scope: Default + # #43 + Primitive::Return{prim_type=1}(%3) #(Undefined) #scope: Default + # #44 +} +# order: +# 1: UnpackCall.26:43{[0]: 27, [1]: 41, [2]: 42} +# 2: UnpackCall.26:44{[0]: ValueNode Return, [1]: 43} + + +# [No.3] construct.29 +# In file C:\ProgramData\Anaconda3\envs\mindspore_py37_CPU\lib\site-packages\mindspore\nn\wrap\cell_wrapper.py(376)/ def construct(self, *inputs):/ +funcgraph fg_29[fg_25]( + %para159 : Tensor(F32)[2, 3, 224, 224] # inputs0 + , %para160 : Tensor(F32)[2, 3, 224, 224] # inputs1 + ) { + %1 : Bool = FuncGraph::fg_45(Bool(0)) #(Bool) # fg_45=bool_.45 #scope: Default + # In file C:\ProgramData\Anaconda3\envs\mindspore_py37_CPU\lib\site-packages\mindspore\nn\wrap\cell_wrapper.py(377)/ if self.freeze:/#46 + %2 : Func = Primitive::Switch{prim_type=1}(%1, FuncGraph::fg_47, FuncGraph::fg_30) #(Bool, Func, Func) # fg_47=✓construct.47, fg_30=✗construct.30 #scope: Default + # In file C:\ProgramData\Anaconda3\envs\mindspore_py37_CPU\lib\site-packages\mindspore\nn\wrap\cell_wrapper.py(377)/ if self.freeze:/#[CNode]48 + +#------------------------> 2 + %3 = %2() #scope: Default + # In file C:\ProgramData\Anaconda3\envs\mindspore_py37_CPU\lib\site-packages\mindspore\nn\wrap\cell_wrapper.py(377)/ if self.freeze:/#[CNode]49 + Primitive::Return{prim_type=1}(%3) #(Undefined) #scope: Default + # In file C:\ProgramData\Anaconda3\envs\mindspore_py37_CPU\lib\site-packages\mindspore\nn\wrap\cell_wrapper.py(377)/ if self.freeze:/#[CNode]50 +} +# order: +# 1: construct.29:46{[0]: ValueNode bool_.45, [1]: ValueNode false} +# 2: construct.29:[CNode]48{[0]: ValueNode Switch, [1]: 46, [2]: ValueNode ✓construct.47, [3]: ValueNode ✗construct.30} +# 3: construct.29:[CNode]49{[0]: [CNode]48} +# 4: construct.29:[CNode]50{[0]: ValueNode Return, [1]: [CNode]49} + + +# [No.4] ✗construct.30 +# In file C:\ProgramData\Anaconda3\envs\mindspore_py37_CPU\lib\site-packages\mindspore\nn\wrap\cell_wrapper.py(377)/ if self.freeze:/ +funcgraph fg_30[fg_29]( +) { + %1 : Bool = FuncGraph::fg_45(Bool(0)) #(Bool) # fg_45=bool_.45 #scope: Default + # In file C:\ProgramData\Anaconda3\envs\mindspore_py37_CPU\lib\site-packages\mindspore\nn\wrap\cell_wrapper.py(394)/ if self.use_grad_accumulation:/#51 + %2 : Func = Primitive::Switch{prim_type=1}(%1, FuncGraph::fg_52, FuncGraph::fg_31) #(Bool, Func, Func) # fg_52=✓✗construct.52, fg_31=✗✗construct.31 #scope: Default + # In file C:\ProgramData\Anaconda3\envs\mindspore_py37_CPU\lib\site-packages\mindspore\nn\wrap\cell_wrapper.py(394)/ if self.use_grad_accumulation:/#[CNode]53 + +#------------------------> 3 + %3 = %2() #scope: Default + # In file C:\ProgramData\Anaconda3\envs\mindspore_py37_CPU\lib\site-packages\mindspore\nn\wrap\cell_wrapper.py(394)/ if self.use_grad_accumulation:/#[CNode]54 + Primitive::Return{prim_type=1}(%3) #(Undefined) #scope: Default + # In file C:\ProgramData\Anaconda3\envs\mindspore_py37_CPU\lib\site-packages\mindspore\nn\wrap\cell_wrapper.py(394)/ if self.use_grad_accumulation:/#[CNode]55 +} +# order: +# 1: ✗construct.30:loss{[0]: ValueNode unpack_call, [1]: ValueNode construct.35, [2]: [CNode]56} +# 2: ✗construct.30:[CNode]57{[0]: ValueNode getattr, [1]: loss, [2]: ValueNode dtype} +# 3: ✗construct.30:[CNode]58{[0]: ValueNode getattr, [1]: loss, [2]: ValueNode shape} +# 4: ✗construct.30:sens{[0]: ValueNode S-Prim-Fill, [1]: [CNode]57, [2]: [CNode]58, [3]: ValueNode 1.000000} +# 5: ✗construct.30:[CNode]59{[0]: ValueNode S-Prim-MakeTuple, [1]: sens} +# 6: ✗construct.30:grads{[0]: ValueNode UnpackGraph, [1]: ValueNode construct.35, [2]: [CNode]56, [3]: [CNode]59} +# 7: ✗construct.30:grads{[0]: ValueNode S-Prim-grad, [1]: grads, [2]: [CNode]60} +# 8: ✗construct.30:grads{[0]: ValueNode unpack_call, [1]: grads, [2]: [CNode]56, [3]: [CNode]59} +# 9: ✗construct.30:grads{[0]: ValueNode S-Prim-identity, [1]: grads} +# 10: ✗construct.30:51{[0]: ValueNode bool_.45, [1]: ValueNode false} +# 11: ✗construct.30:[CNode]53{[0]: ValueNode Switch, [1]: 51, [2]: ValueNode ✓✗construct.52, [3]: ValueNode ✗✗construct.31} +# 12: ✗construct.30:[CNode]54{[0]: [CNode]53} +# 13: ✗construct.30:[CNode]55{[0]: ValueNode Return, [1]: [CNode]54} + + +# [No.5] ✗✗construct.31 +# In file C:\ProgramData\Anaconda3\envs\mindspore_py37_CPU\lib\site-packages\mindspore\nn\wrap\cell_wrapper.py(394)/ if self.use_grad_accumulation:/ +funcgraph fg_31[fg_30]( +) { + %1 : $(construct.29):Tuple[Tensor(F32)*2] = Primitive::MakeTuple{prim_type=1}(%para159, %para160) #(Tensor(F32)[2, 3, 224, 224], Tensor(F32)[2, 3, 224, 224]) #scope: Default + # In file C:\ProgramData\Anaconda3\envs\mindspore_py37_CPU\lib\site-packages\mindspore\nn\wrap\cell_wrapper.py(384)/ loss = self.freeze_nets[step](*inputs)/#[CNode]56 + +#------------------------> 4 + %2 = $(✗construct.30):UnpackCall::unpack_call(FuncGraph::fg_35, %1) #(Func, Tuple[Tensor(F32)*2]) # fg_35=construct.35 #scope: Default + # In file C:\ProgramData\Anaconda3\envs\mindspore_py37_CPU\lib\site-packages\mindspore\nn\wrap\cell_wrapper.py(390)/ loss = self.network(*inputs)/#loss + %3 = $(✗construct.30):Primitive::getattr{prim_type=1}(%2, "dtype") #(Undefined, Undefined) #scope: Default + # In file C:\ProgramData\Anaconda3\envs\mindspore_py37_CPU\lib\site-packages\mindspore\nn\wrap\cell_wrapper.py(391)/ sens = F.fill(loss.dtype, loss.shape, self.sens)/#[CNode]57 + %4 = $(✗construct.30):Primitive::getattr{prim_type=1}(%2, "shape") #(Undefined, Undefined) #scope: Default + # In file C:\ProgramData\Anaconda3\envs\mindspore_py37_CPU\lib\site-packages\mindspore\nn\wrap\cell_wrapper.py(391)/ sens = F.fill(loss.dtype, loss.shape, self.sens)/#[CNode]58 + %5 = $(✗construct.30):DoSignaturePrimitive::S-Prim-Fill{prim_type=1}(%3, %4, F32(1)) #(Undefined, Undefined, Undefined) #scope: Default + # In file C:\ProgramData\Anaconda3\envs\mindspore_py37_CPU\lib\site-packages\mindspore\nn\wrap\cell_wrapper.py(391)/ sens = F.fill(loss.dtype, loss.shape, self.sens)/#sens + %6 = $(✗construct.30):DoSignaturePrimitive::S-Prim-MakeTuple{prim_type=1}(%5) #(Undefined) #scope: Default + # In file C:\ProgramData\Anaconda3\envs\mindspore_py37_CPU\lib\site-packages\mindspore\nn\wrap\cell_wrapper.py(392)/ grads = self.grad(self.network, self.weights)(*inputs, sens)/#[CNode]59 + %7 = $(✗construct.30):UnpackGraphPrimitive::UnpackGraph{prim_type=1}(FuncGraph::fg_35, %1, %6) #(Undefined, Tuple[Tensor(F32)*2], Undefined) # fg_35=construct.35 #scope: Default + # In file C:\ProgramData\Anaconda3\envs\mindspore_py37_CPU\lib\site-packages\mindspore\nn\wrap\cell_wrapper.py(392)/ grads = self.grad(self.network, self.weights)(*inputs, sens)/#grads + %8 = $(construct.29):Primitive::MakeTuple{prim_type=1}(%para4, %para5, %para6, %para7, %para8, %para9, %para10, %para11, %para12, %para13, %para14, %para15, %para16, %para17, %para18, %para19, %para20, %para21, %para22, %para23, %para24, %para25, %para26, %para27, %para28, %para29, %para30, %para31, %para32, %para33, %para34, %para35, %para36, %para37, %para38, %para39, %para40, %para41, %para42, %para43, %para44, %para45, %para46, %para47, %para48, %para49, %para50, %para51, %para52, %para53) #(Ref[Tensor(F32)][50, 3, 3, 3], Ref[Tensor(F32)][50, 50, 3, 3], Ref[Tensor(F32)][50, 50, 3, 3], Ref[Tensor(F32)][50, 50, 3, 3], Ref[Tensor(F32)][50, 3, 4, 4], Ref[Tensor(F32)][50, 50, 4, 4], Ref[Tensor(F32)][50, 50, 4, 4], Ref[Tensor(F32)][50, 50, 4, 4], Ref[Tensor(F32)][50, 3, 5, 5], Ref[Tensor(F32)][50, 50, 5, 5], Ref[Tensor(F32)][50, 50, 5, 5], Ref[Tensor(F32)][50, 50, 5, 5], Ref[Tensor(F32)][50, 150, 3, 3], Ref[Tensor(F32)][50, 150, 4, 4], Ref[Tensor(F32)][50, 50, 4, 4], Ref[Tensor(F32)][50, 150, 5, 5], Ref[Tensor(F32)][50, 153, 3, 3], Ref[Tensor(F32)][50, 50, 3, 3], Ref[Tensor(F32)][50, 50, 3, 3], Ref[Tensor(F32)][50, 50, 3, 3], Ref[Tensor(F32)][50, 153, 4, 4], Ref[Tensor(F32)][50, 50, 4, 4], Ref[Tensor(F32)][50, 50, 4, 4], Ref[Tensor(F32)][50, 50, 4, 4], Ref[Tensor(F32)][50, 153, 5, 5], Ref[Tensor(F32)][50, 50, 5, 5], Ref[Tensor(F32)][50, 50, 5, 5], Ref[Tensor(F32)][50, 50, 5, 5], Ref[Tensor(F32)][50, 150, 3, 3], Ref[Tensor(F32)][50, 150, 4, 4], Ref[Tensor(F32)][50, 50, 4, 4], Ref[Tensor(F32)][50, 150, 5, 5], Ref[Tensor(F32)][3, 150, 1, 1], Ref[Tensor(F32)][50, 3, 3, 3], Ref[Tensor(F32)][50, 50, 3, 3], Ref[Tensor(F32)][50, 50, 3, 3], Ref[Tensor(F32)][50, 50, 3, 3], Ref[Tensor(F32)][50, 3, 4, 4], Ref[Tensor(F32)][50, 50, 4, 4], Ref[Tensor(F32)][50, 50, 4, 4], Ref[Tensor(F32)][50, 50, 4, 4], Ref[Tensor(F32)][50, 3, 5, 5], Ref[Tensor(F32)][50, 50, 5, 5], Ref[Tensor(F32)][50, 50, 5, 5], Ref[Tensor(F32)][50, 50, 5, 5], Ref[Tensor(F32)][50, 150, 3, 3], Ref[Tensor(F32)][50, 150, 4, 4], Ref[Tensor(F32)][50, 50, 4, 4], Ref[Tensor(F32)][50, 150, 5, 5], Ref[Tensor(F32)][3, 150, 1, 1]) #scope: Default + # In file C:\ProgramData\Anaconda3\envs\mindspore_py37_CPU\lib\site-packages\mindspore\nn\wrap\cell_wrapper.py(392)/ grads = self.grad(self.network, self.weights)(*inputs, sens)/#[CNode]60 + %9 = $(✗construct.30):DoSignaturePrimitive::S-Prim-grad{prim_type=1}(%7, %8) #(Undefined, Undefined) #scope: Default + # In file C:\ProgramData\Anaconda3\envs\mindspore_py37_CPU\lib\site-packages\mindspore\nn\wrap\cell_wrapper.py(392)/ grads = self.grad(self.network, self.weights)(*inputs, sens)/#grads + %10 = $(✗construct.30):UnpackCall::unpack_call(%9, %1, %6) #(Undefined, Tuple[Tensor(F32)*2], Undefined) #scope: Default + # In file C:\ProgramData\Anaconda3\envs\mindspore_py37_CPU\lib\site-packages\mindspore\nn\wrap\cell_wrapper.py(392)/ grads = self.grad(self.network, self.weights)(*inputs, sens)/#grads + %11 = $(✗construct.30):DoSignaturePrimitive::S-Prim-identity{prim_type=1}[side_effect_propagate=I64(1)](%10) #(Undefined) #scope: Default + # In file C:\ProgramData\Anaconda3\envs\mindspore_py37_CPU\lib\site-packages\mindspore\nn\wrap\cell_wrapper.py(393)/ grads = self.grad_reducer(grads)/#grads + %12 = FuncGraph::fg_61(%11) #(Undefined) # fg_61=construct.61 #scope: Default + # In file C:\ProgramData\Anaconda3\envs\mindspore_py37_CPU\lib\site-packages\mindspore\nn\wrap\cell_wrapper.py(397)/ loss = F.depend(loss, self.optimizer(grads))/#[CNode]62 + %13 = DoSignaturePrimitive::S-Prim-Depend{prim_type=1}[side_effect_propagate=I64(1)](%2, %12) #(Undefined, Undefined) #scope: Default + # In file C:\ProgramData\Anaconda3\envs\mindspore_py37_CPU\lib\site-packages\mindspore\nn\wrap\cell_wrapper.py(397)/ loss = F.depend(loss, self.optimizer(grads))/#loss + %14 = FuncGraph::fg_63(%13) #(Undefined) # fg_63=↓✗construct.63 #scope: Default + # In file C:\ProgramData\Anaconda3\envs\mindspore_py37_CPU\lib\site-packages\mindspore\nn\wrap\cell_wrapper.py(394)/ if self.use_grad_accumulation:/#[CNode]64 + Primitive::Return{prim_type=1}(%14) #(Undefined) #scope: Default + # In file C:\ProgramData\Anaconda3\envs\mindspore_py37_CPU\lib\site-packages\mindspore\nn\wrap\cell_wrapper.py(394)/ if self.use_grad_accumulation:/#[CNode]65 +} +# order: +# 1: ✗✗construct.31:[CNode]62{[0]: ValueNode construct.61, [1]: grads} +# 2: ✗✗construct.31:loss{[0]: ValueNode S-Prim-Depend, [1]: loss, [2]: [CNode]62} +# 3: ✗✗construct.31:[CNode]64{[0]: ValueNode ↓✗construct.63, [1]: loss} +# 4: ✗✗construct.31:[CNode]65{[0]: ValueNode Return, [1]: [CNode]64} + + +# [No.6] UnpackCall.32 +# +funcgraph fg_32( + %para161 : Func # 33 + , %para162 : Tuple[Tensor(F32)*2] # 34 + ) { + %1 : Tensor(F32)[2, 3, 224, 224] = Primitive::TupleGetItem{prim_type=1}(%para162, I64(0)) #(Tuple[Tensor(F32)*2], I64) #scope: Default + # #66 + %2 : Tensor(F32)[2, 3, 224, 224] = Primitive::TupleGetItem{prim_type=1}(%para162, I64(1)) #(Tuple[Tensor(F32)*2], I64) #scope: Default + # #67 + +#------------------------> 5 + %3 = %para161(%1, %2) #(Tensor(F32)[2, 3, 224, 224], Tensor(F32)[2, 3, 224, 224]) #scope: Default + # #68 + Primitive::Return{prim_type=1}(%3) #(Undefined) #scope: Default + # #69 +} +# order: +# 1: UnpackCall.32:68{[0]: 33, [1]: 66, [2]: 67} +# 2: UnpackCall.32:69{[0]: ValueNode Return, [1]: 68} + + +# [No.7] construct.35 +# In file C:\ProgramData\Anaconda3\envs\mindspore_py37_CPU\lib\site-packages\mindspore\nn\wrap\cell_wrapper.py(111)/ def construct(self, data, label):/ +funcgraph fg_35[fg_25]( + %para163 : Tensor(F32)[2, 3, 224, 224] # data + , %para164 : Tensor(F32)[2, 3, 224, 224] # label + ) { + %1 : Tensor(F32)[2, 3, 224, 224] = FuncGraph::fg_70(%para163) #(Tensor(F32)[2, 3, 224, 224]) # fg_70=construct.70 #scope: Default/network-WithLossCell + # In file C:\ProgramData\Anaconda3\envs\mindspore_py37_CPU\lib\site-packages\mindspore\nn\wrap\cell_wrapper.py(112)/ out = self._backbone(data)/#out + +#------------------------> 6 + %2 = FuncGraph::fg_36(%1, %para164) #(Tensor(F32)[2, 3, 224, 224], Tensor(F32)[2, 3, 224, 224]) # fg_36=construct.36 #scope: Default/network-WithLossCell + # In file C:\ProgramData\Anaconda3\envs\mindspore_py37_CPU\lib\site-packages\mindspore\nn\wrap\cell_wrapper.py(113)/ return self._loss_fn(out, label)/#[CNode]71 + Primitive::Return{prim_type=1}(%2) #(Undefined) #scope: Default/network-WithLossCell + # In file C:\ProgramData\Anaconda3\envs\mindspore_py37_CPU\lib\site-packages\mindspore\nn\wrap\cell_wrapper.py(113)/ return self._loss_fn(out, label)/#[CNode]72 +} +# order: +# 1: construct.35:out{[0]: ValueNode construct.70, [1]: data} +# 2: construct.35:[CNode]71{[0]: ValueNode construct.36, [1]: out, [2]: label} +# 3: construct.35:[CNode]72{[0]: ValueNode Return, [1]: [CNode]71} + + +# [No.8] construct.36 +# In file E:/keyi.rao/FAIR1M/train.py(64)/ def construct(self, prime, label):/ +funcgraph fg_36( + %para165 : Tensor(F32)[2, 3, 224, 224] # prime + , %para166 : Tensor(F32)[2, 3, 224, 224] # label + ) { + +#------------------------> 7 + %1 = DoSignaturePrimitive::S-Prim-Split{prim_type=1}[axis=I64(1), output_num=I64(2)](%para165) #(Tensor(F32)[2, 3, 224, 224]) #scope: Default/network-WithLossCell/_loss_fn-MyLoss + # In file E:/keyi.rao/FAIR1M/train.py(66)/ c_prime, s_prime = self.split1(prime)/#[CNode]73 + %2 = DoSignaturePrimitive::S-Prim-getitem{prim_type=1}(%1, I64(0)) #(Undefined, Undefined) #scope: Default/network-WithLossCell/_loss_fn-MyLoss + # In file E:/keyi.rao/FAIR1M/train.py(66)/ c_prime, s_prime = self.split1(prime)/#c_prime + %3 = DoSignaturePrimitive::S-Prim-Split{prim_type=1}[axis=I64(0), output_num=I64(2)](%para166) #(Tensor(F32)[2, 3, 224, 224]) #scope: Default/network-WithLossCell/_loss_fn-MyLoss + # In file E:/keyi.rao/FAIR1M/train.py(67)/ c, s = self.split0(label)/#[CNode]74 + %4 = DoSignaturePrimitive::S-Prim-getitem{prim_type=1}(%3, I64(0)) #(Undefined, Undefined) #scope: Default/network-WithLossCell/_loss_fn-MyLoss + # In file E:/keyi.rao/FAIR1M/train.py(67)/ c, s = self.split0(label)/#c + %5 = FuncGraph::fg_75(%2, %4) #(Undefined, Undefined) # fg_75=construct.75 #scope: Default/network-WithLossCell/_loss_fn-MyLoss + # In file E:/keyi.rao/FAIR1M/train.py(68)/ loss_cover = self.mse(c_prime, c)/#loss_cover + %6 = DoSignaturePrimitive::S-Prim-getitem{prim_type=1}(%1, I64(1)) #(Undefined, Undefined) #scope: Default/network-WithLossCell/_loss_fn-MyLoss + # In file E:/keyi.rao/FAIR1M/train.py(66)/ c_prime, s_prime = self.split1(prime)/#s_prime + %7 = DoSignaturePrimitive::S-Prim-getitem{prim_type=1}(%3, I64(1)) #(Undefined, Undefined) #scope: Default/network-WithLossCell/_loss_fn-MyLoss + # In file E:/keyi.rao/FAIR1M/train.py(67)/ c, s = self.split0(label)/#s + %8 = FuncGraph::fg_75(%6, %7) #(Undefined, Undefined) # fg_75=construct.75 #scope: Default/network-WithLossCell/_loss_fn-MyLoss + # In file E:/keyi.rao/FAIR1M/train.py(69)/ loss_secret = self.mse(s_prime, s)/#loss_secret + %9 = DoSignaturePrimitive::S-Prim-mul{prim_type=1}(I64(1), %8) #(Undefined, Undefined) #scope: Default/network-WithLossCell/_loss_fn-MyLoss + # In file E:/keyi.rao/FAIR1M/train.py(71)/ loss_all = loss_cover + beta * loss_secret/#[CNode]76 + %10 = DoSignaturePrimitive::S-Prim-add{prim_type=1}(%5, %9) #(Undefined, Undefined) #scope: Default/network-WithLossCell/_loss_fn-MyLoss + # In file E:/keyi.rao/FAIR1M/train.py(71)/ loss_all = loss_cover + beta * loss_secret/#loss_all + %11 = FuncGraph::fg_77(%10) #(Undefined) # fg_77=get_loss.77 #scope: Default/network-WithLossCell/_loss_fn-MyLoss + # In file E:/keyi.rao/FAIR1M/train.py(72)/ return self.get_loss(loss_all)/#[CNode]78 + Primitive::Return{prim_type=1}(%11) #(Undefined) #scope: Default/network-WithLossCell/_loss_fn-MyLoss + # In file E:/keyi.rao/FAIR1M/train.py(72)/ return self.get_loss(loss_all)/#[CNode]79 +} +# order: +# 1: construct.36:[CNode]73{[0]: ValueNode S-Prim-Split, [1]: prime} +# 2: construct.36:c_prime{[0]: ValueNode S-Prim-getitem, [1]: [CNode]73, [2]: ValueNode 0} +# 3: construct.36:s_prime{[0]: ValueNode S-Prim-getitem, [1]: [CNode]73, [2]: ValueNode 1} +# 4: construct.36:[CNode]74{[0]: ValueNode S-Prim-Split, [1]: label} +# 5: construct.36:c{[0]: ValueNode S-Prim-getitem, [1]: [CNode]74, [2]: ValueNode 0} +# 6: construct.36:s{[0]: ValueNode S-Prim-getitem, [1]: [CNode]74, [2]: ValueNode 1} +# 7: construct.36:loss_cover{[0]: ValueNode construct.75, [1]: c_prime, [2]: c} +# 8: construct.36:loss_secret{[0]: ValueNode construct.75, [1]: s_prime, [2]: s} +# 9: construct.36:[CNode]76{[0]: ValueNode S-Prim-mul, [1]: ValueNode 1, [2]: loss_secret} +# 10: construct.36:loss_all{[0]: ValueNode S-Prim-add, [1]: loss_cover, [2]: [CNode]76} +# 11: construct.36:[CNode]78{[0]: ValueNode get_loss.77, [1]: loss_all} +# 12: construct.36:[CNode]79{[0]: ValueNode Return, [1]: [CNode]78} + + +#=============================================================================== +# num of function graphs in stack: 8/9 (Ignored 1 internal frames). diff --git a/code/2021_autumn/2021202130071-Mindspore-DeepSteganography/config/Config.yaml b/code/2021_autumn/2021202130071-Mindspore-DeepSteganography/config/Config.yaml new file mode 100644 index 0000000..279d02b --- /dev/null +++ b/code/2021_autumn/2021202130071-Mindspore-DeepSteganography/config/Config.yaml @@ -0,0 +1,30 @@ +# This is a yaml config file +# 利用外部的配置文件,让配置文件仅仅包含配置信息,和代码独立开来。 +# 不直接引用也就不需要写成python代码。通常使用json、yaml或者ini的文件格式来存储配置。 + +# ----------------------------------------------------------------------------- +# Data settings +# ----------------------------------------------------------------------------- +DATA_PATH: './datasets/' +MODELS_PATH: './checkpoints' +TRAIN_PATH: './datasets/train/' +VALID_PATH: './datasets/valid/' +TEST_PATH: './datasets/test/' + +# ----------------------------------------------------------------------------- +# train parameters setting +# ----------------------------------------------------------------------------- +batch_size: 2 +repeat_size: 1 +epochs: 5 +learning_rate: 0.001 +alpha: 0.1 +beta: 1 + +# ----------------------------------------------------------------------------- +# Testing settings +# ----------------------------------------------------------------------------- + + + + diff --git a/code/2021_autumn/2021202130071-Mindspore-DeepSteganography/config/__init__.py b/code/2021_autumn/2021202130071-Mindspore-DeepSteganography/config/__init__.py new file mode 100644 index 0000000..6531027 --- /dev/null +++ b/code/2021_autumn/2021202130071-Mindspore-DeepSteganography/config/__init__.py @@ -0,0 +1,5 @@ +#!/usr/bin/python3 +# -*- coding: utf-8 -*- +# @Author: Kae +# @Time : 2021/11/28 15:44 +# @File : __init__.py diff --git a/code/2021_autumn/2021202130071-Mindspore-DeepSteganography/config/yamlparser.py b/code/2021_autumn/2021202130071-Mindspore-DeepSteganography/config/yamlparser.py new file mode 100644 index 0000000..8696386 --- /dev/null +++ b/code/2021_autumn/2021202130071-Mindspore-DeepSteganography/config/yamlparser.py @@ -0,0 +1,34 @@ +#!/usr/bin/python3 +# -*- coding: utf-8 -*- +# @Author: Kae +# @Time : 2021/11/7 10:40 +# @File : yamlparser.py +""" +Configparser: Parameter Setting +The configuration modification does not involve code modification, +which greatly facilitates software maintenance in the later period +""" +import argparse # 传参 +import yaml # 调用yaml配置文件 +from easydict import EasyDict as Edict # 建立全局变量 + + +def parse_argument(): + # 创建一个解析对象 + parser = argparse.ArgumentParser(description="you should add those parameter:") + # 向该对象中添加命令行参数和选项 + # 每一个add_argument方法对应一个参数或选项 + parser.add_argument('--cfg', type=str, default='./config/Config.yaml') + # 调用parse_args()方法进行解析;解析成功之后即可使用。 + args = parser.parse_args() + return args + + +def get_argument(): + args = Edict(yaml.load(open(parse_argument().cfg, "r", encoding="utf-8"), Loader=yaml.FullLoader)) + print(args) + return args + + +if __name__ == "__main__": + get_argument() diff --git a/code/2021_autumn/2021202130071-Mindspore-DeepSteganography/data/__init__.py b/code/2021_autumn/2021202130071-Mindspore-DeepSteganography/data/__init__.py new file mode 100644 index 0000000..3bfe1b0 --- /dev/null +++ b/code/2021_autumn/2021202130071-Mindspore-DeepSteganography/data/__init__.py @@ -0,0 +1,5 @@ +#!/usr/bin/python3 +# -*- coding: utf-8 -*- +# @Author: Kae +# @Time : 2021/11/26 14:20 +# @File : __init__.py diff --git a/code/2021_autumn/2021202130071-Mindspore-DeepSteganography/data/analyze_fail.dat b/code/2021_autumn/2021202130071-Mindspore-DeepSteganography/data/analyze_fail.dat new file mode 100644 index 0000000..a552aba --- /dev/null +++ b/code/2021_autumn/2021202130071-Mindspore-DeepSteganography/data/analyze_fail.dat @@ -0,0 +1,229 @@ +# [No.1] construct_wrapper.0 +# In file E:\keyi.rao\FAIR1M\models\networks.py(68)/ def construct(self, x):/ +funcgraph fg_0( + %para1 : Dictionary[[image,label,],[Tensor[Float32]*2]] # x + , %para2 : Ref[Tensor(F32)][50, 150, 5, 5] # finalP5.0.weight + , %para3 : Ref[Tensor(F32)][50, 150, 3, 3] # finalP3.0.weight + , %para4 : Ref[Tensor(F32)][50, 150, 4, 4] # finalP4.0.weight + , %para5 : Ref[Tensor(F32)][50, 50, 4, 4] # finalP4.2.weight + , %para6 : Ref[Tensor(F32)][50, 3, 3, 3] # initialP3.0.weight + , %para7 : Ref[Tensor(F32)][50, 50, 3, 3] # initialP3.2.weight + , %para8 : Ref[Tensor(F32)][50, 50, 3, 3] # initialP3.4.weight + , %para9 : Ref[Tensor(F32)][50, 50, 3, 3] # initialP3.6.weight + , %para10 : Ref[Tensor(F32)][50, 3, 4, 4] # initialP4.0.weight + , %para11 : Ref[Tensor(F32)][50, 50, 4, 4] # initialP4.2.weight + , %para12 : Ref[Tensor(F32)][50, 50, 4, 4] # initialP4.4.weight + , %para13 : Ref[Tensor(F32)][50, 50, 4, 4] # initialP4.6.weight + , %para14 : Ref[Tensor(F32)][50, 3, 5, 5] # initialP5.0.weight + , %para15 : Ref[Tensor(F32)][50, 50, 5, 5] # initialP5.2.weight + , %para16 : Ref[Tensor(F32)][50, 50, 5, 5] # initialP5.4.weight + , %para17 : Ref[Tensor(F32)][50, 50, 5, 5] # initialP5.6.weight + ) { + +#------------------------> 0 + %1 = FuncGraph::fg_3(%para1) #(Dictionary[[image,label,],[Tensor[Float32]*2]]) # fg_3=construct.3 #scope: Default + # In file E:\keyi.rao\FAIR1M\models\networks.py(68)/ def construct(self, x):/#[CNode]10 + Primitive::Return{prim_type=1}(%1) #(Undefined) #scope: Default + # In file E:\keyi.rao\FAIR1M\models\networks.py(68)/ def construct(self, x):/#[CNode]11 +} +# order: +# 1: construct_wrapper.0:[CNode]10{[0]: ValueNode construct.3, [1]: x} +# 2: construct_wrapper.0:[CNode]11{[0]: ValueNode Return, [1]: [CNode]10} + + +# [No.2] construct.3 +# In file E:\keyi.rao\FAIR1M\models\networks.py(68)/ def construct(self, x):/ +funcgraph fg_3[fg_0]( + %para18 : Dictionary[[image,label,],[Tensor[Float32]*2]] # x + ) { + %1 : Func = ClassType() #scope: Default + # In file E:\keyi.rao\FAIR1M\models\networks.py(70)/ cat = ops.Concat()/#cat + +#------------------------> 1 + %2 = FuncGraph::fg_4(%para18) #(Dictionary[[image,label,],[Tensor[Float32]*2]]) # fg_4=construct.4 #scope: Default + # In file E:\keyi.rao\FAIR1M\models\networks.py(72)/ x1 = self.initialP3(x)/#x1 + %3 = FuncGraph::fg_12(%para18) #(Dictionary[[image,label,],[Tensor[Float32]*2]]) # fg_12=construct.12 #scope: Default + # In file E:\keyi.rao\FAIR1M\models\networks.py(73)/ x2 = self.initialP4(x)/#x2 + %4 = FuncGraph::fg_13(%para18) #(Dictionary[[image,label,],[Tensor[Float32]*2]]) # fg_13=construct.13 #scope: Default + # In file E:\keyi.rao\FAIR1M\models\networks.py(74)/ x3 = self.initialP5(x)/#x3 + %5 = DoSignaturePrimitive::S-Prim-MakeTuple{prim_type=1}(%2, %3, %4) #(Undefined, Undefined, Undefined) #scope: Default + # In file E:\keyi.rao\FAIR1M\models\networks.py(75)/ mid = cat((x1, x2, x3), 1)/#[CNode]14 + %6 = %1(%5, I64(1)) #(Undefined, Undefined) #scope: Default + # In file E:\keyi.rao\FAIR1M\models\networks.py(75)/ mid = cat((x1, x2, x3), 1)/#mid + %7 = FuncGraph::fg_15(%6) #(Undefined) # fg_15=construct.15 #scope: Default + # In file E:\keyi.rao\FAIR1M\models\networks.py(79)/ x6 = self.finalP5(mid)/#x6 + %8 = Primitive::stop_gradient{prim_type=1}(%7) #(Undefined) #scope: Default + # In file E:\keyi.rao\FAIR1M\models\networks.py(68)/ def construct(self, x):/#[CNode]16 + %9 = FuncGraph::fg_17(%6) #(Undefined) # fg_17=construct.17 #scope: Default + # In file E:\keyi.rao\FAIR1M\models\networks.py(77)/ x4 = self.finalP3(mid)/#x4 + %10 = FuncGraph::fg_18(%6) #(Undefined) # fg_18=construct.18 #scope: Default + # In file E:\keyi.rao\FAIR1M\models\networks.py(78)/ x5 = self.finalP4(mid)/#x5 + %11 = DoSignaturePrimitive::S-Prim-MakeTuple{prim_type=1}(%9, %10, %10) #(Undefined, Undefined, Undefined) #scope: Default + # In file E:\keyi.rao\FAIR1M\models\networks.py(80)/ out = cat((x4, x5, x5), 1)/#[CNode]19 + %12 = %1(%11, I64(1)) #(Undefined, Undefined) #scope: Default + # In file E:\keyi.rao\FAIR1M\models\networks.py(80)/ out = cat((x4, x5, x5), 1)/#out + %13 = Primitive::Depend{prim_type=1}[side_effect_propagate=I64(1)](%12, %8) #(Undefined, Undefined) #scope: Default + # In file E:\keyi.rao\FAIR1M\models\networks.py(68)/ def construct(self, x):/#[CNode]20 + Primitive::Return{prim_type=1}(%13) #(Undefined) #scope: Default + # In file E:\keyi.rao\FAIR1M\models\networks.py(68)/ def construct(self, x):/#[CNode]21 +} +# order: +# 1: construct.3:cat{[0]: ValueNode class 'mindspore.ops.operations.array_ops.Concat'} +# 2: construct.3:x1{[0]: ValueNode construct.4, [1]: x} +# 3: construct.3:x2{[0]: ValueNode construct.12, [1]: x} +# 4: construct.3:x3{[0]: ValueNode construct.13, [1]: x} +# 5: construct.3:[CNode]14{[0]: ValueNode S-Prim-MakeTuple, [1]: x1, [2]: x2, [3]: x3} +# 6: construct.3:mid{[0]: cat, [1]: [CNode]14, [2]: ValueNode 1} +# 7: construct.3:x4{[0]: ValueNode construct.17, [1]: mid} +# 8: construct.3:x5{[0]: ValueNode construct.18, [1]: mid} +# 9: construct.3:x6{[0]: ValueNode construct.15, [1]: mid} +# 10: construct.3:[CNode]19{[0]: ValueNode S-Prim-MakeTuple, [1]: x4, [2]: x5, [3]: x5} +# 11: construct.3:out{[0]: cat, [1]: [CNode]19, [2]: ValueNode 1} +# 12: construct.3:[CNode]21{[0]: ValueNode Return, [1]: [CNode]20} + + +# [No.3] construct.4 +# In file C:\ProgramData\Anaconda3\envs\mindspore_py37_CPU\lib\site-packages\mindspore\nn\layer\container.py(235)/ def construct(self, input_data):/ +funcgraph fg_4[fg_0]( + %para19 : Dictionary[[image,label,],[Tensor[Float32]*2]] # input_data + ) { + %1 : Tuple[Func*8] = Primitive::MakeTuple{prim_type=1}(FuncGraph::fg_8, FuncGraph::fg_22, FuncGraph::fg_23, FuncGraph::fg_24, FuncGraph::fg_25, FuncGraph::fg_26, FuncGraph::fg_27, FuncGraph::fg_28) #(Func, Func, Func, Func, Func, Func, Func, Func) # fg_8=construct.8, fg_22=construct.22, fg_23=construct.23, fg_24=construct.24, fg_25=construct.25, fg_26=construct.26, fg_27=construct.27, fg_28=construct.28 #scope: Default/initialP3-SequentialCell + # In file C:\ProgramData\Anaconda3\envs\mindspore_py37_CPU\lib\site-packages\mindspore\nn\layer\container.py(236)/ for cell in self.cell_list:/#[CNode]29 + %2 : I64 = FuncGraph::fg_30(%1) #(Tuple[Func*8]) # fg_30=ms_len.30 #scope: Default/initialP3-SequentialCell + # In file C:\ProgramData\Anaconda3\envs\mindspore_py37_CPU\lib\site-packages\mindspore\nn\layer\container.py(236)/ for cell in self.cell_list:/#[CNode]31 + %3 : Bool = Primitive::scalar_lt{prim_type=1}(%2, I64(9223372036854775807)) #(I64, I64) #scope: Default/initialP3-SequentialCell + # In file C:\ProgramData\Anaconda3\envs\mindspore_py37_CPU\lib\site-packages\mindspore\nn\layer\container.py(236)/ for cell in self.cell_list:/#[CNode]32 + %4 : Func = Primitive::Switch{prim_type=1}(%3, FuncGraph::fg_5, FuncGraph::fg_33) #(Bool, Func, Func) # fg_5=✓construct.5, fg_33=✗construct.33 #scope: Default/initialP3-SequentialCell + # In file C:\ProgramData\Anaconda3\envs\mindspore_py37_CPU\lib\site-packages\mindspore\nn\layer\container.py(236)/ for cell in self.cell_list:/#[CNode]34 + +#------------------------> 2 + %5 = %4() #scope: Default/initialP3-SequentialCell + # In file C:\ProgramData\Anaconda3\envs\mindspore_py37_CPU\lib\site-packages\mindspore\nn\layer\container.py(236)/ for cell in self.cell_list:/#[CNode]35 + Primitive::Return{prim_type=1}(%5) #(Undefined) #scope: Default/initialP3-SequentialCell + # In file C:\ProgramData\Anaconda3\envs\mindspore_py37_CPU\lib\site-packages\mindspore\nn\layer\container.py(236)/ for cell in self.cell_list:/#[CNode]36 +} +# order: +# 1: construct.4:[CNode]31{[0]: ValueNode ms_len.30, [1]: [CNode]29} +# 2: construct.4:[CNode]32{[0]: ValueNode scalar_lt, [1]: [CNode]31, [2]: ValueNode 9223372036854775807} +# 3: construct.4:[CNode]34{[0]: ValueNode Switch, [1]: [CNode]32, [2]: ValueNode ✓construct.5, [3]: ValueNode ✗construct.33} +# 4: construct.4:[CNode]35{[0]: [CNode]34} +# 5: construct.4:[CNode]36{[0]: ValueNode Return, [1]: [CNode]35} + + +# [No.4] ✓construct.5 +# In file C:\ProgramData\Anaconda3\envs\mindspore_py37_CPU\lib\site-packages\mindspore\nn\layer\container.py(236)/ for cell in self.cell_list:/ +funcgraph fg_5[fg_4]( +) { + %1 : $(construct.4):Tuple[Func*8] = Primitive::MakeTuple{prim_type=1}(FuncGraph::fg_8, FuncGraph::fg_22, FuncGraph::fg_23, FuncGraph::fg_24, FuncGraph::fg_25, FuncGraph::fg_26, FuncGraph::fg_27, FuncGraph::fg_28) #(Func, Func, Func, Func, Func, Func, Func, Func) # fg_8=construct.8, fg_22=construct.22, fg_23=construct.23, fg_24=construct.24, fg_25=construct.25, fg_26=construct.26, fg_27=construct.27, fg_28=construct.28 #scope: Default/initialP3-SequentialCell + # In file C:\ProgramData\Anaconda3\envs\mindspore_py37_CPU\lib\site-packages\mindspore\nn\layer\container.py(236)/ for cell in self.cell_list:/#[CNode]29 + %2 : Tuple[Func*8] = FuncGraph::fg_37(%1) #(Tuple[Func*8]) # fg_37=ms_iter.37 #scope: Default/initialP3-SequentialCell + # In file C:\ProgramData\Anaconda3\envs\mindspore_py37_CPU\lib\site-packages\mindspore\nn\layer\container.py(236)/ for cell in self.cell_list:/#@cell + +#------------------------> 3 + %3 = FuncGraph::fg_6(%2, %para19) #(Tuple[Func*8], Dictionary[[image,label,],[Tensor[Float32]*2]]) # fg_6=⤾✓construct.6 #scope: Default/initialP3-SequentialCell + # In file C:\ProgramData\Anaconda3\envs\mindspore_py37_CPU\lib\site-packages\mindspore\nn\layer\container.py(236)/ for cell in self.cell_list:/#[CNode]38 + Primitive::Return{prim_type=1}(%3) #(Undefined) #scope: Default/initialP3-SequentialCell + # In file C:\ProgramData\Anaconda3\envs\mindspore_py37_CPU\lib\site-packages\mindspore\nn\layer\container.py(236)/ for cell in self.cell_list:/#[CNode]39 +} +# order: +# 1: ✓construct.5:@cell{[0]: ValueNode ms_iter.37, [1]: [CNode]29} +# 2: ✓construct.5:[CNode]38{[0]: ValueNode ⤾✓construct.6, [1]: @cell, [2]: input_data} +# 3: ✓construct.5:[CNode]39{[0]: ValueNode Return, [1]: [CNode]38} + + +# [No.5] ⤾✓construct.6 +# In file C:\ProgramData\Anaconda3\envs\mindspore_py37_CPU\lib\site-packages\mindspore\nn\layer\container.py(236)/ for cell in self.cell_list:/ +funcgraph fg_6( + %para20 : Tuple[Func*8] # @cell + , %para21 : Dictionary[[image,label,],[Tensor[Float32]*2]] # Φinput_data + ) { + %1 : Bool = FuncGraph::fg_40(%para20) #(Tuple[Func*8]) # fg_40=hasnext.40 #scope: Default/initialP3-SequentialCell + # In file C:\ProgramData\Anaconda3\envs\mindspore_py37_CPU\lib\site-packages\mindspore\nn\layer\container.py(236)/ for cell in self.cell_list:/#[CNode]41 + %2 : Func = Primitive::Switch{prim_type=1}(%1, FuncGraph::fg_7, FuncGraph::fg_42) #(Bool, Func, Func) # fg_7=⥁✓construct.7, fg_42=↓✓construct.42 #scope: Default/initialP3-SequentialCell + # In file C:\ProgramData\Anaconda3\envs\mindspore_py37_CPU\lib\site-packages\mindspore\nn\layer\container.py(236)/ for cell in self.cell_list:/#[CNode]43 + +#------------------------> 4 + %3 = %2() #scope: Default/initialP3-SequentialCell + # In file C:\ProgramData\Anaconda3\envs\mindspore_py37_CPU\lib\site-packages\mindspore\nn\layer\container.py(236)/ for cell in self.cell_list:/#[CNode]44 + Primitive::Return{prim_type=1}(%3) #(Undefined) #scope: Default/initialP3-SequentialCell + # In file C:\ProgramData\Anaconda3\envs\mindspore_py37_CPU\lib\site-packages\mindspore\nn\layer\container.py(236)/ for cell in self.cell_list:/#[CNode]45 +} +# order: +# 1: ⤾✓construct.6:[CNode]41{[0]: ValueNode hasnext.40, [1]: @cell} +# 2: ⤾✓construct.6:[CNode]43{[0]: ValueNode Switch, [1]: [CNode]41, [2]: ValueNode ⥁✓construct.7, [3]: ValueNode ↓✓construct.42} +# 3: ⤾✓construct.6:[CNode]44{[0]: [CNode]43} +# 4: ⤾✓construct.6:[CNode]45{[0]: ValueNode Return, [1]: [CNode]44} + + +# [No.6] ⥁✓construct.7 +# In file C:\ProgramData\Anaconda3\envs\mindspore_py37_CPU\lib\site-packages\mindspore\nn\layer\container.py(236)/ for cell in self.cell_list:/ +funcgraph fg_7[fg_6]( +) { + %1 : Tuple[Func,Tuple[Func*7]] = FuncGraph::fg_46(%para20) #(Tuple[Func*8]) # fg_46=ms_next.46 #scope: Default/initialP3-SequentialCell + # In file C:\ProgramData\Anaconda3\envs\mindspore_py37_CPU\lib\site-packages\mindspore\nn\layer\container.py(236)/ for cell in self.cell_list:/#[CNode]47 + %2 : Tuple[Func*7] = DoSignaturePrimitive::S-Prim-getitem{prim_type=1}(%1, I64(1)) #(Tuple[Func,Tuple[Func*7]], I64) #scope: Default/initialP3-SequentialCell + # In file C:\ProgramData\Anaconda3\envs\mindspore_py37_CPU\lib\site-packages\mindspore\nn\layer\container.py(236)/ for cell in self.cell_list:/#@cell + %3 : Func = DoSignaturePrimitive::S-Prim-getitem{prim_type=1}(%1, I64(0)) #(Tuple[Func,Tuple[Func*7]], I64) #scope: Default/initialP3-SequentialCell + # In file C:\ProgramData\Anaconda3\envs\mindspore_py37_CPU\lib\site-packages\mindspore\nn\layer\container.py(236)/ for cell in self.cell_list:/#cell + +#------------------------> 5 + %4 = %3(%para21) #(Dictionary[[image,label,],[Tensor[Float32]*2]]) #scope: Default/initialP3-SequentialCell + # In file C:\ProgramData\Anaconda3\envs\mindspore_py37_CPU\lib\site-packages\mindspore\nn\layer\container.py(237)/ input_data = cell(input_data)/#input_data + %5 = FuncGraph::fg_6(%2, %4) #(Tuple[Func*7], Undefined) # fg_6=⤾✓construct.6 #scope: Default/initialP3-SequentialCell + # In file C:\ProgramData\Anaconda3\envs\mindspore_py37_CPU\lib\site-packages\mindspore\nn\layer\container.py(236)/ for cell in self.cell_list:/#[CNode]48 + Primitive::Return{prim_type=1}(%5) #(Undefined) #scope: Default/initialP3-SequentialCell + # In file C:\ProgramData\Anaconda3\envs\mindspore_py37_CPU\lib\site-packages\mindspore\nn\layer\container.py(236)/ for cell in self.cell_list:/#[CNode]49 +} +# order: +# 1: ⥁✓construct.7:[CNode]47{[0]: ValueNode ms_next.46, [1]: @cell} +# 2: ⥁✓construct.7:cell{[0]: ValueNode S-Prim-getitem, [1]: [CNode]47, [2]: ValueNode 0} +# 3: ⥁✓construct.7:@cell{[0]: ValueNode S-Prim-getitem, [1]: [CNode]47, [2]: ValueNode 1} +# 4: ⥁✓construct.7:input_data{[0]: cell, [1]: Φinput_data} +# 5: ⥁✓construct.7:[CNode]48{[0]: ValueNode ⤾✓construct.6, [1]: @cell, [2]: input_data} +# 6: ⥁✓construct.7:[CNode]49{[0]: ValueNode Return, [1]: [CNode]48} + + +# [No.7] construct.8 +# In file C:\ProgramData\Anaconda3\envs\mindspore_py37_CPU\lib\site-packages\mindspore\nn\layer\conv.py(260)/ def construct(self, x):/ +funcgraph fg_8[fg_0]( + %para22 : Dictionary[[image,label,],[Tensor[Float32]*2]] # x + ) { + %1 : Bool = FuncGraph::fg_50(Bool(0)) #(Bool) # fg_50=bool_.50 #scope: Default/initialP3-SequentialCell/0-Conv2d + # In file C:\ProgramData\Anaconda3\envs\mindspore_py37_CPU\lib\site-packages\mindspore\nn\layer\conv.py(262)/ if self.has_bias:/#51 + %2 : Func = Primitive::Switch{prim_type=1}(%1, FuncGraph::fg_52, FuncGraph::fg_9) #(Bool, Func, Func) # fg_52=✓construct.52, fg_9=✗construct.9 #scope: Default/initialP3-SequentialCell/0-Conv2d + # In file C:\ProgramData\Anaconda3\envs\mindspore_py37_CPU\lib\site-packages\mindspore\nn\layer\conv.py(262)/ if self.has_bias:/#[CNode]53 + +#------------------------> 6 + %3 = %2() #scope: Default/initialP3-SequentialCell/0-Conv2d + # In file C:\ProgramData\Anaconda3\envs\mindspore_py37_CPU\lib\site-packages\mindspore\nn\layer\conv.py(262)/ if self.has_bias:/#[CNode]54 + Primitive::Return{prim_type=1}(%3) #(Undefined) #scope: Default/initialP3-SequentialCell/0-Conv2d + # In file C:\ProgramData\Anaconda3\envs\mindspore_py37_CPU\lib\site-packages\mindspore\nn\layer\conv.py(262)/ if self.has_bias:/#[CNode]55 +} +# order: +# 1: construct.8:output{[0]: ValueNode S-Prim-Conv2D, [1]: x, [2]: initialP3.0.weight} +# 2: construct.8:51{[0]: ValueNode bool_.50, [1]: ValueNode false} +# 3: construct.8:[CNode]53{[0]: ValueNode Switch, [1]: 51, [2]: ValueNode ✓construct.52, [3]: ValueNode ✗construct.9} +# 4: construct.8:[CNode]54{[0]: [CNode]53} +# 5: construct.8:[CNode]55{[0]: ValueNode Return, [1]: [CNode]54} + + +# [No.8] ✗construct.9 +# In file C:\ProgramData\Anaconda3\envs\mindspore_py37_CPU\lib\site-packages\mindspore\nn\layer\conv.py(262)/ if self.has_bias:/ +funcgraph fg_9[fg_8]( +) { + +#------------------------> 7 + %1 = $(construct.8):DoSignaturePrimitive::S-Prim-Conv2D{prim_type=1}[stride=(I64(1), I64(1), I64(1), I64(1)), pad=(I64(1), I64(1), I64(1), I64(1)), pad_mode=I64(0), out_channel=I64(50), kernel_size=(I64(3), I64(3)), input_names=["x", "w"], format="NCHW", groups=I64(1), mode=I64(1), group=I64(1), dilation=(I64(1), I64(1), I64(1), I64(1)), output_names=["output"]](%para22, %para6) #(Dictionary[[image,label,],[Tensor[Float32]*2]], Ref[Tensor(F32)][50, 3, 3, 3]) #scope: Default/initialP3-SequentialCell/0-Conv2d + # In file C:\ProgramData\Anaconda3\envs\mindspore_py37_CPU\lib\site-packages\mindspore\nn\layer\conv.py(261)/ output = self.conv2d(x, self.weight)/#output + %2 = FuncGraph::fg_56(%1) #(Undefined) # fg_56=↓construct.56 #scope: Default/initialP3-SequentialCell/0-Conv2d + # In file C:\ProgramData\Anaconda3\envs\mindspore_py37_CPU\lib\site-packages\mindspore\nn\layer\conv.py(262)/ if self.has_bias:/#[CNode]57 + Primitive::Return{prim_type=1}(%2) #(Undefined) #scope: Default/initialP3-SequentialCell/0-Conv2d + # In file C:\ProgramData\Anaconda3\envs\mindspore_py37_CPU\lib\site-packages\mindspore\nn\layer\conv.py(262)/ if self.has_bias:/#[CNode]58 +} +# order: +# 1: ✗construct.9:[CNode]57{[0]: ValueNode ↓construct.56, [1]: output} +# 2: ✗construct.9:[CNode]58{[0]: ValueNode Return, [1]: [CNode]57} + + +#=============================================================================== +# num of function graphs in stack: 8/9 (Ignored 1 internal frames). diff --git a/code/2021_autumn/2021202130071-Mindspore-DeepSteganography/data/calculate_mean_std.py b/code/2021_autumn/2021202130071-Mindspore-DeepSteganography/data/calculate_mean_std.py new file mode 100644 index 0000000..e5f96d1 --- /dev/null +++ b/code/2021_autumn/2021202130071-Mindspore-DeepSteganography/data/calculate_mean_std.py @@ -0,0 +1,58 @@ +#!/usr/bin/python3 +# -*- coding: utf-8 -*- +# @Author: Kae +# @Time : 2021/11/05 15:52 +# @File : calculate_mean_std.py + +''' + Computing Mean & std in a specified image Dataset + get statistics(STAT) +''' + +import numpy as np + + +def get_stat(loader): + # The dimensions of inputs is [batch_size x 3 x image_size x image_size], + # so we need to make sure we aggregate values per each RGB channel separately. + # so we set axis = [0, 2, 3] to compute mean values with respect to axis 1. + # 即计算各通道均值 + # 此方法适用于batch_size=1的情况 + channels_mean_sum, channels_std_sum, num_batches = 0, 0, 0 + print("Start calculating STAT") + for img in loader: + # img是字典dict,img['image']才是其映射的图片 + # print(type(img['image']), img['image'].shape) + item = img['image'].asnumpy() + # item = img['image'] + # print(type(item)) + print("Calculating {0} images".format(num_batches)) + channels_mean_sum += np.mean(item, axis=(0, 2, 3), dtype='float64') + channels_std_sum += np.std(item, axis=(0, 2, 3), dtype='float32') + num_batches += 1 + # print(channels_mean_sum, channels_std_sum, num_batches) + mean = channels_mean_sum/num_batches + std = channels_std_sum/num_batches + print("The STAT result for the {0} images are{1} {2}:".format(num_batches, mean, std)) + # return mean, std + + +# def get_stat_batch(loader): + # # https://discuss.pytorch.org/t/about-normalization-using-pre-trained-vgg16-networks/23560/5?u=kuzand + # # The dimensions of inputs is [batch_size x 3 x image_size x image_size], + # # so we need to make sure we aggregate values per each RGB channel separately. + # # so we set axis = [0, 2, 3] to compute mean values with respect to axis 1. + # # 即计算各通道均值 + # mean = 0. + # std = 0. + # nb_samples = 0. + # for data in loader: + # batch_samples = data.size(0) + # data = data.view(batch_samples, data.size(1), -1) + # mean += data.mean(2).sum(0) + # std += data.std(2).sum(0) + # nb_samples += batch_samples + # + # mean /= nb_samples + # std /= nb_samples + diff --git a/code/2021_autumn/2021202130071-Mindspore-DeepSteganography/data/create_datasets.py b/code/2021_autumn/2021202130071-Mindspore-DeepSteganography/data/create_datasets.py new file mode 100644 index 0000000..9794b7e --- /dev/null +++ b/code/2021_autumn/2021202130071-Mindspore-DeepSteganography/data/create_datasets.py @@ -0,0 +1,125 @@ +# -*- coding: utf-8 -*- +# author: kae + +import os +import numpy as np +import mindspore +import mindspore.numpy +import mindspore.dataset.transforms.c_transforms as c_transforms # 常用转化用算子 +import mindspore.dataset.vision.c_transforms as vision # 图像转化用算子 +import mindspore.dataset as ds # 自定义算术集合 +import mindspore.context as context +from PIL import Image # (RGB) +from mindspore import dtype as mstype +from data import calculate_mean_std +from PIL import ImageStat +import matplotlib.pyplot as plt +from models import networks +import mindspore.ops as ops + +transforms_list = [c_transforms.TypeCast(mstype.float32), + vision.Resize((224, 224)), + # vision.RandomRotation((0, 15)), + vision.Rescale(1.0/255.0, 0.0), + # vision.Normalize(mean=(0.37, 0.38, 0.33), std=(0.18, 0.16, 0.15)), + # calculate the STATS before rescale + # original: (100, 115.0, 121.0), (71.0, 68.0, 70.0) + # method 1:[112.31863839 110.73437749 101.03731864] [47.02056 42.81785 39.97917] + # method 2:[93.91606605 97.79874902 84.44525164] [39.05604 34.2134 31.209335] + # method 3:[92.25529924 98.55032928 90.46930658] [39.5386 35.33961 32.99178] + # calculate the STATS after rescale + # original: [0.485, 0.456, 0.406] [0.229, 0.224, 0.225] + # method 1:[[0.36874344 0.38397096 0.33158724] [0.18031646 0.15813905 0.14791036]] + vision.HWC2CHW()] + + +class GetDatasetGenerator: + def __init__(self, root): + imgs = os.listdir(root) # os.listdir() 方法用于返回指定的文件夹包含的所有文件或文件夹的名字的列表 + self.imgs = [os.path.join(root, k) for k in imgs] # 把目录和文件名合成一个路径,带文件名的路径存成一个列表 + + # 通过getitem函数,读取数据和标签,并返回数据 + # Random accessible dataset as random accessible input. + def __getitem__(self, index): + img_path = self.imgs[index] + pil_img = np.asarray(Image.open(img_path).convert('RGB')) + # print(pil_img.shape, pil_img.dtype) + # label = 0 + # img = pil_img[ :, :, :] + # label = pil_img[ :, :, :] + img = pil_img + label = pil_img + return img, label # BCHW顺序 + + # 通过len函数,返回数据集数量 + def __len__(self): + return len(self.imgs) + + +class CreateDataset: + def __init__(self, data_name="try", data_path=r" ", batch_size=2, shuffle_control=False, training=True, ): + self.data_name = data_name + self.data_path = data_path + self.shuffle_control = shuffle_control + self.batch_size = batch_size + self.training = training + if self.training: + usage = 'train' + else: + usage = 'test' + + @property + def create_dataset(self): + # 生成一个对象 + # ROOT_DIR = os.path.abspath(os.path.dirname(os.path.dirname(__file__))) + # print(ROOT_DIR) + # img_path = os.path.join(ROOT_DIR, self.data_path) + img_path = self.data_path + dataset_generator = GetDatasetGenerator(img_path) + print("generate dataset object from {0}".format(img_path)) + # image1 = dataset_train_generator[100] + # print(image1.size) + # plt.imshow(image1) + # plt.show() + + # 创建一个dataset + # ds.GeneratorDataset():用户自定义的数据集读取、处理的方式。 + dataset = ds.GeneratorDataset(source=dataset_generator, column_names=["image", "label"], shuffle=self.shuffle_control) + print("create dataset {0}".format(self.data_name)) + + # 数据处理与数据增强 + # according to the parameters, generate the corresponding data enhancement method + print("Preprocessing....") + # apply the transform to the dataset through dataset.map() + dataset = dataset.map(input_columns=["image"], operations=transforms_list) + dataset = dataset.map(input_columns=["label"], operations=transforms_list) + # apply DatasetOps + dataset = dataset.batch(self.batch_size, drop_remainder=True) + + # 创建一个dataloader + dataloader = dataset.create_dict_iterator() + print("Create dataloader") + # for image in dataloader: + # print(type(image['image']), image['image'].shape) + # # print(image) + print("Create dataloader successfully!") + return dataset, dataloader + + +if __name__ == "__main__": + context.set_context(mode=context.PYNATIVE_MODE, device_target='CPU') + DATA_DIR = r".\datasets\train" + DATA_NAME = "TRAIN" + dataset, dataloader = CreateDataset(DATA_NAME, DATA_DIR).create_dataset + # print(type(dataset)) + # for data in dataset.create_dict_iterator(): + # print("Image shape:", type(data['image']), data['image'].shape, ", Label:", data['label']) + net = networks.DSNet() + net1 = networks.HidingNetwork() + cat = ops.Concat(axis=1) + for m in dataloader: + out = net(m['image']) + + + + diff --git a/code/2021_autumn/2021202130071-Mindspore-DeepSteganography/data/crop_image.py b/code/2021_autumn/2021202130071-Mindspore-DeepSteganography/data/crop_image.py new file mode 100644 index 0000000..96a2373 --- /dev/null +++ b/code/2021_autumn/2021202130071-Mindspore-DeepSteganography/data/crop_image.py @@ -0,0 +1,45 @@ +#!/usr/bin/python3 +# -*- coding: utf-8 -*- +# @Author: Kae +# @Time : 2021/11/05 10:23 +# @File : crop_image.py +""" + Crop all the images in a Folder +""" +import numpy as np +from PIL import Image +import os.path # 用于获取文件的属性 +import sys + + +def crop(path): + print(path) + images = os.listdir(path) + for item in images: + fullPath = os.path.join(path, item) + # print(fullPath) + if os.path.isfile(fullPath): # 判断路径是否为文件 + im = Image.open(fullPath) + arry_im = np.asarray(im) + print(item, type(im), im.size) + print(item, type(arry_im), arry_im.shape) + f, e = os.path.splitext(fullPath) # 分离文件名与扩展名;默认返回(fname,fextension)元组 + if im.size == (224, 224): + print("The size of image {0} is (224x224) already.".format(item)) + break + print("Crop the image {0} into 224x224".format(item)) + imCrop = im.crop((50, 50, 274, 274)) + imCrop.save(f+"c"+e, quality=100) + return 0 + + +if __name__ == '__main__': + + # print("当前目录是:{}".format(os.path.abspath(os.path.dirname(__file__)))) + # print("上级目录是:{}".format(os.path.abspath(os.path.dirname(os.path.dirname(__file__))))) + ROOT_DIR = os.path.abspath(os.path.dirname(os.path.dirname(__file__))) + # print(ROOT_DIR) + img_path = os.path.join(ROOT_DIR, r'datasets/small_size/try') + # os.path.join字符串不应以斜杠开头。以斜杠开头,那么它们将被视为“绝对路径”,丢弃它们之前的所有内容。 + # print(img_path) + crop(img_path) diff --git a/code/2021_autumn/2021202130071-Mindspore-DeepSteganography/data/random_select_image.py b/code/2021_autumn/2021202130071-Mindspore-DeepSteganography/data/random_select_image.py new file mode 100644 index 0000000..bd50eb0 --- /dev/null +++ b/code/2021_autumn/2021202130071-Mindspore-DeepSteganography/data/random_select_image.py @@ -0,0 +1,145 @@ +# -*- coding: utf-8 -*- +# author: Kae +# time: 2021/10/27 +""" +从批量文件夹中随机按照一定比例抽取一定数量的照片,保存到新的文件目录,再按比例分配train、val和test,用来制作数据集 +""" + +import os +import random +import shutil +import time + + +def random_copy_rate(src, dst, rate=0.01): + print('Start Copy Files !!!!') + if not os.path.exists(dst): + os.mkdir(dst) + pic_names = os.listdir(src) # 返回指定的文件夹包含的文件或文件夹的名字的列表 + pic_num = len(pic_names) # 计算文件夹下图片的数量 + pick_num = int(pic_num*rate) # 计算按照比例抽取的图片的数量 + sample = random.sample(pic_names, pick_num) # 随机选取的图片的名称存为列表(random.sample: 随机截取列表的指定数量的元素,但是不会改变列表本身的排序) + for name in sample: + # shutil.copy: 递归地将一个文件或目录(源)复制到另一个位置(目的地)并返回目的地。 + # 移动随机选择的图片到指定文件夹 + shutil.copy(src + "\\" + name, dst + "\\"+name) + print("Now there are {0} images in the {1}".format(len(os.listdir(dst)), dst)) + return 0 + + +def random_copy_num(src, dst, pick_num=1000): + print('Start Copy Files !!!!') + if not os.path.exists(dst): + os.mkdir(dst) + pic_names = os.listdir(src) # 返回指定的文件夹包含的文件或文件夹的名字的列表 + pic_num = len(pic_names) # 计算文件夹下图片的数量 + if pick_num > pic_num: + pick_num = pic_num + exist_names = os.listdir(dst) + exist_num = len(exist_names) + if exist_num < pick_num: + pick_num = pick_num - exist_num + if exist_num >= pick_num: + print("Enough Image {0}, Stop Copying".format(exist_num)) + return 0 + pick_num = int(pick_num) # 按指定数量抽取图片 + sample = random.sample(pic_names, pick_num) # 随机选取的图片的名称存为列表(random.sample: 随机截取列表的指定数量的元素,但是不会改变列表本身的排序) + print("Copy {0} images from {1} to {2}".format(pick_num, src, dst)) + for name in sample: + # shutil.copy: 递归地将一个文件或目录(源)复制到另一个位置(目的地)并返回目的地。 + # 移动随机选择的图片到指定文件夹 + shutil.copy(src + "\\" + name, dst + "\\"+name) + print("Copy images{0} to be {1}".format(src + "\\" + name, dst + "\\" + name)) + print("Now there are {0} images in the {1}".format(len(os.listdir(dst)), dst)) + return 0 + + +def random_move_rate(src, dst, rate=0.01): + print('Start Move Files !!!!') + if not os.path.exists(dst): + os.mkdir(dst) + pic_names = os.listdir(src) # 返回指定的文件夹包含的文件或文件夹的名字的列表 + pic_num = len(pic_names) # 计算文件夹下图片的数量 + pick_num = int(pic_num*rate) # 计算按照比例抽取的图片的数量 + sample = random.sample(pic_names, pick_num) # 随机选取的图片的名称存为列表(random.sample: 随机截取列表的指定数量的元素,但是不会改变列表本身的排序) + print("Move {0} images from {1} to {2}".format(pick_num, src, dst)) + for name in sample: + # shutil.copy: 递归地将一个文件或目录(源)复制到另一个位置(目的地)并返回目的地。 + # 移动随机选择的图片到指定文件夹 + shutil.move(src + "\\" + name, dst + "\\"+name) + print("Copy images{0} to be {1}".format(src + "\\" + name, dst + "\\"+name)) + print("Now there are {0} images in the {1}".format(len(os.listdir(dst)), dst)) + return 0 + + +def random_move_num(src, dst, pick_num=1000): + print('Start Move Files !!!!') + if not os.path.exists(dst): + os.mkdir(dst) + pic_names = os.listdir(src) # 返回指定的文件夹包含的文件或文件夹的名字的列表 + pic_num = len(pic_names) # 计算文件夹下图片的数量 + if pick_num > pic_num: + pick_num = pic_num + exist_names = os.listdir(dst) + exist_num = len(exist_names) + if exist_num < pick_num: + pick_num = pick_num - exist_num + if exist_num >= pick_num: + print("Enough Image {0}, Stop Moving".format(exist_num)) + return 0 + pick_num = int(pick_num) # 按指定数量抽取图片 + sample = random.sample(pic_names, pick_num) # 随机选取的图片的名称存为列表(random.sample: 随机截取列表的指定数量的元素,但是不会改变列表本身的排序) + print("Move {0} images from {1} to {2}".format(pick_num, src, dst)) + for name in sample: + # shutil.copy: 递归地将一个文件或目录(源)复制到另一个位置(目的地)并返回目的地。 + # 移动随机选择的图片到指定文件夹 + shutil.move(src + "\\" + name, dst + "\\"+name) + print("Move images{0} to be {1}".format(src + "\\" + name, dst + "\\" + name)) + print("Now there are {0} images in the {1}".format(len(os.listdir(dst)), dst)) + return 0 + + +if __name__ == '__main__': + start = time.time() + + """ + 随机选取1000张图片作为test + """ + # src_test = r"E:\keyi.rao\FAIR1M\FAIR1M_OriginalSet\test\images\images" + # dst_test = r"E:\keyi.rao\FAIR1M\datasets\test" + # num = 1000 + # random_copy_num(src_test, dst_test, num) + + """ + 随机选取8000张图片作为train + """ + # src_train= r"E:\keyi.rao\FAIR1M\FAIR1M_OriginalSet\train\part2\images-1" + # dst_train = r"E:\keyi.rao\FAIR1M\datasets\train" + # num = 8000 + # random_copy_num(src_train, dst_train, num) + + """ + 随机选取50%图片作为test_secret + """ + # src_train = r"E:\keyi.rao\FAIR1M\datasets\train" + # dst_train_secret = r"E:\keyi.rao\FAIR1M\datasets\train\secret" + # dst_train_cover = r"E:\keyi.rao\FAIR1M\datasets\train\cover" + # r = 0.5 + # random_move_rate(src_train, dst_train_secret, r) + # r = 1 + # random_move_rate(src_train, dst_train_cover, r) + + """ + 随机选取50%图片作为train_secret + """ + src_test = r"E:\keyi.rao\FAIR1M\datasets\test" + dst_test_secret = r"E:\keyi.rao\FAIR1M\datasets\test_secret" + dst_test_cover = r"E:\keyi.rao\FAIR1M\datasets\test_cover" + r = 0.5 + random_move_rate(src_test, dst_test_secret, r) + r = 1 + random_move_rate(src_test, dst_test_cover, r) + + + end = time.time() + print('selected pics finished, cost: {}/s'.format((end-start))) diff --git a/code/2021_autumn/2021202130071-Mindspore-DeepSteganography/data/rename_images.py b/code/2021_autumn/2021202130071-Mindspore-DeepSteganography/data/rename_images.py new file mode 100644 index 0000000..4f6fa36 --- /dev/null +++ b/code/2021_autumn/2021202130071-Mindspore-DeepSteganography/data/rename_images.py @@ -0,0 +1,33 @@ +# -*- coding: utf-8 -*- +# author: Kae +# time: 2021/10/27 +""" +按照原图片顺序以阿拉伯数字重命名所有图片 +""" + +import os + + +def rename(path, label=''): + imgList = os.listdir(path) + i = 0 + for img in imgList: + i += 1 + if img.endswith('.tif'): + print(i) + src = os.path.join(os.path.abspath(img_path), img) # 原先的图片名字 + dst = os.path.join(os.path.abspath(img_path), label+str(i)+'.tif') # 根据自己的需要重新命名,可以把'E_' + img改成你想要的名字 + os.rename(src, dst) # 重命名,覆盖原先的名字 + + +if __name__ == '__main__': + # ROOT_DIR = os.path.abspath("./") + ROOT_DIR = r"/datasets" + print(ROOT_DIR) + # img_path = os.path.join(ROOT_DIR, r"original_size\test\test_cover") + # img_path = os.path.join(ROOT_DIR, r"original_size\test\test_secret") + # img_path = os.path.join(ROOT_DIR, r"original_size\train\train_cover") + # img_path = os.path.join(ROOT_DIR, r"../datasets/original_size/train/train_secret") + img_path = os.path.join(ROOT_DIR, r"/datasets/test") + print(img_path) + rename(img_path) diff --git a/code/2021_autumn/2021202130071-Mindspore-DeepSteganography/models/__init__.py b/code/2021_autumn/2021202130071-Mindspore-DeepSteganography/models/__init__.py new file mode 100644 index 0000000..a0c0c0e --- /dev/null +++ b/code/2021_autumn/2021202130071-Mindspore-DeepSteganography/models/__init__.py @@ -0,0 +1,5 @@ +#!/usr/bin/python3 +# -*- coding: utf-8 -*- +# @Author: Kae +# @Time : 2021/11/26 14:21 +# @File : __init__.py diff --git a/code/2021_autumn/2021202130071-Mindspore-DeepSteganography/models/networks.py b/code/2021_autumn/2021202130071-Mindspore-DeepSteganography/models/networks.py new file mode 100644 index 0000000..beaf82e --- /dev/null +++ b/code/2021_autumn/2021202130071-Mindspore-DeepSteganography/models/networks.py @@ -0,0 +1,256 @@ +#!/usr/bin/python3 +# -*- coding: utf-8 -*- +# @Author: Kae +# @Time : 2021/11/06 10:22 +# @File : networks.py + +import numpy as np +import mindspore +import mindspore.nn as nn +import mindspore.ops as ops +from mindspore import Tensor + + +# Prep-Network: Secret Image Preparation +class PrepNetwork(nn.Cell): + """ + Prep-network结构 + """ + def __init__(self): + super(PrepNetwork, self).__init__() + # 定义所需要的运算 + # preparation network + # 3x3 con branch + self.initialP3 = nn.SequentialCell( + [nn.Conv2d(in_channels=3, out_channels=50, kernel_size=3, pad_mode='pad', padding=1), + nn.ReLU(), + nn.Conv2d(in_channels=50, out_channels=50, kernel_size=3, pad_mode='pad', padding=1), + nn.ReLU(), + nn.Conv2d(in_channels=50, out_channels=50, kernel_size=3, pad_mode='pad', padding=1), + nn.ReLU(), + nn.Conv2d(in_channels=50, out_channels=50, kernel_size=3, pad_mode='pad', padding=1), + nn.ReLU()]) + # 4x4 conv branch + self.initialP4 = nn.SequentialCell( + [nn.Conv2d(in_channels=3, out_channels=50, pad_mode='pad', kernel_size=4, padding=1), + nn.ReLU(), + nn.Conv2d(in_channels=50, out_channels=50, pad_mode='pad', kernel_size=4, padding=2), + nn.ReLU(), + nn.Conv2d(in_channels=50, out_channels=50, pad_mode='pad', kernel_size=4, padding=1), + nn.ReLU(), + nn.Conv2d(in_channels=50, out_channels=50, pad_mode='pad', kernel_size=4, padding=2), + nn.ReLU()]) + # 5x5 conv branch + self.initialP5 = nn.SequentialCell( + [nn.Conv2d(3, 50, kernel_size=5, pad_mode='pad', padding=2), + nn.ReLU(), + nn.Conv2d(50, 50, kernel_size=5, pad_mode='pad', padding=2), + nn.ReLU(), + nn.Conv2d(50, 50, kernel_size=5, pad_mode='pad', padding=2), + nn.ReLU(), + nn.Conv2d(50, 50, kernel_size=5, pad_mode='pad', padding=2), + nn.ReLU()]) + # middle network + # 3x3 conv branch + self.finalP3 = nn.SequentialCell( + [nn.Conv2d(150, 50, kernel_size=3, pad_mode='pad', padding=1), + nn.ReLU()]) + # 4x4 conv branch + self.finalP4 = nn.SequentialCell( + [nn.Conv2d(150, 50, kernel_size=4, pad_mode='pad', padding=1), + nn.ReLU(), + nn.Conv2d(50, 50, kernel_size=4, pad_mode='pad', padding=2), + nn.ReLU()]) + # 5x5 conv branch + self.finalP5 = nn.SequentialCell( + [nn.Conv2d(150, 50, kernel_size=5, pad_mode='pad', padding=2), + nn.ReLU()]) + + def construct(self, x): + # 使用定义好的运算构建前向网络 + cat = ops.Concat(axis=1) + # Transformations made by the preparation network + x1 = self.initialP3(x) + x2 = self.initialP4(x) + x3 = self.initialP5(x) + mid = cat((x1, x2, x3)) + # Transformations made by the middle network + x4 = self.finalP3(mid) + x5 = self.finalP4(mid) + x6 = self.finalP5(mid) + out = cat((x4, x5, x6)) + return out + + +# Hiding Network (5 conv layers): Hiding the image in the cover image +class HidingNetwork(nn.Cell): + def __init__(self): + super(HidingNetwork, self).__init__() + # 3x3 conv branch + self.initialH3 = nn.SequentialCell( + [nn.Conv2d(153, 50, kernel_size=3, pad_mode='pad', padding=1), + nn.ReLU(), + nn.Conv2d(50, 50, kernel_size=3, pad_mode='pad', padding=1), + nn.ReLU(), + nn.Conv2d(50, 50, kernel_size=3, pad_mode='pad', padding=1), + nn.ReLU(), + nn.Conv2d(50, 50, kernel_size=3, pad_mode='pad', padding=1), + nn.ReLU()]) + # 4x4 conv branch + self.initialH4 = nn.SequentialCell( + [nn.Conv2d(153, 50, kernel_size=4, pad_mode='pad', padding=1), + nn.ReLU(), + nn.Conv2d(50, 50, kernel_size=4, pad_mode='pad', padding=2), + nn.ReLU(), + nn.Conv2d(50, 50, kernel_size=4, pad_mode='pad', padding=1), + nn.ReLU(), + nn.Conv2d(50, 50, kernel_size=4, pad_mode='pad', padding=2), + nn.ReLU()]) + # 5x5 conv branch + self.initialH5 = nn.SequentialCell( + [nn.Conv2d(153, 50, kernel_size=5, pad_mode='pad', padding=2), + nn.ReLU(), + nn.Conv2d(50, 50, kernel_size=5, pad_mode='pad', padding=2), + nn.ReLU(), + nn.Conv2d(50, 50, kernel_size=5, pad_mode='pad', padding=2), + nn.ReLU(), + nn.Conv2d(50, 50, kernel_size=5, pad_mode='pad', padding=2), + nn.ReLU()]) + # middle network + # 3x3 conv branch + self.finalH3 = nn.SequentialCell( + [nn.Conv2d(150, 50, kernel_size=3, pad_mode='pad', padding=1), + nn.ReLU()]) + # 4x4 conv branch + self.finalH4 = nn.SequentialCell( + [nn.Conv2d(150, 50, kernel_size=4, pad_mode='pad', padding=1), + nn.ReLU(), + nn.Conv2d(50, 50, kernel_size=4, pad_mode='pad', padding=2), + nn.ReLU()]) + # 5x5 conv branch + self.finalH5 = nn.SequentialCell( + [nn.Conv2d(150, 50, kernel_size=5, pad_mode='pad', padding=2), + nn.ReLU()]) + # generate stego image + self.finalH = nn.SequentialCell( + [nn.Conv2d(150, 3, kernel_size=1, pad_mode='pad', padding=0)]) + + def construct(self, h): + cat = ops.Concat(axis=1) + # feature fusion + h1 = self.initialH3(h) + h2 = self.initialH4(h) + h3 = self.initialH5(h) + mid = cat((h1, h2, h3)) + # generate stego image + h4 = self.finalH3(mid) + h5 = self.finalH4(mid) + h6 = self.finalH5(mid) + mid2 = cat((h4, h5, h6)) + out = self.finalH(mid2) + return out + + +# Reveal Network (2 conv layers): Uncovering the hidden image with the reveal network +class RevealNetwork(nn.Cell): + def __init__(self): + super(RevealNetwork, self).__init__() + # 3x3 conv branch + self.initialR3 = nn.SequentialCell( + [nn.Conv2d(3, 50, kernel_size=3, pad_mode='pad', padding=1), + nn.ReLU(), + nn.Conv2d(50, 50, kernel_size=3, pad_mode='pad', padding=1), + nn.ReLU(), + nn.Conv2d(50, 50, kernel_size=3, pad_mode='pad', padding=1), + nn.ReLU(), + nn.Conv2d(50, 50, kernel_size=3, pad_mode='pad', padding=1), + nn.ReLU()]) + # 4x4 conv branch + self.initialR4 = nn.SequentialCell( + [nn.Conv2d(3, 50, kernel_size=4, pad_mode='pad', padding=1), + nn.ReLU(), + nn.Conv2d(50, 50, kernel_size=4, pad_mode='pad', padding=2), + nn.ReLU(), + nn.Conv2d(50, 50, kernel_size=4, pad_mode='pad', padding=1), + nn.ReLU(), + nn.Conv2d(50, 50, kernel_size=4, pad_mode='pad', padding=2), + nn.ReLU()]) + # 5x5 conv branch + self.initialR5 = nn.SequentialCell( + [nn.Conv2d(3, 50, kernel_size=5, pad_mode='pad', padding=2), + nn.ReLU(), + nn.Conv2d(50, 50, kernel_size=5, pad_mode='pad', padding=2), + nn.ReLU(), + nn.Conv2d(50, 50, kernel_size=5, pad_mode='pad', padding=2), + nn.ReLU(), + nn.Conv2d(50, 50, kernel_size=5, pad_mode='pad', padding=2), + nn.ReLU()]) + # Middle network + # 3x3 conv branch + self.finalR3 = nn.SequentialCell( + [nn.Conv2d(150, 50, kernel_size=3, pad_mode='pad', padding=1), + nn.ReLU()]) + # 3x3 conv branch + self.finalR4 = nn.SequentialCell( + [nn.Conv2d(150, 50, kernel_size=4, pad_mode='pad', padding=1), + nn.ReLU(), + nn.Conv2d(50, 50, kernel_size=4, pad_mode='pad', padding=2), + nn.ReLU()]) + # 3x3 conv branch + self.finalR5 = nn.SequentialCell( + [nn.Conv2d(150, 50, kernel_size=5, pad_mode='pad', padding=2), + nn.ReLU()]) + # generate secret image + self.finalR = nn.Conv2d(150, 3, kernel_size=1, pad_mode='pad', padding=0) + + def construct(self, r): + cat = ops.Concat(axis=1) + # feature fusion + r1 = self.initialR3(r) + r2 = self.initialR4(r) + r3 = self.initialR5(r) + mid = cat((r1, r2, r3)) + # generate reconstructed image + r4 = self.finalR3(mid) + r5 = self.finalR4(mid) + r6 = self.finalR5(mid) + mid2 = cat((r4, r5, r6)) + out = self.finalR(mid2) + return out + + +# Merge all sub-network into one module +class DSNet(nn.Cell): + def __init__(self): + super(DSNet, self).__init__() + # create instance for some specific network + self.m1 = PrepNetwork() + self.m2 = HidingNetwork() + self.m3 = RevealNetwork() + # create instance for some specific function + self.cat0 = ops.Concat(axis=0) + self.cat1 = ops.Concat(axis=1) + self.split0 = ops.Split(0, 2) + + def construct(self, data): + # process data + c, s = self.split0(data) + # extract the feature of secret image + feature = self.m1(s) + mid = self.cat1((feature, c)) + # generate stego image + c_prime = self.m2(mid) + # generate reconstructed image + s_prime = self.m3(c_prime) + # merge generated images + prime = self.cat0((c_prime, s_prime)) + # return x_2, x_3,x_2_noise + return prime + + +if __name__ == "__main__": + # 输出网络结构 + network = DSNet() + for m in network.parameters_and_names(): + print(m) + diff --git a/code/2021_autumn/2021202130071-Mindspore-DeepSteganography/test.py b/code/2021_autumn/2021202130071-Mindspore-DeepSteganography/test.py new file mode 100644 index 0000000..123090f --- /dev/null +++ b/code/2021_autumn/2021202130071-Mindspore-DeepSteganography/test.py @@ -0,0 +1,145 @@ +#!/usr/bin/python3 +# -*- coding: utf-8 -*- +# @Author: Kae +# @Time : 2021/11/07 19:52 +# @File : train.py + +# basic module +import os +import numpy as np +import mindspore + +# loading data +from mindspore import context, nn, Tensor +from mindspore.ops import composite +from data import create_datasets +import mindspore.ops as ops + +# evaluate model +from mindspore.nn import Metric +# from mindspore.nn import rearrange_inputs +from models.networks import DSNet +from mindspore.train.serialization import load_checkpoint, load_param_into_net + +DATA_DIR = r".\datasets\test" +DATA_NAME = "Test" +PARAM_DIR = r".\checkpoints" +PARAM_FILE = r"checkpoint_DSNet_2-48_4000" +batch_size = 2 +learning_rate = 1e-4 + + +class MyMetric(nn.Metric): + '''定义metric,评估模型''' + + def __init__(self): + super(MyMetric, self).__init__() + self.clear() + self.single_psrn_c = 0 + self.single_ssim_c = 0 + self.single_psrn_s = 0 + self.single_ssim_s = 0 + self._psrn_c_sum = 0 + self._ssim_c_sum = 0 + self._psrn_s_sum = 0 + self._ssim_s_sum = 0 + self._samples_num = 0 + self._result = [] + self._is_update = False + self.mse = nn.loss.MSELoss() + self.split1 = mindspore.ops.Split(1, 2) + self.split0 = mindspore.ops.Split(0, 2) + self.psnr = nn.PSNR() + self.ssim = nn.SSIM() + + def clear(self): + # 初始化相关内部参数 + self._psrn_c_sum = 0 + self._ssim_c_sum = 0 + self._psrn_s_sum = 0 + self._ssim_s_sum = 0 + self._samples_num = 0 + self._result = [] + self._is_update = False + + # @rearrange_inputs + def update(self, *inputs): + # 接收网络的预测和真值标签,更新内部变量 + # 更新输入数据,prime和label,数据输入类型可以是Tensor,list或numpy,维度必须相等 + if len(inputs) != 2: + raise ValueError('PNSR and SSIM need 2 inputs, but got {}'.format(len(inputs))) + # Mindspore内置的PSNR和SSIM的计算对象是tensor, 这里不需要把数据对象转换为 + inputs_prime = inputs[0] + inputs_label = inputs[1] + c_prime, s_prime = self.split0(inputs_prime) + c, s = self.split0(inputs_label) + # 统计数据的个数,方便后面求均值 + self._samples_num += c.shape[0] + if c.shape != c_prime.shape: + raise RuntimeError( + 'c_prime and c should have same the dimension, but the shape of y_pred is{}, ''the shape of y is {}.'.format( + c_prime.shape, c.shape)) + # 先求单次的PSNR和SSIM + self.single_psrn_c = self.psnr(c_prime, c) + self.single_ssim_c = self.ssim(c_prime, c) + self.single_psrn_s = self.psnr(s_prime, s) + self.single_ssim_s = self.ssim(s_prime, s) + # 对每一批次的进行累加 + self._psrn_c_sum += self.single_psrn_c.asnumpy() + self._ssim_c_sum += self.single_ssim_c.asnumpy() + self._psrn_s_sum += self.single_psrn_s.asnumpy() + self._ssim_s_sum += self.single_ssim_s.asnumpy() + print(self._psrn_c_sum/self._samples_num, self._psrn_s_sum/self._samples_num) + self._is_update = True + + def eval(self): + # 计算相关指标并返回计算结果 + if self._samples_num == 0: + raise RuntimeError('Total samples num must not be 0.') + self._result = np.array([self._psrn_c_sum, self._ssim_c_sum, self._psrn_s_sum, self._ssim_s_sum]) + return self._result/float(self._samples_num) + + +class MyWithEvalCell(nn.Cell): + """定义验证流程""" + + def __init__(self, network): + super(MyWithEvalCell, self).__init__(auto_prefix=False) + self.network = network + + def construct(self, data, label): + return self.network(data), label + + +if __name__ == "__main__": + # 获取验证数据 + dataset, dataloader = create_datasets.CreateDataset(DATA_NAME, DATA_DIR, batch_size).create_dataset + # 设置模型参数 + print("Loading Parameters from a trained-model") + net = DSNet() + optim = nn.Adam(params=net.trainable_params(), learning_rate=learning_rate) + # 加载模型参数 + param_dir = os.path.join(PARAM_DIR, PARAM_FILE+".ckpt") + param_dict = load_checkpoint(param_dir) + load_param_into_net(net, param_dict) + load_param_into_net(optim, param_dict) + # 定义评估网络 + print("Starting evaluating") + eval_net = MyWithEvalCell(net) + eval_net.set_train(False) + # 定义评估指标 + psnr_ssim = MyMetric() + # 执行推理过程 + psnr_ssim.clear() + i = 0 + for image, label in dataset: + prime, label = eval_net(image, label) + psnr_ssim.update(prime, label) + print("Update {0} time".format(i)) + i += 1 + break + result = psnr_ssim.eval() + print("psnr and ssim for c and s are respectively: ", result) + # 保存评估模型 + eval_dir = os.path.join(PARAM_DIR, PARAM_FILE+"_Eval.ckpt") + mindspore.save_checkpoint(net, eval_dir) diff --git a/code/2021_autumn/2021202130071-Mindspore-DeepSteganography/train.py b/code/2021_autumn/2021202130071-Mindspore-DeepSteganography/train.py new file mode 100644 index 0000000..8382f3d --- /dev/null +++ b/code/2021_autumn/2021202130071-Mindspore-DeepSteganography/train.py @@ -0,0 +1,182 @@ +#!/usr/bin/python3 +# -*- coding: utf-8 -*- +# @Author: Kae +# @Time : 2021/11/27 10:22 +# @File : train.py + +''' + Model training +''' + +# basic module +import mindspore +import os +import time +import argparse + +# loading data +import numpy +from mindspore import context, nn, Tensor +from mindspore.ops import composite +from data import create_datasets +import mindspore.ops as ops + +# training related modules +from models import networks +from mindspore.nn import TrainOneStepCell, WithLossCell +from mindspore.train.callback import ModelCheckpoint, CheckpointConfig, LossMonitor, Callback +from mindspore import Model +from mindspore.nn import Accuracy +from mindspore.train.serialization import load_checkpoint, load_param_into_net + +# visualization +import matplotlib.pyplot as plt +import matplotlib + +# Hyper Parameters +DATA_DIR = r"./datasets/train" +DATA_NAME = "Train" +PARAM_DIR = r".\checkpoints" +PARAM_FILE = r"checkpoint_DSNet_2-48_4000" +epochs = 80 +batch_size = 2 +repeat_size = 1 +learning_rate = 1e-4 +alpha = 0.1 +beta = 1 + + +class MyLoss(nn.loss.loss.LossBase): + """Calculates loss specified on the paper""" + + # loss = MSE(S’-S)+beta*MSE(C‘-C) + # 自定义损失函数的表达形式,还不是真正意义上的“损失函数” + + def __init__(self, + sparse=False, + reduction='none'): + # Initialize Customized Loss function + super(MyLoss, self).__init__(reduction) + self.mse = nn.loss.MSELoss() + # self.split1 = mindspore.ops.Split(1, 2) + self.split0 = mindspore.ops.Split(0, 2) + + def construct(self, prime, label): + # Set the forward way + c_prime, s_prime = self.split0(prime) + c, s = self.split0(label) + loss_cover = self.mse(c_prime, c) + loss_secret = self.mse(s_prime, s) + # Overall Loss Function + loss_all = loss_cover + beta * loss_secret + return self.get_loss(loss_all) + + +# custom callback function +class StepLossInfo(Callback): + def step_end(self, run_context): + cb_params = run_context.original_args() + # step_loss dictionary for saving loss value and step number information + step_loss["loss_value"].append(str(cb_params.net_outputs)) + step_loss["step"].append(str(cb_params.cur_step_num)) + + +def train_net(model, ckpoint_cb, step_loss_info, sink_mode=False): + """Define the training method.""" + print("============== Starting Training ==============") + # 加载训练数据 + dataset, dataloader = create_datasets.CreateDataset(DATA_NAME, DATA_DIR, batch_size).create_dataset + model.train(epochs, dataset, callbacks=([ckpoint_cb, LossMonitor(100), step_loss_info]), + dataset_sink_mode=sink_mode) + print("================ Stop Training =================") + + +# def train_net(args, model, epoch_size, data_path, chpoint_cb, sink_mode,train_dataset, network): +# """Define the training method.""" +# print("============== Starting Training ==============") +# """优化模型参数""" +# criterion = MyLoss() +# optim = nn.Adam(params=network.trainable_params(), learning_rate=learning_rate) +# model = Model(network, criterion, optim, metrics={"Accuracy": Accuracy()}) +# model.train(epochs, train_dataset, callbacks=LossMonitor()) +# print("================ Stop Training =================") + + +def save_loss(dictionary, filename='loss_history'): + '''保存loss_history''' + f = open('{}.txt'.format(filename), 'w') + f.write(str(dictionary)) + f.close() + + +def ReadDict(filename='loss_history'): + '''读取loss_history''' + f = open('{}.txt'.format(filename), 'r') + a = f.read() + dictionary = eval(a) + f.close() + return dictionary + + +def plot_loss(loss): + steps = loss["step"] + loss_value = loss["loss_value"] + steps = list(map(int, steps)) + loss_value = list(map(float, loss_value)) + plt.plot(steps, loss_value, color="red") + plt.xlabel("Steps") + plt.ylabel("Loss_value") + plt.title("Loss function value change chart") + plt.show() + + +if __name__ == "__main__": + # 设置参数 + parser = argparse.ArgumentParser(description='MindSpore LeNet Example') + parser.add_argument('--device_target', type=str, default="CPU", choices=['Ascend', 'GPU', 'CPU'], + help='device where the code will be implemented (default: CPU)') + # parser.add_argument('--epoch_size', type=) + # args = parser.parse_args() + + # 设置执行方式 + context.set_context(mode=context.GRAPH_MODE, device_target="CPU") + # context.set_context(mode=context.PYNATIVE_MODE, device_target='GPU') + # context.set_context(mode=context.PYNATIVE_MODE, device_target=args.device_target)) + # context.set_context(mode=context.GRAPH_MODE, device_target=args.device_target)) + + start_time = time.time() + # 创建网络 + net = networks.DSNet() + # 定义优化器 + optim = nn.Adam(params=net.trainable_params(), learning_rate=learning_rate) + # 定义损失函数 + """优化模型参数""" + criterion = MyLoss() + # 定义模型 + model = Model(network=net, loss_fn=criterion, optimizer=optim, metrics={"Accuracy": Accuracy()}) + # 保存网络模型和参数,以便后续进行微调 + config_ck = CheckpointConfig(save_checkpoint_steps=500, keep_checkpoint_max=10) + # 将层分组为具有训练和评估功能的对象 + ckpoint_cb = ModelCheckpoint(prefix="checkpoint_DSNet", directory=r".\checkpoints", + config=config_ck) + # 定义step_loss字典,用于保存loss值和step number信息 + step_loss = {"step": [], "loss_value": []} + # 保存steps和损失信息 + step_loss_info = StepLossInfo() + # 开始训练模型 + train_net(model, ckpoint_cb, step_loss_info) + # # 保存loss记录 + save_loss(step_loss) + plot_loss(step_loss) + + # # 加载模型参数进行再训练 + # param_dir = os.path.join(PARAM_DIR, PARAM_FILE + ".ckpt") + # param_dict = load_checkpoint(param_dir) + # load_param_into_net(net, param_dict) + # load_param_into_net(optim, param_dict) + # model = Model(network=net, loss_fn=criterion, optimizer=optim, metrics={"Accuracy": Accuracy()}) + # train_net(model, ckpoint_cb, step_loss_info) + # save_loss(step_loss) + # plot_loss(step_loss) + + print('The total time cost is: {}s'.format(time.time() - start_time)) -- Gitee