基于tensorflow,dbn实现mnist数据识别的运行过程中出现的问题

Python新手在使用TensorFlow的DBN进行MNIST数据集分类时遇到多个问题,包括Pillow安装位置、urllib.urlretrieve属性错误、数据读取错误等。通过激活TensorFlow环境安装Pillow,修改input_data模块,以及下载并指定MNIST数据路径,解决了所有问题。在运行程序时出现的警告也进行了相应调整。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

点击打开链接

点击打开链接

点击打开链接

因为分享,知识才得以传播。

谢谢网上大神的分享

Python小白,为了项目开始接触深度学习,使用DBN进行分类,在网上找到最经典的例子来看,具体过程参考了网上的大神,详看链接。就我遇到的问题做个总结。

1.按照@devhl的运行顺序,在安装Pillow时遇到了第一个问题。

因为我的Python基于anaconda构建,tensorflow也基于anaconda,不知道应该把pillow安装在哪里,后来一想基于tensorflow运行

Pycharm,那么我应该安装在anaconda的tensorflow中,打开anaconda prompt,输入activate tensorflow(不知怎么着,在我的电脑里

tensorflow环境的名字为ame…… 和我一样情况的可以换成activate ame),然后继续按照教程走。

2.我还出现了一个问题,module 'urllib' has no attribute 'urlretrieve',解决方法参考链接3,感谢大神分享。

在input_date中做以下修改。


import urllib
import urllib.request
import numpy
SOURCE_URL = 'http://yann.lecun.com/exdb/mnist/'
#data = urllib.request.urlretrieve("http://yann.lecun.com/exdb/mnist/")
def maybe_download(filename, work_directory):
  """Download the data from Yann's website, unless it's already here."""
  if not os.path.exists(work_directory):
    os.mkdir(work_directory)
  filepath = os.path.join(work_directory, filename)
  if not os.path.exists(filepath):
    filepath, _ = urllib.request.urlretrieve(SOURCE_URL + filename, filepath)

3.在按照教程的第三个步骤添加[0]后,运行rbm_MNIST_test时,出现了另一个问题:

如下:

Traceback (most recent call last):
  File "E:/迅雷下载/dbn_tf-master/dbn_tf-master/rbm_MNIST_test.py", line 15, in <module>
    mnist = input_data.read_data_sets("MNIST_data/", one_hot=True)
  File "E:\迅雷下载\dbn_tf-master\dbn_tf-master\input_data.py", line 155, in read_data_sets
    test_labels = extract_labels(local_file, one_hot=one_hot)
  File "E:\迅雷下载\dbn_tf-master\dbn_tf-master\input_data.py", line 57, in extract_labels
    magic = _read32(bytestream)
  File "E:\迅雷下载\dbn_tf-master\dbn_tf-master\input_data.py", line 25, in _read32
    return numpy.frombuffer(bytestream.read(4), dtype=dt)[0]

IndexError: index 0 is out of bounds for axis 0 with size 0

在网上找了很多资料都没用,终于发现了一个方法。链接2里面的方法,感谢大佬的无私分享。虽然错误不同,但我还是尝试了这个方法,成功了!

即为:

将rbm_MNIST_test中的程序进行简单修改,下载MNIST到指定位置,添加它的路径;test程序相同。

mnist = input_data.read_data_sets("E:\迅雷下载/MNIST_data/", one_hot=True)#修改过,加了MNIST_data的下载路径

4.到这里基本没啥问题了,在运行test和rbm_MNIST_test时会出现警告,照着警告改就好。

示例:在nn_tf中:

sess.run(tf.global_variables_initializer())#修改过,将tf.initialize_all_variables改成tf.global_variables_initializer.

链接没经过各位大神同意,如果各位大神介意的话,请马上通知我,我会删除链接的。感谢各位大神的分享和帮助。



Code provided by Ruslan Salakhutdinov and Geoff Hinton Permission is granted for anyone to copy, use, modify, or distribute this program and accompanying programs and documents for any purpose, provided this copyright notice is retained and prominently displayed, along with a note saying that the original programs are available from our web page. The programs and documents are distributed without any warranty, express or implied. As the programs were written for research purposes only, they have not been tested to the degree that would be advisable in any important application. All use of these programs is entirely at the user's own risk. How to make it work: 1. Create a separate directory and download all these files into the same directory 2. Download from http://yann.lecun.com/exdb/mnist the following 4 files: o train-images-idx3-ubyte.gz o train-labels-idx1-ubyte.gz o t10k-images-idx3-ubyte.gz o t10k-labels-idx1-ubyte.gz 3. Unzip these 4 files by executing: o gunzip train-images-idx3-ubyte.gz o gunzip train-labels-idx1-ubyte.gz o gunzip t10k-images-idx3-ubyte.gz o gunzip t10k-labels-idx1-ubyte.gz If unzipping with WinZip, make sure the file names have not been changed by Winzip. 4. Download Conjugate Gradient code minimize.m 5. Download Autoencoder_Code.tar which contains 13 files OR download each of the following 13 files separately for training an autoencoder and a classification model: o mnistdeepauto.m Main file for training deep autoencoder o mnistclassify.m Main file for training classification model o converter.m Converts raw MNIST digits into matlab format o rbm.m Training RBM with binary hidden and binary visible units o rbmhidlinear.m Training RBM with Gaussian hidden and binary visible units o backprop.m Backpropagation for fine-tuning an autoencoder o backpropclassify.m Backpropagation for classification using "encoder" network o CG_MNIST.m Conjugate Gradient optimization for fine-tuning an autoencoder o CG_CLASSIFY_INIT.m Co
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值