• 吴裕雄--天生自然神经网络与深度学习实战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()

  • 相关阅读:
    计算机方向的一些顶级会议和期刊—Top Conferences and Journals in Computer Science
    jvm dns缓存问题解决方式
    eclipse调试过程中插入代码执行
    Spring Atomikos分布式事务
    spring quartz 注解配置定时任务
    web系统性能分析JavaMelody
    收集到几种开源NLP工具
    记录些实用的linux指令串
    javamelody对Java Application进行监控
    解决ssh连接问题1
  • 原文地址:https://www.cnblogs.com/tszr/p/12237930.html
Copyright © 2020-2023  润新知