一次GAN项目背景下的tensorflow_datasets中mnist数据集的下载笔记

起因:帮我可爱的妹子跑一个GAN的代码(已有,github),这回是在我自己实验室的服务器上(到了展现我男友力的时候了!激动!)

我的背景:第一次 | 正式使用tensorflow | 要开始排坑了 | 我爱Pytorch | 用之前碎碎念

项目地址:https://github.com/google/compare_gan(很基础的一个GAN代码,谷歌大佬发布的)

项目论文:https://arxiv.org/pdf/1406.2661.pdf

一、TF环境安装

1. 建立虚拟环境:conda create -n GAN python=3.6

2. 进入虚拟环境:source activate GAN

3. 确认本地Linux版本是否支持cuda:uname -m && cat /etc/*release【得到反馈 CentOS Linux release 7.3.1611 (Core)】

4. 检查本地gcc是否安装:gcc --version【得到反馈 gcc (GCC) 4.8.5】

5. 开始安装tensorflow:pip install tensorflow-gpu==1.15【得到反馈如下】

ERROR: matplotlib 2.1.2 requires cycler>=0.10, which is not installed.
ERROR: matplotlib 2.1.2 requires pyparsing!=2.0.4,!=2.1.2,!=2.1.6,>=2.0.1, which is not installed.
ERROR: matplotlib 2.1.2 requires pytz, which is not installed.
Installing collected packages: six, google-pasta, astor, numpy, h5py, keras-applications, markdown, absl-py, werkzeug, protobuf, grpcio, tensorboard, tensorflow-estimator, keras-preprocessing, gast, opt-einsum, termcolor, wrapt, tensorflow-gpu
Successfully installed absl-py-0.8.1 astor-0.8.1 gast-0.2.2 google-pasta-0.1.8 grpcio-1.25.0 h5py-2.10.0 keras-applications-1.0.8 keras-preprocessing-1.1.0 markdown-3.1.1 numpy-1.17.4 opt-einsum-3.1.0 protobuf-3.11.1 six-1.13.0 tensorboard-1.15.0 tensorflow-estimator-1.15.1 tensorflow-gpu-1.15.0 termcolor-1.1.0 werkzeug-0.16.0 wrapt-1.11.2

6. 意思是缺少cycler、pyparsing、pytz所以没安成matplotlib,于是:pip install matplotlib【得到反馈 安装成功】

二、安装项目要求环境

1. 按照项目网址提供的方式:https://github.com/google/compare_gan,运行安装setup.py下的依赖

(GAN) [zsun@gpu09 compare_gan]$ pwd
/users4/zsun/tensorflow/compare_gan/compare_gan
(GAN) [zsun@gpu09 compare_gan]$ cd ..
(GAN) [zsun@gpu09 compare_gan]$ pip install -e .

得到反馈

Found existing installation: compare-gan 3.0
    Can't uninstall 'compare-gan'. No files were found to uninstall.
  Running setup.py develop for compare-gan
Successfully installed chardet-3.0.4 compare-gan enum34-1.1.6 future-0.18.2 gin-config-0.1.4 googleapis-common-protos-1.6.0 idna-2.8 pandas-0.25.3 promise-2.2.1 pstar-0.1.9 qj-0.1.6 requests-2.22.0 scipy-1.3.3 tensorflow-datasets-1.0.1 tensorflow-gan-0.0.0.dev0 tensorflow-hub-0.7.0 tensorflow-metadata-0.15.1 tqdm-4.40.2 urllib3-1.25.7

2. 检查TF环境是否装好【最后一行可知,安装成功,这输出这么多,666】

(GAN) [zsun@gpu09 compare_gan]$ python
Python 3.6.9 |Anaconda, Inc.| (default, Jul 30 2019, 19:07:31)
[GCC 7.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
>>> hello = tf.constant('HELLO!')
>>> with tf.Session() as sess:
...     print(sess.run(hello))
...
2019-12-12 11:19:36.965890: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcuda.so.1
2019-12-12 11:19:51.072275: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1618] Found device 0 with properties:
name: Tesla P100-PCIE-16GB major: 6 minor: 0 memoryClockRate(GHz): 1.3285
pciBusID: 0000:04:00.0
2019-12-12 11:19:51.147632: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1618] Found device 1 with properties:
name: Tesla P100-PCIE-16GB major: 6 minor: 0 memoryClockRate(GHz): 1.3285
pciBusID: 0000:06:00.0
2019-12-12 11:19:51.225782: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1618] Found device 2 with properties:
name: Tesla P100-PCIE-16GB major: 6 minor: 0 memoryClockRate(GHz): 1.3285
pciBusID: 0000:07:00.0
2019-12-12 11:19:51.801456: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcudart.so.10.0
2019-12-12 11:19:51.804722: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcublas.so.10.0
2019-12-12 11:19:51.808385: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcufft.so.10.0
2019-12-12 11:19:53.037509: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1746] Adding visible gpu devices: 0, 1, 2
2019-12-12 11:19:53.038331: I tensorflow/core/platform/cpu_feature_guard.cc:142] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA
2019-12-12 11:19:53.061923: I tensorflow/core/platform/profile_utils/cpu_utils.cc:94] CPU Frequency: 2200035000 Hz
2019-12-12 11:19:53.075273: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x7fe6ada91810 initialized for platform Host (this does not guarantee that XLA will be used). Devices:
2019-12-12 11:19:53.075359: I tensorflow/compiler/xla/service/service.cc:176]   StreamExecutor device (0): Host, Default Version
2019-12-12 11:20:48.462150: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x7fe6aa1f53e0 initialized for platform CUDA (this does not guarantee that XLA will be used). Devices:
2019-12-12 11:20:48.462228: I tensorflow/compiler/xla/service/service.cc:176]   StreamExecutor device (0): Tesla P100-PCIE-16GB, Compute Capability 6.0
2019-12-12 11:20:48.462243: I tensorflow/compiler/xla/service/service.cc:176]   StreamExecutor device (1): Tesla P100-PCIE-16GB, Compute Capability 6.0
2019-12-12 11:20:48.462254: I tensorflow/compiler/xla/service/service.cc:176]   StreamExecutor device (2): Tesla P100-PCIE-16GB, Compute Capability 6.0
2019-12-12 11:20:52.105700: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1618] Found device 0 with properties:
name: Tesla P100-PCIE-16GB major: 6 minor: 0 memoryClockRate(GHz): 1.3285
pciBusID: 0000:04:00.0
2019-12-12 11:20:52.163494: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1618] Found device 1 with properties:
name: Tesla P100-PCIE-16GB major: 6 minor: 0 memoryClockRate(GHz): 1.3285
pciBusID: 0000:06:00.0
2019-12-12 11:20:52.230471: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1618] Found device 2 with properties:
name: Tesla P100-PCIE-16GB major: 6 minor: 0 memoryClockRate(GHz): 1.3285
pciBusID: 0000:07:00.0
2019-12-12 11:20:52.861860: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcudart.so.10.0
2019-12-12 11:20:52.862299: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcublas.so.10.0
2019-12-12 11:20:52.862343: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcufft.so.10.0
2019-12-12 11:20:57.968244: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1746] Adding visible gpu devices: 0, 1, 2
2019-12-12 11:20:57.968473: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcudart.so.10.0
2019-12-12 11:20:59.756185: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1159] Device interconnect StreamExecutor with strength 1 edge matrix:
2019-12-12 11:20:59.756279: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1165]      0 1 2 
2019-12-12 11:20:59.756306: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1178] 0:   N Y Y 
2019-12-12 11:20:59.756323: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1178] 1:   Y N Y 
2019-12-12 11:20:59.756339: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1178] 2:   Y Y N 
tensorflow/core/common_runtime/gpu/gpu_device.cc:1304] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 15190 MB memory) -> physical GPU (device: 0, name: Tesla P100-PCIE-16GB, pci bus id: 0000:04:00.0, compute capability: 6.0)
2019-12-12 11:21:01.088668: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1304] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:1 with 15190 MB memory) -> physical GPU (device: 1, name: Tesla P100-PCIE-16GB, pci bus id: 0000:06:00.0, compute capability: 6.0)
2019-12-12 11:21:01.417236: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1304] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:2 with 5406 MB memory) -> physical GPU (device: 2, name: Tesla P100-PCIE-16GB, pci bus id: 0000:07:00.0, compute capability: 6.0)
b'HELLO!'

3. 检查 tensorflow_datasets 是否安装成功,并输出tfds都包含了哪些数据集:

>>> import tensorflow_datasets as tfds
>>> print(tfds.list_builders())
['bair_robot_pushing_small', 'cats_vs_dogs', 'celeb_a', 'celeb_a_hq', 'cifar10', 'cifar100', 'coco2014', 'diabetic_retinopathy_detection', 'dummy_dataset_shared_generator', 'dummy_mnist', 'fashion_mnist', 'image_label_folder', 'imagenet2012', 'imdb_reviews', 'lm1b', 'lsun', 'mnist', 'moving_mnist', 'nsynth', 'omniglot', 'open_images_v4', 'quickdraw_bitmap', 'squad', 'starcraft_video', 'svhn_cropped', 'tf_flowers', 'wmt_translate_ende', 'wmt_translate_enfr']

没问题,安装成功。

三、尝试运行训练代码

1. 首次运行 python main.py --model_dir try --gin_config ../example_configs/dcgan_celeba64.gin

出现错误。

  File "/users4/zsun/anaconda3/envs/GAN/lib/python3.6/site-packages/tensorflow_datasets/core/download/downloader.py", line 133, in _sync_download
    response = session.get(url, stream=True)
  File "/users4/zsun/anaconda3/envs/GAN/lib/python3.6/site-packages/requests/sessions.py", line 546, in get
    return self.request('GET', url, **kwargs)
  File "/users4/zsun/anaconda3/envs/GAN/lib/python3.6/site-packages/requests/sessions.py", line 533, in request
    resp = self.send(prep, **send_kwargs)
  File "/users4/zsun/anaconda3/envs/GAN/lib/python3.6/site-packages/requests/sessions.py", line 668, in send
    history = [resp for resp in gen] if allow_redirects else []
  File "/users4/zsun/anaconda3/envs/GAN/lib/python3.6/site-packages/requests/sessions.py", line 668, in <listcomp>
    history = [resp for resp in gen] if allow_redirects else []
  File "/users4/zsun/anaconda3/envs/GAN/lib/python3.6/site-packages/requests/sessions.py", line 247, in resolve_redirects
    **adapter_kwargs
  File "/users4/zsun/anaconda3/envs/GAN/lib/python3.6/site-packages/requests/sessions.py", line 646, in send
    r = adapter.send(request, **kwargs)
  File "/users4/zsun/anaconda3/envs/GAN/lib/python3.6/site-packages/requests/adapters.py", line 516, in send
    raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPConnectionPool(host='172.17.228.3', port=8081): Max retries exceeded with url: /IXCa9bee7c9d834e0e4d14e3b433c66e97e/exdb/mnist/train-images-idx3-ubyte.gz (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7fe51008c2e8>: Failed to establish a new connection: [Errno 113] No route to host',))

于是怀疑问题出现在数据集无法下载上,直接尝试能否下载数据集:

>>> ds_train = tfds.load(name="celeb_a", split="train")

报同样的错误,定位成功。

2. 尝试手动下载celeb_a数据集,发现官网不是很好找,于是换一个常用数据集mnist

更改代码的gin文件即可。

python main.py --model_dir try --gin_config ../example_configs/mnist.gin

3. 检查 tensorflow_datasets 是否可以使用:

【用tfds.load执行一系列的批量示例、转换操作,然后再调用】

>>> ds_train = tfds.load(name="mnist", split="train")

报错:

requests.exceptions.ConnectionError: HTTPConnectionPool(host='172.17.228.3', port=8081): Max retries exceeded with url: /IXCa9bee7c9d834e0e4d14e3b433c66e97e/exdb/mnist/train-images-idx3-ubyte.gz (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7fe51008c2e8>: Failed to establish a new connection: [Errno 113] No route to host',))

4. 尝试一下另一种方法:【DatasetBuilder直接实例化或者用tfds.builder字符串读取】【这份其实是上面tfds.load的源码

# Fetch the dataset directly
mnist = tfds.image.MNIST()
# or by string name
mnist = tfds.builder('mnist')
mnist.download_and_prepare()

仍然报同一个错误:

requests.exceptions.ConnectionError: HTTPConnectionPool(host='172.17.228.3', port=8081): Max retries exceeded with url: /IXCa9bee7c9d834e0e4d14e3b433c66e97e/exdb/mnist/train-images-idx3-ubyte.gz (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7fe510110d68>: Failed to establish a new connection: [Errno 113] No route to host',))

使用mnist(有四个文件,train-img,train-label,t10k-img,t10k-label)检查了一下到底有没有成功下载,发现指定下载目录下成功下载了两个(两个label文件,所以初步怀疑报错是因为两个大文件太大下载不成功),并带上了他们的info文件(dict形式,写着名称,下载地址等)

yann.lecu.com_exdb_mnis_t10k-labe-idx1-ubytlX-SfSvqLNNrV7AqoACgdSrEYP_4wsDz4T_rhacyC0o.gz       yann.lecu.com_exdb_mnis_trai-labe-idx1-ubyt7cc_IeM51G_ngIY2ORleKjMjLVCXd-TCUHlYvEiRiKI.gz
yann.lecu.com_exdb_mnis_t10k-labe-idx1-ubytlX-SfSvqLNNrV7AqoACgdSrEYP_4wsDz4T_rhacyC0o.gz.INFO  yann.lecu.com_exdb_mnis_trai-labe-idx1-ubyt7cc_IeM51G_ngIY2ORleKjMjLVCXd-TCUHlYvEiRiKI.gz.INFO

但是另外两个image文件并没有下载成功,上面的错误正是报在image文件无法下载这个问题上。

5.  tensorflow_datasets 为什么安装成功但是不能使用?

参考博客:

https://blog.csdn.net/i8088/article/details/79126150

https://blog.csdn.net/abc13526222160/article/details/85109498

https://blog.csdn.net/jiaoyangwm/article/details/79254667

能查到的问题都是在解决input_data(如下)无法自动下载mnist文件的问题,而我们的代码使用的不是input_data,而是tfds。所以我们面临的是tfds无法自动下载mnist文件的问题。

我们的这个问题无法查到。

from tensorflow.examples.tutorials.mnist import input_data #这是TensorFlow 为了教学Mnist而提前设计好的程序
mnist = input_data.read_data_sets('MNIST_data', one_hot=True) #TensorFlow 会检测数据是否存在。当数据不存在时,系统会自动,在当前代码py文件位置,自动创建MNIST_data文件夹,并将数据下载到该件夹内。当执行完语句后,读者可以自行前往MNIST_data/文件夹下查看上述4 个文件是否已经被正确地下载
#若因网络问题无法正常下载,可以前往MNIST官网http://yann.lecun.com/exdb/mnist/使用下载工具下载上述4 个文件, 并将它们复制到MNIST_data/文件夹中。

能查到的博客上说的都是同一个方法:自己手动下载数据 ,o好8,那就下载一个。

6. 手动下载数据集

在自己电脑上从网址 http://yann.lecun.com/exdb/mnist/ 手动下载数据集(四个,上文有提到)

这个时候需要注意⚠️,有些浏览器下载压缩包会自动给解压。

我的电脑就自动给解压了,并且在浏览器里没有找到 [不要解压] 的选项。

于是换一种下载方法,在数据集处右键获得数据集链接,直接在命令行输入 [wget + 链接] 下载未解压版本。

此处也可以直接使用上面的代码来下载未解压文件:

from tensorflow.examples.tutorials.mnist import input_data #这是TensorFlow 为了教学Mnist而提前设计好的程序
mnist = input_data.read_data_sets('MNIST_data', one_hot=True) #TensorFlow 会检测数据是否存在。当数据不存在时,系统会自动,在当前代码py文件位置,自动创建MNIST_data文件夹,并将数据下载到该件夹内。当执行完语句后,读者可以自行前往MNIST_data/文件夹下查看上述4 个文件是否已经被正确地下载
#若因网络问题无法正常下载,可以前往MNIST官网http://yann.lecun.com/exdb/mnist/使用下载工具下载上述4 个文件, 并将它们复制到MNIST_data/文件夹中。

7. 数据集放到指定位置

仔细观察步骤4的报错信息,发现其自动下载数据集的存放地址为 [~/tensorflow_datasets/mnist/1.0.0]

于是新建一个文件夹,把刚刚下载好的未解压的文件放到这里。

再次运行步骤4的tfds.load('mnist')的代码

手动下载数据集并放到正确位置后,url错误消失,但出现新的错误,仍然无法成功load数据集:

  File "/users4/zsun/tensorflow/compare_gan/compare_gan/datasets.py", line 247, in _load_dataset
    as_dataset_kwargs={"shuffle_files": False})  # \\\\\\\\\\\\\\\\\\\\\\
  File "/users4/zsun/anaconda3/envs/GAN/lib/python3.6/site-packages/tensorflow_datasets/core/api_utils.py", line 52, in disallow_positional_args_dec
    return fn(*args, **kwargs)
  File "/users4/zsun/anaconda3/envs/GAN/lib/python3.6/site-packages/tensorflow_datasets/core/registered.py", line 250, in load
    dbuilder = builder(name, data_dir=data_dir, **builder_kwargs)
  File "/users4/zsun/anaconda3/envs/GAN/lib/python3.6/site-packages/tensorflow_datasets/core/registered.py", line 149, in builder
    return _DATASET_REGISTRY[name](**builder_kwargs)
  File "/users4/zsun/anaconda3/envs/GAN/lib/python3.6/site-packages/tensorflow_datasets/core/api_utils.py", line 52, in disallow_positional_args_dec
    return fn(*args, **kwargs)
  File "/users4/zsun/anaconda3/envs/GAN/lib/python3.6/site-packages/tensorflow_datasets/core/dataset_builder.py", line 531, in __init__
    super(GeneratorBasedBuilder, self).__init__(**kwargs)
  File "/users4/zsun/anaconda3/envs/GAN/lib/python3.6/site-packages/tensorflow_datasets/core/api_utils.py", line 52, in disallow_positional_args_dec
    return fn(*args, **kwargs)
  File "/users4/zsun/anaconda3/envs/GAN/lib/python3.6/site-packages/tensorflow_datasets/core/dataset_builder.py", line 158, in __init__
    self.info.read_from_directory(self._data_dir)
  File "/users4/zsun/anaconda3/envs/GAN/lib/python3.6/site-packages/tensorflow_datasets/core/dataset_info.py", line 312, in read_from_directory
    parsed_proto = read_from_json(json_filename)
  File "/users4/zsun/anaconda3/envs/GAN/lib/python3.6/site-packages/tensorflow_datasets/core/dataset_info.py", line 543, in read_from_json
    dataset_info_json_str = f.read()
  File "/users4/zsun/anaconda3/envs/GAN/lib/python3.6/site-packages/tensorflow_core/python/lib/io/file_io.py", line 122, in read
    self._preread_check()
  File "/users4/zsun/anaconda3/envs/GAN/lib/python3.6/site-packages/tensorflow_core/python/lib/io/file_io.py", line 84, in _preread_check
    compat.as_bytes(self.__name), 1024 * 512)
tensorflow.python.framework.errors_impl.NotFoundError: /users4/zsun/tensorflow_datasets/mnist/1.0.0/dataset_info.json; No such file or directory

报错内容:tensorflow_datasets/mnist/1.0.0/dataset_info.json; No such file or directory

8. 这个 [dataset_info.json] 是什么?

官网只提供了四个数据文件,并没有这个json文件。

但想要成功运行tfds.load 或者 mnist.download_and_prepare(),看起来必须要这个文件。

那么找一下

查看tensorflow源码(根据tensorflow_datasets.core相关的报错位置查看源码)

https://github.com/tensorflow/datasets/blob/master/tensorflow_datasets/core/dataset_info.py

https://github.com/tensorflow/datasets/blob/v1.3.0/tensorflow_datasets/core/dataset_builder.py#L236-L308

查看tensorflow官方文档 https://tensorflow.google.cn/datasets/api_docs/python/tfds/core/DatasetInfo 其中有关于数据集dataset的info文件,灵机一动,诶,会不会是他呢?

于是查找到dataset.info的输出方式,输出看看,嗯,格式差不多。。。

那我们把它存成这个json文件试一下在这里https://www.tensorflow.org/datasets/api_docs/python/tfds/core/DatasetInfo找到了DatasetInfo有转为json的属性,当然直接用啊!

转为json之后,写到文件里,整体代码如下

>>> mnist = tfds.image.MNIST()
>>> mnist.info
<tensorflow_datasets.core.dataset_info.DatasetInfo object at 0x7fd6945811d0>
>>> print(mnist.info)
tfds.core.DatasetInfo(
    name='mnist',
    version=1.0.0,
    description='The MNIST database of handwritten digits.',
    urls=['http://yann.lecun.com/exdb/mnist/'],
    features=FeaturesDict({
        'image': Image(shape=(28, 28, 1), dtype=tf.uint8),
        'label': ClassLabel(shape=(), dtype=tf.int64, num_classes=10)
    },
    total_num_examples=0,
    splits={

    },
    supervised_keys=('image', 'label'),
    citation='"""
        @article{lecun2010mnist,
          title={MNIST handwritten digit database},
          author={LeCun, Yann and Cortes, Corinna and Burges, CJ},
          journal={ATT Labs [Online]. Available: http://yann. lecun. com/exdb/mnist},
          volume={2},
          year={2010}
        }

    """',
)

>>> print(mnist.info.as_json)
{
  "citation": "@article{lecun2010mnist,\n  title={MNIST handwritten digit database},\n  author={LeCun, Yann and Cortes, Corinna and Burges, CJ},\n  journal={ATT Labs [Online]. Available: http://yann. lecun. com/exdb/mnist},\n  volume={2},\n  year={2010}\n}\n",
  "description": "The MNIST database of handwritten digits.",
  "location": {
    "urls": [
      "http://yann.lecun.com/exdb/mnist/"
    ]
  },
  "name": "mnist",
  "supervisedKeys": {
    "input": "image",
    "output": "label"
  },
  "version": "1.0.0"
}
>>>
>>> import json
>>> with open('/users4/zsun/tensorflow_datasets/mnist/1.0.0/dataset_info.json', 'w') as f:json.dump(mnist.info.as_json, f)
  File "/users4/zsun/anaconda3/envs/GAN/lib/python3.6/site-packages/tensorflow_datasets/core/dataset_info.py", line 546, in read_from_json
    dataset_info_pb2.DatasetInfo())
  File "/users4/zsun/anaconda3/envs/GAN/lib/python3.6/site-packages/google/protobuf/json_format.py", line 430, in Parse
    return ParseDict(js, message, ignore_unknown_fields, descriptor_pool)
  File "/users4/zsun/anaconda3/envs/GAN/lib/python3.6/site-packages/google/protobuf/json_format.py", line 450, in ParseDict
    parser.ConvertMessage(js_dict, message)
  File "/users4/zsun/anaconda3/envs/GAN/lib/python3.6/site-packages/google/protobuf/json_format.py", line 481, in ConvertMessage
    self._ConvertFieldValuePair(value, message)
  File "/users4/zsun/anaconda3/envs/GAN/lib/python3.6/site-packages/google/protobuf/json_format.py", line 592, in _ConvertFieldValuePair
    raise ParseError(str(e))
google.protobuf.json_format.ParseError: Message type "tensorflow_datasets.DatasetInfo" has no field named "{".
 Available Fields(except extensions): ['name', 'description', 'version', 'citation', 'sizeInBytes', 'location', 'downloadChecksums', 'schema', 'splits', 'supervisedKeys']

依旧有问题,说明自己建json文件不可行。

怀疑input_data与tfds所需要的数据集格式不同,inputdata的解决方案并不适用。

9. 本地使用tfds下载安装数据集

之前报url的错误是是服务器上,由于服务器无法翻墙,又无法保证链接稳定;

目前来看其他方法也行不通。

所以最后一个办法。

本地电脑安装tensorflow==1.15 tensorflow_dataset==1.0.1

然后本地运行某一种方法:

mnist = tfds.builder('mnist')
mnist.download_and_prepare()

成功下载并处理。

查看处理后的文件样式:

果然和input_data.py相差十万八千里

再次运行python main.py --model_dir try --gin_config ../example_configs/mnist.gin,不再出现数据集的问题。

成功!!!

总结:input_data 和 tfds 的数据集调用方式 和 问题解决方式不一样,目前来看mnist在tfds上只有换电脑这一种解决方式

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值