TecoGAN图像增强

环境

  • windows 10 64-bit
  • python 3.7
  • TecoGAN
  • tensorflow 1.15.0
  • pytorch 1.7

简介

TecoGAN 是一个基于 GAN 的自监督学习的图像增强器,也就是能让原来模糊的图像变得清晰, TecoTEmporal COherence 的缩写。原作者的介绍视频地址:https://www.youtube.com/watch?v=pZXFXtfd-Ak,论文地址: https://arxiv.org/pdf/1811.09393.pdf

TecoGAN图像增强

TecoGAN

TecoGAN图像增强

TecoGAN

TecoGAN图像增强

TecoGAN

从官方效果图来看,非常令人惊叹。

[En]

Judging from the official effect picture, it is very amazing.

项目体验

下载源码

git clone https://github.com/thunil/TecoGAN.git
cd TecoGAN

安装依赖

# 要求1.8以上,太高也会报错
pip install tensorflow-gpu==1.15.0
pip install -r requirements.txt

下载模型及数据

python runGAN.py 0

开始推理

python runGAN.py 1

默认处理文件夹 LR/calendar,处理后的结果存放于文件夹 results/calendar

使用自己的素材

目前只支持图片,所以是视频的话,就需要将其转成图片序列,放在一个文件夹内如 test,然后将文件夹 test 放到目录 LR下,修改文件 runGAN.py

elif( runcase == 1 ): # inference a trained model

    dirstr = './results/' # the place to save the results

    # 由默认的calendar改为test
    # testpre = ['calendar'] # the test cases
    testpre = ['test'] # the test cases

    if (not os.path.exists(dirstr)): os.mkdir(dirstr)

    # run these test cases one by one:
    for nn in range(len(testpre)):
        cmd1 = ["python3", "main.py",
            "--cudaID", "0",            # set the cudaID here to use only one GPU
            "--output_dir",  dirstr,    # Set the place to put the results.
            "--summary_dir", os.path.join(dirstr, 'log/'), # Set the place to put the log.
            "--mode","inference",
            "--input_dir_LR", os.path.join("./LR/", testpre[nn]),   # the LR directory
            #"--input_dir_HR", os.path.join("./HR/", testpre[nn]),  # the HR directory
            # one of (input_dir_HR,input_dir_LR) should be given
            "--output_pre", testpre[nn], # the subfolder to save current scene, optional
            "--num_resblock", "16",  # our model has 16 residual blocks,
            # the pre-trained FRVSR and TecoGAN mini have 10 residual blocks
            "--checkpoint", './model/TecoGAN',  # the path of the trained model,
            "--output_ext", "png"               # png is more accurate, jpg is smaller
        ]
        mycall(cmd1).communicate()

从上面的代码片段,可以看出,其原理是通过系统调用的方式去处理每一张图片,具体的逻辑实现是在文件 main.py

然后执行

python runGAN.py

处理后的图片存放在目录 results/test

遇到的坑

tensorflow

基本上,这些问题是由版本差异引起的。

[En]

Basically, the problems are caused by version differences.

问题一

"ImportError: cannot import name 'export_saved_model' from 'tensorflow.python.keras.saving.saved_model'"

这通常是因为安装了多个版本,所以您需要先卸载CLEAN,然后再安装相应的版本。

[En]

This is usually caused by the installation of multiple versions, so you need to uninstall clean first, and then install the corresponding version.

pip uninstall tensorflow-gpu
pip install tensorflow-gpu==1.15.0

问题二

ImportError: cannot import name 'get_config' from 'tensorflow.python.eager.context'

修改文件 lib/ops.py,将 import keras 改为 from tensorflow import keras

问题三

ModuleNotFoundError: No module named 'tensorflow.contrib'

tensorflow 从 1.15版本后将 tensorflow.contrib 移除,可安装 1.14版本

pip install tensorflow-gpu==1.15.0

问题四

AttributeError: module 'tensorflow' has no attribute 'set_random_seed'

修改文件 main.py,将 tf.set_random_seed(1234) 改为 tf.random.set_seed(1234)

skimage

ImportError: cannot import name 'compare_ssim' from 'skimage.measure'

这是版本更新后的 api 变化引起的

TecoGAN图像增强

tecogan

解决方法是安装较低版本,如0.16.2

[En]

The workaround is to install a lower version, such as 0.16.2

pip install -U scikit-image==0.16.2

numpy

NotImplementedError: Cannot convert a symbolic Tensor (2nd_target:0) to a numpy array

这里要求 numpy 版本不要过高

pip install numpy==1.19.5

wget

'wget' 不是内部或外部命令,也不是可运行的程序

如果是 windows 系统,默认是没有 wget 工具的,工程中会使用它来下载数据包。下载地址 https://eternallybored.org/misc/wget/,然后将下载后的可执行 exe 文件拷贝到目录 C:\Windows\System32

参考资料

  • https://github.com/thunil/TecoGAN

知识星球

在新的知识星球上,目标每天都在更新。共享各类学习资源、实践项目、付费项目、私人工作分享、资源对接、行业资讯等,欢迎扫码加盟。

[En]

The new knowledge planet, the target is updated daily. Share all kinds of learning resources, practical projects, paid projects, private work sharing, resource docking, industry information, etc. Welcome to scan the code to join.

TecoGAN图像增强

Original: https://blog.csdn.net/djstavaV/article/details/121987672
Author: 迷途小书童的Note
Title: TecoGAN图像增强

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/511204/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

亲爱的 Coder【最近整理,可免费获取】👉 最新必读书单  | 👏 面试题下载  | 🌎 免费的AI知识星球