EnlightenGAN 开源代码运行

EnlightenGAN: Deep Light Enhancement without Paired Supervision工作公布于2019年,论文已被TIP 2021接收,其采用非成对数据训练了一个用于低照度图像增强的对抗生成网络模型,可以显著增强低照度图像的亮度及对比度,表现优异。

论文地址:https://arxiv.org/abs/1906.06972
代码地址:https://github.com/VITA-Group/EnlightenGAN

以下记录运行开源代码的主要步骤及测试过程中遇到的一些问题和解决办法。


源码下载和环境配置比较简单,本文测试环境:Win10 + RTX2060、cuda 11.1、python 3.8 + torch 1.9.0 + numpy 1.20.1

1. 打开visidom.server:

  • 若是Linux系统,执行nohup python -m visdom.server -port=8097,其中nohup用于在后台不挂断地运行命令;
  • Windows系统则直接执行pyhton -m visdom.server -port=8097,而后另开一个终端执行后续操作即可。

上述命令执行过程中可能会出现以下情况:

D:\ProgramData\Anaconda3\lib\site-packages\visdom\server.py:39: DeprecationWarning: zmq.eventloop.ioloop
is deprecated in pyzmq 17. pyzmq now works with default tornado and asyncio eventloops.
  ioloop.install()  # Needs to happen before any tornado imports!
Checking for scripts.
Downloading scripts, this may take a little while

找到visidom的源码中download_scripts_and_run函数,将download_scripts()注释掉,如下图所示:

def download_scripts_and_run():
    # download_scripts()
    main()

再次执行上述命令,结果如下;

D:\ProgramData\Anaconda3\lib\site-packages\visdom\server.py:39: DeprecationWarning: zmq.eventloop.ioloop
is deprecated in pyzmq 17. pyzmq now works with default tornado and asyncio eventloops.
  ioloop.install()  # Needs to happen before any tornado imports!
It's Alive!
INFO:root:Application Started
You can navigate to http://localhost:8097

打开浏览器输入地址http://localhost:8097,即可监测训练进程。

2. 修改测试文件地址:

  • readme.md文件说明,创建测试文件目录,其结构如下:
|——test_dataset
   |——testA
   |——testB 

测试图像放在/testA文件夹下,为了使程序正常运行,需确保在/testB文件夹下至少有一张任意图像。

  • 执行python .\scripts\script.py --predict运行测试程序,可能会出现如下报错:
AssertionError: ../test_dataset\testA is not a valid directory

报错显示提供的测试路径不是有效路径,原因可能是在创建test_dataset时候将其作为项目文件夹的子文件夹,解决方法是将其从项目文件夹移出,使之与项目文件夹在同级目录下,最终测试结果保存在./ablation/enlightening/test_200/images文件夹下。

3. 测试代码运行出错:

  • 在执行python .\scripts\script.py --predict后,终端可能会报错
RuntimeError:
       An attempt has been made to start a new process before the
       current process has finished its bootstrapping phase.

       This probably means that you are not using fork to start your
       child processes and you have forgotten to use the proper idiom
       in the main module:

           if __name__ == '__main__':
               freeze_support()
               ...

       The "freeze_support()" line can be omitted if the program
       is not going to be frozen to produce an executable.

该报错原因是windows下测试时,子进程递归创建导致的,需要修改程序入口,具体做法是,在predict.py中,把要运行的代码段放进if __name__ == '__main__':中,一种可行的修改方案如下:

if __name__ == '__main__':
   freeze_support()
   opt = TestOptions().parse()
   print(opt.which_epoch)
   opt.nThreads = 1   # test code only supports nThreads = 1
   opt.batchSize = 1  # test code only supports batchSize = 1
   opt.serial_batches = True  # no shuffle
   opt.no_flip = True  # no flip

   data_loader = CreateDataLoader(opt)
   dataset = data_loader.load_data()
   model = create_model(opt)
   visualizer = Visualizer(opt)
   # create website
   web_dir = os.path.join("./ablation/", opt.name, '%s_%s' % (opt.phase, opt.which_epoch))
   webpage = html.HTML(web_dir, 'Experiment = %s, Phase = %s, Epoch = %s' % (opt.name, opt.phase, opt.which_epoch))
   # test
   print(len(dataset))
   for i, data in enumerate(dataset):
       model.set_input(data)
       visuals = model.predict()
       img_path = model.get_image_paths()
       print('process image... %s' % img_path)
       visualizer.save_images(webpage, visuals, img_path)

   webpage.save()

4. 最后一点说明:

无论是训练还是测试,都要打开visdom.server

祝好!^_^


你可能感兴趣的:(深度学习,python,计算机视觉,windows)