• 深度学习项目示例 使用自编码器进行模糊图像修复


    图像模糊是由相机或拍摄对象移动、对焦不准确或使用光圈配置不当导致的图像不清晰。为了获得更清晰的照片,我们可以使用相机镜头的首选焦点重新拍摄同一张照片,或者使用深度学习知识重现模糊的图像。由于我的专长不是摄影,只能选择使用深度学习技术对图像进行去模糊处理!

    在开始这个项目之前,本文假定读者应该了解深度学习的基本概念,例如神经网络、CNN。还要稍微熟悉一下 Keras、Tensorflow 和 OpenCV。

    有各种类型的模糊——运动模糊、高斯模糊、平均模糊等。但我们将专注于高斯模糊图像。在这种模糊类型中,像素权重是不相等的。模糊在中心处较高,在边缘处按照钟形曲线减少。

    数据集

    在开始使用代码之前,首先需要的是一个由 2 组图像组成的数据集——模糊图像和干净图像。目前可能没有现成的数据集可以使用,但是就像我们上面所说的,如果你有opencv的基础这个对于我们来说是非常个简单的,只要我们有原始图像,使用opencv就可以自己生成训练需要的数据集。

    这里我的数据集大小约为 50 张图像(50 张干净图像和 50 张模糊图像),因为只是演示目的所以只选择了少量图像。

    编写代码

    已经准备好数据集,可以开始编写代码了。

    依赖项

    1. import numpy as np
    2. import pandas as pd
    3. import matplotlib.pyplot as plt
    4. %matplotlib inline
    5. import random
    6. import cv2
    7. import os
    8. import tensorflow as tf
    9. from tqdm import tqdm

    这里导入了 tqdm 库来帮助我创建进度条,这样可以知道运行代码需要多长时间。

    导入数据

    1. good_frames = '/content/drive/MyDrive/mini_clean'
    2. bad_frames = '/content/drive/MyDrive/mini_blur'

    现在创建了2 个列表。我们将使用 keras 预处理库读取“.jpg”、“jpeg”或“.png”类型的图像,并转换为数组。这里图像尺寸为 128x128。

    1. clean_frames = []
    2. for file in tqdm(sorted(os.listdir(good_frames))):
    3. if any(extension in file for extension in ['.jpg', 'jpeg', '.png']):
    4. image = tf.keras.preprocessing.image.load_img(good_frames + '/' + file, target_size=(128,128))
    5. image = tf.keras.preprocessing.image.img_to_array(image).astype('float32') / 255

    完整文章:

    https://www.overfit.cn/post/d9b6d1a979a444f39c34edc47c647be6

    1. clean_frames.append(image)
    2. clean_frames = np.array(clean_frames)
    3. blurry_frames = []
    4. for file in tqdm(sorted(os.listdir(bad_frames))):
    5. if any(extension in file for extension in ['.jpg', 'jpeg', '.png']):
    6. image = tf.keras.preprocessing.image.load_img(bad_frames + '/' + file, target_size=(128,128))
    7. image = tf.keras.preprocessing.image.img_to_array(image).astype('float32') / 255
    8. blurry_frames.append(image)
    9. blurry_frames = np.array(blurry_frames)

    导入模型库

    1. from keras.layers import Dense, Input
    2. from keras.layers import Conv2D, Flatten
    3. from keras.layers import Reshape, Conv2DTranspose
    4. from keras.models import Model
    5. from keras.callbacks import ReduceLROnPlateau, ModelCheckpoint
    6. from keras.utils.vis_utils import plot_model
    7. from keras import backend as K
    8. random.seed = 21
    9. np.random.seed = seed

    将数据集拆分为训练集和测试集

    现在我们按 80:20 的比例将数据集分成训练和测试集。

    完整文章:

    https://www.overfit.cn/post/d9b6d1a979a444f39c34edc47c647be6

  • 相关阅读:
    GitHub转华为软件开发云详细教程
    如何将项目管理从禅道迁移到华为软件开发云
    华为CloudIDE免费公测,带你出坑带你飞
    闲谈 | 敏捷宣言说了什么
    Eclipse安装Git插件以及通过Git导入华为软件开发云项目
    终于等到你!MobileTest免费公测,华为带你走出安卓适配大坑
    华为软件开发云测评报告三:测试管理
    华为软件开发云发布管理测评报告
    你真的知道敏捷和迭代吗?
    ThoughtWorks、Teambition、Trello、Slack、DevCloud 主流敏捷软件开发工具平台比较
  • 原文地址:https://www.cnblogs.com/deephub/p/16085435.html
Copyright © 2020-2023  润新知