zoukankan      html  css  js  c++  java
  • 吴裕雄--天生自然神经网络与深度学习实战Python+Keras+TensorFlow:去噪型编码网络

    #为图像像素点增加高斯噪音
    noise = np.random.normal(loc=0.5, scale = 0.5, size = x_train.shape)
    x_train_noisy = x_train + noise
    noise = np.random.normal(loc=0.5, scale = 0.5, size = x_test.shape)
    x_test_noisy = x_test + noise
    #添加噪音值后,像素点值可能会超过1或小于0,我们把这些值调整到[0,1]之间
    x_train_noisy = np.clip(x_train_noisy, 0., 1.)
    x_test_noisy = np.clip(x_test_noisy, 0., 1.)
    autoencoder = Model(inputs, decoder(encoder(inputs)), name = 'autoencoder')
    autoencoder.compile(loss='mse', optimizer='adam')
    autoencoder.fit(x_train_noisy, x_train, validation_data = (x_test_noisy, x_test),
                                                              epochs = 10,
                                                              batch_size = batch_size)

    #获取去噪后的图片
    x_decode = autoencoder.predict(x_test_noisy)
    '''
    将去噪前和去噪后的图片显示出来,第一行是原图片,第二行时增加噪音后的图片,
    第三行时去除噪音后的图片
    '''
    rows , cols = 3, 9
    num = rows * cols
    imgs = np.concatenate([x_test[:num], x_test_noisy[:num], x_decode[:num]])
    imgs = imgs.reshape((rows * 3, cols, image_size, image_size))
    imgs = np.vstack(np.split(imgs, rows, axis = 1))
    imgs = imgs.reshape((rows * 3, -1, image_size, image_size))
    imgs = np.vstack([np.hstack(i) for i in imgs])
    imgs = (imgs * 255).astype(np.uint8)
    plt.figure()
    plt.axis('off')
    plt.title('first row: original image , middle row: noised image, third row: denoised image')
    plt.imshow(imgs, interpolation='none', cmap='gray')
    plt.show()

  • 相关阅读:
    php pdf添加水印(中文水印,图片水印)
    论文阅读---Reducing the Dimensionality of Data with Neural Networks
    Deep Learning综述[下]
    Install-Package:QRCoder已拥有为System.Drawing.Common定义的依赖项
    linux和windows之间传递文件
    IPV6修复工具
    Deep Learning综述[上]
    novaclient开发中遇到的问题小结
    easybcd删除win10启动项如何恢复?
    uefi+gpt安装双系统
  • 原文地址:https://www.cnblogs.com/tszr/p/12237930.html
Copyright © 2011-2022 走看看