当前位置:网站首页>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
边栏推荐
- Penser au jeu 15: penser au service complet et au sous - service
- 电子协会 C语言 1级 32、计算2的幂
- 人工智能在网络安全中的作用
- Docker installing Oracle_ 11g
- No converter found for return value of type: class
- [Chongqing Guangdong education] Tianshui Normal University universe exploration reference
- 关于ASP.NET CORE使用DateTime日期类型参数的一个小细节
- Memorabilia of domestic database in June 2022
- What are the affordable Bluetooth headsets? Student party parity Bluetooth headset recommendation
- 机器学习基本概念
猜你喜欢
MySQL application day02
How to compress video size while adding watermark with one click?
The technology boss is ready, and the topic of position C is up to you
[rust web rokcet Series 2] connect the database and add, delete, modify and check curd
SQL injection for Web Security (2)
How can I batch produce the same title for the video?
Game thinking 15: thinking about the whole region and sub region Services
Basic concepts of machine learning
The pain of Xiao Sha
II Basic structure of radio energy transmission system
随机推荐
error: . repo/manifests/: contains uncommitted changes
微信小程序中使用tabBar
站在新的角度来看待产业互联网,并且去寻求产业互联网的正确方式和方法
I'll teach you to visit Amazon RDS for a year and build a MySQL cloud database (only 10 minutes, really fragrant)
Bubble Sort Graph
It's already 30. Can you learn programming from scratch?
CTF daily question day45 sensor
Edge computing accelerates live video scenes: clearer, smoother, and more real-time
[IVX junior engineer training course 10 papers] 05 canvas and aircraft war game production
[IVX junior engineer training course 10 papers] 06 database and services
遊戲思考15:全區全服和分區分服的思考
Error creating bean with name ‘stringRedisTemplate‘ defined in class path re
Memorabilia of domestic database in June 2022
基于SSM实现微博系统
Error creating bean with name ‘stringRedisTemplate‘ defined in class path re
浅浅了解Servlet
SAP ui5 beginner tutorial 20 - explanation of expression binding usage of SAP ui5
Single chip microcomputer -- hlk-w801 transplant NES simulator (III)
Android high frequency network interview topic must know and be able to compare Android development environment
Fastadmin controls the length of fields in the table