当前位置:网站首页>VARIATIONAL IMAGE COMPRESSION WITH A SCALE HYPERPRIOR文献实验复现
VARIATIONAL IMAGE COMPRESSION WITH A SCALE HYPERPRIOR文献实验复现
2022-07-02 01:31:00 【小夭。】
前言
这篇文章是在END-TO-END OPTIMIZED IMAGE COMPRESSION文献基础上进行的改进,主要是加入了超先验网络对边信息进行了处理。相关环境配置与基础可以参考END-TO-END OPTIMIZED IMAGE COMPRESSION
github地址:github
1、相关命令
(1)训练
python bmshj2018.py -V train
同样,我这里方便调试,加入了launch.json
{
// 使用 IntelliSense 了解相关属性。
// 悬停以查看现有属性的描述。
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Python: 当前文件",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal",
"justMyCode": true,
// bmshj2018
"args": ["--verbose","train"] // 训练
}
]
}
2、数据集
if args.train_glob:
train_dataset = get_custom_dataset("train", args)
validation_dataset = get_custom_dataset("validation", args)
else:
train_dataset = get_dataset("clic", "train", args)
validation_dataset = get_dataset("clic", "validation", args)
validation_dataset = validation_dataset.take(args.max_validation_steps)
给定数据集地址的情况下使用对应数据集,否则使用默认CLIC数据集
3、整理训练流程
整个代码其实主要还是在bls2017.py上进行的补充,所以整个流转流程是和bls2017的过程一样,这里我简单整理一下这篇文献的训练过程
实例化对象
init中初始化一些参数(LocationScaleIndexedEntropyModel、ContinuousBatchedEntropyModel两个熵模型中所需参数,对应的模型说明可以见tfc熵模型,具体的参数有scale_fn以及给定的num_scales)
初始化非线性分析变换、非线性综合变换、超先验非线性分析变换、超先验非线性综合变换、添加均匀噪声、获得先验概率等
call中通过两个熵模型计算
(1)x->y(非线性分析变换)
(2)y->z(超先验非线性分析变换)
(3)z->z_hat、边信息bit数(ContinuousBatchedEntropyModel熵模型)
(4)y->y_hat、比特数(LocationScaleIndexedEntropyModel熵模型)
(5)计算bpp(这里bpp=bit/px,bit数等于上面两项bit数相加)、mse、loss
其中非线性分析变换即cnn卷积的过程,其中有一步补零的过程是为了输入与输出图片尺寸相等model.compile
通过model.compile配置训练方法,使用优化器进行梯度下降、算bpp、mse、lose的加权平均过滤剪裁数据集
通过参数查看是否给定了数据集路径
给定数据集路径:直接剪裁成256x256(统一剪裁成256*256送入网络训练,后面压缩的图片不会改变大小)
未给定数据集路径:用CLIC数据集,过滤出图片大小大于256x256的三通的图片,然后进行剪裁
分出训练数据集与验证数据集model.fit
传入训练数据集,设置相关参数(epoch等)进行训练
通过retval = super().fit(*args, **kwargs)
进入model的train_step(不得不说这里封装的太严实了…但从单文件的代码根本找不到怎么跳进去的)train_step
self.trainable_variables获取变量集,通过传入变量集与定义的损失函数,进行前向传播与反向误差传播更新参数。然后更新loss, bpp, mse
def train_step(self, x):
with tf.GradientTape() as tape:
loss, bpp, mse = self(x, training=True)
variables = self.trainable_variables
gradients = tape.gradient(loss, variables)
self.optimizer.apply_gradients(zip(gradients, variables))
self.loss.update_state(loss)
self.bpp.update_state(bpp)
self.mse.update_state(mse)
return {
m.name: m.result() for m in [self.loss, self.bpp, self.mse]}
- 接下来就是重复训练的过程,直到到终止条件(比如epoch达到10000)
4、压缩一张图片
python bmshj2018.py [options] compress original.png compressed.tfci
这里通过launch.json调试
"args": ["--verbose","compress","./models/kodak/kodim01.png", "./models/kodim01.tfci"] // 压缩一张图
引入你自己的path
边栏推荐
- Learn C language from scratch day 025 (maze)
- Bat Android Engineer interview process analysis + restore the most authentic and complete first-line company interview questions
- Basic usage of three JS high-order functions --filter---map---reduce
- How can the tsingsee Qingxi platform play multiple videos at the same time on the same node?
- Part 29 supplement (XXIX) basis of ECMAScript
- Android: the kotlin language uses grendao3, a cross platform app development framework
- 关于ASP.NET CORE使用DateTime日期类型参数的一个小细节
- Brief introduction to the development of mobile network
- [Maya] the error of importing Maya into Metahuman
- MySQL winter vacation self-study 2022 12 (4)
猜你喜欢
学习笔记24--多传感器后融合技术
Liteos learning - first knowledge of development environment
[rust web rokcet Series 2] connect the database and add, delete, modify and check curd
SAP ui5 beginner tutorial 20 - explanation of expression binding usage of SAP ui5
The concept and application of Cartland number
卷積神經網絡(包含代碼與相應圖解)
【图像增强】基于Frangi滤波器实现血管图像增强附matlab代码
Memorabilia of domestic database in June 2022
Docker安装Oracle_11g
Learn C language from scratch day 025 (maze)
随机推荐
Single chip microcomputer -- hlk-w801 transplant NES simulator (III)
k线图形态这样记(口诀篇)
[IVX junior engineer training course 10 papers] 06 database and services
遷移雲計算工作負載的四個基本策略
【疾病检测】基于BP神经网络实现肺癌检测系统含GUI界面
Réseau neuronal convolutif (y compris le Code et l'illustration correspondante)
Mathematics - feelings -20220215
Learning note 24 - multi sensor post fusion technology
Sql--- related transactions
Another programmer "deleted the library and ran away", deleted the code of the retail platform, and was sentenced to 10 months
matlab 使用 audioread 、 sound 读取和播放 wav 文件
MPLS experiment operation
Appium inspector can directly locate the WebView page. Does anyone know the principle
技术大佬准备就绪,话题C位由你决定
微信小程序中使用tabBar
Exclusive delivery of secret script move disassembly (the first time)
Pyldavis installation and use | attributeerror: module 'pyldavis' has no attribute' gensim '| visual results are exported as separate web pages
Error creating bean with name ‘stringRedisTemplate‘ defined in class path re
学习笔记3--高精度地图关键技术(上)
Minimize the error