本文参考了黄文坚和唐源所著的《TensorFlow实战》一书。
操作系统以及语言环境:MacOS Python3.5 TensorFlow1.1
下面开始实现最常用的自编码器。先导入NumPy库,Scikit-learn中的preprocessing模块,这个模块是对数据进行预处理的常用模块,之后会用到其中的数据标准化功能。
本文使用的数据集是MNIST数据集,导入TensorFlow中的MNIST数据加载模块。以下代码来自https://github.com/tensorflow/models.git的开源实现。可以使用git clone https://github.com/tensorflow/models.git 下载到本地。然后:
python3 pythitiveGaussianNoiseAutoe
执行的结果:
Successfully downloaded train-images-idx3-ubyte.gz 9912422 bytes.
Extracting MNIST_data/train-images-idx3-ubyte.gz
Successfully downloaded train-labels-idx1-ubyte.gz 28881 bytes.
Extracting MNIST_data/train-labels-idx1-ubyte.gz
Successfully downloaded t10k-images-idx3-ubyte.gz 1648877 bytes.
Extracting MNIST_data/t10k-images-idx3-ubyte.gz
Successfully downloaded t10k-labels-idx1-ubyte.gz 4542 bytes.
Extracting MNIST_data/t10k-labels-idx1-ubyte.gz
2017-06-05 19:32:30.406118: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.1 instructions, but these are available on your machine and could speed up CPU computations.
2017-06-05 19:32:30.406157: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.2 instructions, but these are available on your machine and could speed up CPU computations.
2017-06-05 19:32:30.406166: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use AVX instructions, but these are available on your machine and could speed up CPU computations.
2017-06-05 19:32:30.406174: W tensorflow/core/platform/cpu_fea