marta gan代码过程

执行的是:MARTAGANs-master 程序。另外一个MARTA-GAN-master里面有问题,未攻克。

# MARTA-GANs
This is the code for [MARTA GANs: Unsupervised Representation Learning for Remote Sensing Image Classification](https://arxiv.org/abs/1612.08879). An multiple-layer feature-matching generative adversarial networks (MARTA GANs) to learn a representation using only unlabeled data.  



## Prepare data

Download and unzip dataset from [BaiDuYun](https://pan.baidu.com/s/1i5zQNdj) or [Google Drive](https://drive.google.com/open?id=0B1Evui8Soh85ZXM3cDNvbGdOamc).

## Dependencies

NVIDIA GPU + CUDA CuDNN (CPU mode and CUDA without CuDNN mode are also available but significantly slower)

- tensorflow
- tensorlayer
- sklearn

## Usage

Training GAN
```
python train_gan.py
```

Extract features
```
python features.py
```

Training SVM

```
python train_svm.py
```

## Citation
If you find this code useful for your research, please cite:
```
@article{lin2017marta,
  title={MARTA GANs: Unsupervised Representation Learning for Remote Sensing Image Classification},
  author={Lin, Daoyu and Fu, Kun and Wang, Yang and Xu, Guangluan and Sun, Xian},
  journal={IEEE Geoscience and Remote Sensing Letters},
  year={2017},
  publisher={IEEE}
}
```

因为python3.6和tensorflow1.0以上的版本,导致好多库缺少,所以遇到很多坑,最终终于搞定了。

1、相关库安装:

ModuleNotFoundError: No module named 'chardet'

pip install chardet

ModuleNotFoundError: No module named 'urllib3'

import urllib.request #原来是urllib3

Traceback (most recent call last):
  File "/home/gden/.local/lib/python3.6/site-packages/requests/exceptions.py", line 9, in <module>
    from urllib3.exceptions import HTTPError as BaseHTTPError # 无urllib3
ModuleNotFoundError: No module named 'urllib3'

pip uninstall urllib3
pip install --no-cache-dir -U urllib3
pip uninstall chardet
pip install --no-cache-dir -U chardet

    locals()[package] = __import__(package)
ModuleNotFoundError: No module named 'idna'

pip install idna

    from lxml import etree
ModuleNotFoundError: No module named 'lxml'

pip install  lxml

扫描二维码关注公众号,回复: 4220206 查看本文章

pip install imageio

 'flag --%s=%s: %s' % (self.name, argument, e))
absl.flags._exceptions.IllegalFlagValueError: flag --train_size=inf: Expect argument to be a string or int, found <class 'float'>

#flags.DEFINE_integer("train_size", np.inf, "The size of train images [np.inf]") # np.inf是浮点数 无穷大的数
flags.DEFINE_float("train_size", np.inf, "The size of train images [np.inf]")

或者上面的np.inf用sys.maxsize代替

Traceback (most recent call last):
  File "/home/gden/PycharmProjects/MARTA-GAN-master/extract_feature.py", line 179, in <module>
    tf.app.run()
  File "/home/gden/.local/lib/python3.6/site-packages/tensorflow/python/platform/app.py", line 125, in run
    _sys.exit(main(argv))
  File "/home/gden/PycharmProjects/MARTA-GAN-master/extract_feature.py", line 62, in main
    net_d, d_logits, features = discriminator_simplified_api(real_images, is_train=FLAGS.is_train, reuse=False)
  File "/home/gden/PycharmProjects/MARTA-GAN-master/network.py", line 121, in discriminator_simplified_api
    feature = ConcatLayer(layer = [global_max1, global_max2, global_max3], name ='d/concat_layer1')
TypeError: __init__() got an unexpected keyword argument 'layer'

结果:

Epoch: 0030 d_cost= 1.386294365 g_cost= 3.185708287
Model saved in path: checkpoint/uc_train_256_data_64_256

执行 features.py时候出现问题:

# d_netx, Dx, Dfx =  network.discriminator(x, is_train=FLAGS.is_train, reuse=False)

发现该函数定义时候返回两个值,但是这里指定3个值,把第一个去掉

Dx, Dfx = network.discriminator(x, is_train=FLAGS.is_train, reuse=False)

即可顺利执行,生产几个.npy文件在features文件夹下。就可以继续执行svm训练了

在笔记本windows上跑DCGAN----tensorflow-cpu

2018年05月17日 22:11:50 IGIli 阅读数:955更多

个人分类: Deep Learning

版权声明:本文为博主原创文章,转载注明博主博客地址。 https://blog.csdn.net/IGIli/article/details/80357157

偶然的一次机会帮别人调程序,发现DCGAN在1080ti上占用显存只有600M左右,我想是不是可以笔记本上跑一下,本着玩一玩的心态,跑了一下,虽然很慢大约30s左右一张图片,但是可以当做练手的。先贴一下古董笔记本cpu。

因为之前跑过一些python程序,opencv,svm,爬虫啥的,电脑上有python2.7和python3.6。DCGAN在python2.7和python3.6是都可以跑通的。

cpu版本的tensorflow安装

使用的是原生pip安装,官网写的很清楚,window下只支持python3.5.x 64位和python3.6.x 64位,python3附带有pip3软件包管理器,可以使用此程序安装cpu版本的tensorflow。

输入以下命令:

C:\> pip3 install --upgrade tensorflow

验证安装

可以从shell中调用python,如下所示:

$ python

在 Python 交互式 shell 中输入以下几行简短的程序代码:

 
  1. >>> import tensorflow as tf

  2. >>> hello = tf.constant('Hello, TensorFlow!')

  3. >>> sess = tf.Session()

  4. >>> print(sess.run(hello))

如果系统输出以下内容,就说明您可以开始编写 TensorFlow 程序了:

Hello, TensorFlow!

依赖库配置:

输入命令

 
  1. pip3 install scipy

  2. .............

  3. pip3 install scikit-image

我只配置了两个依赖库scipy和scikit-image。

代码下载https://github.com/tensorlayer/dcgan

下载好后,cmd需要进入程序所在目录。

首先下载数据集到 dcgan-master/data/celebA:

$ python download.py celebA		[202599 face images]

接下来训练gan

$ python main.py

可能报错:

 
  1. $ python main.py

  2. /home/ly/anaconda3/envs/learning/lib/python3.6/site-packages/h5py/__init__.py:36: FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated. In future, it will be treated as `np.float64 == np.dtype(float).type`.

  3. from ._conv import register_converters as _register_converters

  4. Traceback (most recent call last):

  5. File "/home/ly/anaconda3/envs/learning/lib/python3.6/site-packages/absl/flags/_flag.py", line 166, in _parse

  6. return self.parser.parse(argument)

  7. File "/home/ly/anaconda3/envs/learning/lib/python3.6/site-packages/absl/flags/_argument_parser.py", line 152, in parse

  8. val = self.convert(argument)

  9. File "/home/ly/anaconda3/envs/learning/lib/python3.6/site-packages/absl/flags/_argument_parser.py", line 268, in convert

  10. type(argument)))

  11. TypeError: Expect argument to be a string or int, found <class 'float'>

  12.  
  13. During handling of the above exception, another exception occurred:

  14.  
  15. Traceback (most recent call last):

  16. File "main.py", line 23, in <module>

  17. flags.DEFINE_integer("train_size", np.inf, "The size of train images [np.inf]")

  18. File "/home/ly/anaconda3/envs/learning/lib/python3.6/site-packages/tensorflow/python/platform/flags.py", line 58, in wrapper

  19. return original_function(*args, **kwargs)

  20. File "/home/ly/anaconda3/envs/learning/lib/python3.6/site-packages/absl/flags/_defines.py", line 315, in DEFINE_integer

  21. DEFINE(parser, name, default, help, flag_values, serializer, **args)

  22. File "/home/ly/anaconda3/envs/learning/lib/python3.6/site-packages/absl/flags/_defines.py", line 81, in DEFINE

  23. DEFINE_flag(_flag.Flag(parser, serializer, name, default, help, **args),

  24. File "/home/ly/anaconda3/envs/learning/lib/python3.6/site-packages/absl/flags/_flag.py", line 107, in __init__

  25. self._set_default(default)

  26. File "/home/ly/anaconda3/envs/learning/lib/python3.6/site-packages/absl/flags/_flag.py", line 196, in _set_default

  27. self.default = self._parse(value)

  28. File "/home/ly/anaconda3/envs/learning/lib/python3.6/site-packages/absl/flags/_flag.py", line 169, in _parse

  29. 'flag --%s=%s: %s' % (self.name, argument, e))

  30. absl.flags._exceptions.IllegalFlagValueError: flag --train_size=inf: Expect argument to be a string or int, found <class 'float'>

  31.  

解决办法:

在 main.py中的第22行,把

flags.DEFINE_integer("train_size", np.inf, "The size of train images [np.inf]")

改成

flags.DEFINE_float("train_size", np.inf, "The size of train images [np.inf]")

然后就可以正常运行了。这个跑通之后建议跑另外一个dcgan,比较详细。https://github.com/carpedm20/DCGAN-tensorflow

正常运行如下图:

猜你喜欢

转载自blog.csdn.net/gdengden/article/details/84451307
GAN