执行的是:MARTAGANs-master 程序。另外一个MARTA-GAN-master里面有问题,未攻克。
# MARTA-GANs This is the code for [MARTA GANs: Unsupervised Representation Learning for Remote Sensing Image Classification](.08879). An multiple-layer feature-matching generative adversarial networks (MARTA GANs) to learn a representation using only unlabeled data. ## Prepare dataDownload and unzip dataset from [BaiDuYun]() or [Google Drive](=0B1Evui8Soh85ZXM3cDNvbGdOamc).## DependenciesNVIDIA GPU + CUDA CuDNN (CPU mode and CUDA without CuDNN mode are also available but significantly slower)- tensorflow - tensorlayer - sklearn## UsageTraining 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'
quest #原来是urllib3
Traceback (most recent call last):
File "/home/gden/.local/lib/python3.6/site-packages/requests/exceptions.py", line 9, in <module>
ptions 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
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
_it(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训练了
2018年05月17日 22:11:50 IGIli 阅读数:955更多
个人分类: Deep Learning
版权声明:本文为博主原创文章,转载注明博主博客地址。
偶然的一次机会帮别人调程序,发现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 中输入以下几行简短的程序代码:
>>> import tensorflow as tf
>>> hello = tf.constant('Hello, TensorFlow!')
>>> sess = tf.Session()
>>> print(sess.run(hello))
如果系统输出以下内容,就说明您可以开始编写 TensorFlow 程序了:
Hello, TensorFlow!
依赖库配置:
输入命令
pip3 install scipy
.............
pip3 install scikit-image
我只配置了两个依赖库scipy和scikit-image。
代码下载
下载好后,cmd需要进入程序所在目录。
首先下载数据集到 dcgan-master/data/celebA
:
$ python download.py celebA [202599 face images]
接下来训练gan
$ python main.py
可能报错:
$ python main.py
/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`.
from ._conv import register_converters as _register_converters
Traceback (most recent call last):
File "/home/ly/anaconda3/envs/learning/lib/python3.6/site-packages/absl/flags/_flag.py", line 166, in _parse
return self.parser.parse(argument)
File "/home/ly/anaconda3/envs/learning/lib/python3.6/site-packages/absl/flags/_argument_parser.py", line 152, in parse
val = vert(argument)
File "/home/ly/anaconda3/envs/learning/lib/python3.6/site-packages/absl/flags/_argument_parser.py", line 268, in convert
type(argument)))
TypeError: Expect argument to be a string or int, found <class 'float'>
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "main.py", line 23, in <module>
flags.DEFINE_integer("train_size", np.inf, "The size of train images [np.inf]")
File "/home/ly/anaconda3/envs/learning/lib/python3.6/site-packages/tensorflow/python/platform/flags.py", line 58, in wrapper
return original_function(*args, **kwargs)
File "/home/ly/anaconda3/envs/learning/lib/python3.6/site-packages/absl/flags/_defines.py", line 315, in DEFINE_integer
DEFINE(parser, name, default, help, flag_values, serializer, **args)
File "/home/ly/anaconda3/envs/learning/lib/python3.6/site-packages/absl/flags/_defines.py", line 81, in DEFINE
DEFINE_flag(_flag.Flag(parser, serializer, name, default, help, **args),
File "/home/ly/anaconda3/envs/learning/lib/python3.6/site-packages/absl/flags/_flag.py", line 107, in __init__
self._set_default(default)
File "/home/ly/anaconda3/envs/learning/lib/python3.6/site-packages/absl/flags/_flag.py", line 196, in _set_default
self.default = self._parse(value)
File "/home/ly/anaconda3/envs/learning/lib/python3.6/site-packages/absl/flags/_flag.py", line 169, in _parse
'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'>
解决办法:
在 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,比较详细。
正常运行如下图:
本文发布于:2024-01-28 00:07:17,感谢您对本站的认可!
本文链接:https://www.4u4v.net/it/17063716363462.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
留言与评论(共有 0 条评论) |