2019-02-02

A、用GAN生成新的图像和groundtruth

10:49~11:30 找到GAN的代码:最好是Python3+pytorch的(tensorflow也没事)

(tip:可以找李宏毅的作业3的代码)

搜索关键词:MLDS hw3-1

https://github.com/WaitingLin/Image_generation/blob/master/gan.py

https://github.com/perry0513/MLDS_hw3 (我打算用这个程序去跑)

I. 研究代码一

1、直接运行,一步一步解决报错

问题1:安装完之后再python环境里import tensorflow还是显示没有这个模块

参考自己之前的日记吧。

https://www.jianshu.com/writer#/notebooks/27519393/notes/30773541

还是自己的日记靠谱。安装成功。

import tensorflow的时候import成功。

问题2:在data_processor里导入cv2导入不成功

参考网站:https://blog.csdn.net/qq_32846595/article/details/79264071

问题3:研究图像存放路径

在data_processor.py中,我们发现:图片存放路径为:“./AnimeDataset/extra_data/images/”

问题4:代码中的extra_face.npy文件是啥?

暂时还不知道

问题5:报错如下:

ValueError: Variable discriminator/conv2d/kernel/RMSProp/ already exists, disallowed. Did you mean to set reuse=True or reuse=tf.AUTO_REUSE in VarScope? Originally defined at:

果然有人跟我遇到过一样的问题哎,比如这个网站:https://stackoverflow.com/questions/47296969/valueerror-variable-rnn-basic-rnn-cell-kernel-already-exists-disallowed-did-y

我先试试解决办法1:tf.reset_default_graph() 果然没有报一样的错误了。

我再试试解决办法2:把上面那句话注释掉,然后restart一遍,依旧成功了。(*^▽^*)

问题6:在data_process里的imread那里报错了

Spyder的断点调试(之前只用过Pycharm的断点调试)


13133110-833e37a6bdc1ffbb.png

从左往右是 开始调试,逐行运行,查看本行中的函数、方法的代码,把所在的函数、方法运行完,运行到下一个断点,结束调试。

这句报错其实就单独运行这一句就好啦。

果然我单独写了一个程序:

import cv2

a = cv2.imread('./AnimeDataset/extra_data/images/'+'1'+".jpg")

print(a)

发现a是空的哎

(原来自己什么都没有往文件夹里面放啊  蠢死了) 丢了101个图进去。

但是这里还是报错,于是我进行了print(i) 

我想看看是哪一个i读不出来。

但是报错:inconsistent use of tabs and spaces in indentation

明白原因了!!!!image_sum是自己取的数字,取的是image_sum为36739。

换成101就可以啦!

问题7:参数在哪里传进去呀?首先你要用GAN,而不是WGAN

if type == 'gan':

model = GAN(noise_dim)

elif type == 'dcgan':

model = DCGAN(noise_dim)

else:

model = WGAN(noise_dim)

我把这里改成了:

if type == 'wgan':

model = WGAN(noise_dim)

elif type == 'dcgan':

model = DCGAN(noise_dim)

else:

model = GAN(noise_dim)

这样运行的就是GAN的程序。

问题8:

Trying to share variable generator/dense/kernel, but specified shape (128, 512) and found shape (128, 6144).

这个问题我暂时解决不来。。。。

II. 研究代码二

https://github.com/WaitingLin/Image_generation

我在文件夹下建立了一个新的文件夹dataset,再建立一个faces文件夹,里面放入编号为0~100的101个图

服务器上没有tensorflow,需要自己装。

缺哪个包,就 pip install 哪个包 就可以了。

重要:在Linux上安装tensorflow

报错:“Could not find a version that satisfies the requirement tensorflow-gpu (from versions: )No matching distribution found for tensorflow-gpu” 

好像python3.6要用pip3安装tensorflow的哎!

试试看能不能用anaconda进行安装。

参考网站:https://blog.csdn.net/hgdwdtt/article/details/78633232\

在没有sudo的情况下在Linux上的python3的环境下安装tensorflow的方法

1、创建一个conda环境:conda create -n tensorflow python=3.6

2、激活这个环境:source activate tensorflow

3、在这个环境下安装:pip install --upgrade tensorflow就可以了

注意:但是其他的包也要全部重新安装一遍的。。。。。

在自己建立的tensorflow环境下安装PIL包

pip install Pillow

于是顺利开始了pretrain discriminator了。(其实我觉得叫做train就可以了为什么叫做pretrain呢?(自己查原因))

这里注意:training_path和img_dir的区别,以及model_dir

这段代码还是不行,跑不出来。

III、研究代码三

https://github.com/carpedm20/DCGAN-tensorflow

1、先按照他的步骤跑他的代码

2、带入自己的数据跑代码

这次肯定能跑出来的!

(1)在主文件夹下,新建一个data的文件夹。再新建一个文件夹,比如命名为face,再放图片进去。原来的代码里的图片一般是jpg形式的。

(2)自己查看了运行参数:

readme中的两行train的代码如下:

python main.py --dataset mnist --input_height=28 --output_height=28 --train

input_height:"The size of image to use (will be center cropped).”

output_height:“The size of the output images to produce ”  比如如果是64的话,那么输出则是64*64

test运行代码:

python main.py --dataset cell --input_height=1024 --output_height=1024

结果存在sample文件夹

(3)那么自己运行的时候

首先,batchsize改成2.

其次,train的命令行代码为:

python main.py --dataset cell --input_height=1024 --output_height=1024 --train

欧对 记得激活tensorflow环境,在

记得在main里改图片格式 改成tif

改了main.py这一行:flags.DEFINE_string("input_fname_pattern", "*.tif", "Glob pattern of filename of input images [*]")

改了modle.py的第21行:input_fname_pattern='*.tif', checkpoint_dir=None, sample_dir=None, data_dir='./data'):

结果好像有一点OOM了。

所以batchsize取1,然后epoch取10,试试看?

13133110-3cea2ac4d749a1da.png

都oom了居然还能跑epoch.....那等会看看结果吧。。。。。。

test的代码为:python main.py --dataset mnist --input_height=1024 --output_height=1024

改为:

python main.py --dataset cell --input_height=256 --output_height=256

效果还是很差。我觉得问题出现在load failed上面,明天再去研究

B、做完object evaluation

1、用到的软件是ITKsnap和imageJ

2、imageJ自己下载过了。所以先下载ITKsnap

猜你喜欢

转载自blog.csdn.net/weixin_34409741/article/details/87012329
02