反卷积_上采样对比

本文介绍了一种使用自编码器对MNIST手写数字数据集进行图像去噪的方法。通过构建卷积自编码器和上采样自编码器,实现了对加噪图像的有效恢复。实验结果显示,两种自编码器均能在保持较高准确率的同时降低损失,有效提升了图像质量。
import tensorflow as tf
import numpy as np
import matplotlib.pyplot as plt
from tensorflow.compat.v1 import ConfigProto
from tensorflow.compat.v1 import InteractiveSession

#config = ConfigProto()
#config.gpu_options.allow_growth = True
#session = InteractiveSession(config=config)
(x_train,x_label),(y_train,y_label)=tf.keras.datasets.mnist.load_data()
x_train.shape,y_train.shape
((60000, 28, 28), (10000, 28, 28))
x_train = x_train.astype('float32')
y_train = y_train.astype('float32')
x_train = x_train/255
y_train = y_train/255
x_train = np.reshape(x_train,(len(x_train),28,28,1))
y_train = np.reshape(y_train,(len(y_train),28,28,1))
y_train.shape
(10000, 28, 28, 1)
noise_factor = 0.5
noise_x = x_train + noise_factor*np.random.normal(loc=0.0, scale=1.0, size=x_train.shape)
noise_y = y_train + noise_factor*np.random.normal(loc=0.0, scale=1.0, size=y_train.shape)
n = 20
plt.figure(figsize=(60, 12))    # 指定宽为20,高为4
for i in range(1, 11):
    ax = plt.subplot(2, n/2, i)  # 表示将设置为2行,n/2列,当前位置在i。
    plt.imshow(x_train[i].reshape(28, 28))
    plt.gray()
    ax.get_xaxis().set_visible(False)
    ax.get_yaxis().set_visible(False)
    ax = plt.subplot(2, n/2, 10+i)
    plt.imshow(noise_x[i].reshape(28, 28))
    plt.gray()
    ax.get_xaxis().set_visible(False)
    ax.get_yaxis().set_visible(False)
plt.show()

在这里插入图片描述

input = tf.keras.layers.Input(shape=(28,28,1))
x1 = tf.keras.layers.Conv2D(32,(3,3),padding='same',activation = 'relu',name = 'x1')(input) #变为28*28*32
x2 = tf.keras.layers.MaxPooling2D(pool_size=(2, 2),strides=(2, 2),padding='same',name = 'x2')(x1) #变为14*14*32
x3 = tf.keras.layers.Conv2D(64,(3,3),padding='same',activation = 'relu',name = 'x3')(x2)#变为14*14*64
x4 = tf.keras.layers.MaxPooling2D
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

潘诺西亚的火山

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值