idx3ubyte文件解压|用cnn时必须用mnistuint8数据库吗

|

① 为什么hinton 的代码出错

:G.E. hinton个人主页上的源代码,册局宽是关于06年那篇发表州亮在science上的文章,了解的可以下载一下-GE hinton personal home page on the source code, is on the 2006 thing I read the article published in the science, to understand what can be downloaded[上传源码成为会员下载此文件] [成为VIP会员下载此文件]文件列表(点击判断是否您需要的文件,如果是垃腊绝圾请在下面评价投诉): train-labels-idx1-ubyte.gz Autoencoder_Code.tar t10k-images-idx3-ubyte.gz t10k-labels-idx1-ubyte.gz train-images-idx3-ubyte.gz

② 求助tensorflow下遇到cuda compute capability问题

首先需要看你的PC配置是否够,TF的GPU模式只支持N卡,然后计算能力高于3.0,具体可以查:安装教程可以参考:Ubuntu16.04上gtx1080的cuda安装July 17 2016目前tensorflow是一个非常流行的深度学习计算框架,常规硬件及系统的安装方法官方的doc已经说的很清楚了,但是 因为系统是ubuntu16.04,显卡是GTX1080,所以不可避免的要折腾起来。在上一篇已经在16.04上安装好了驱动。接下来其实 重点安装的是CUDA和cuDNN.首先说为什么要安装CUDA和cuDNN,关于采用GPU计算比CPU有速度有多少提升的benchmark找找就有,这次重点是怎么让tensorflow充分用的 上GTX1080能力。具体的就是如何把支持GTX1080的CUDA和cuDNN装起来,然后让tensorflow认识我们新装的CUDA和cuDNN。首先总体说下安装步骤:1 首先要注册NVIDIA developer的帐号,分别下载CUDA和cuDNN2 确认准备gcc版本,安装依赖库sudo apt-get install freegl3 安装CUDA4 解压cuDNN5 clone tensorflow源码,configure配置6 编译安装7 最后一哆嗦,测试!准备工作在正式开始前,需要做几个准备工作,主要是大概先看下文档cuda FAQtensorflow 的安装文档cuda-gpu的支持列表/计算能力/FAQcudnn 5.1有多牛cuda tookit下载页面CUDA_Installation_Guide_linux.pdfcudnn User Guide文档看过之后接下来就是实际动手的过程:1 注册NVIDIA developer的帐号,分别下载CUDA和cuDNN1.1 下载CUDA 打开cuda toolkit下载页面,GTX1080 要用的是CUDA 8。先点击JOIN,注册帐号。 完了后,再回到cuda toolkit下载页面。选择 linux, x86-64, ubuntu, 16.04, runfile(local)1.2 下载cuDNN 进入cudnn的下载页,一堆调查,日志写时下载的是[Download cuDNN v5 (May 27, 2016), for CUDA 8.0 RC],点开选linux,不出意外的话这个就是下载地址.2 确认GCC版本,安装依赖库确认本机gcc版本,16.04默认的是gcc 5,这里安装需要的最高是gcc 4.9。接下来就安装配置gcc 4.9.2.1 安装gcc 4.9,并修改系统默认为4.9sudo apt-get install gcc-4.9 gcc-4.9 g++-4.9 g++-4.9gcc –versionsudo update-alternatives –install /usr/bin/g++ g++ /usr/bin/g++-4.9 10sudo update-alternatives –install /usr/bin/cc cc /usr/bin/gcc 30sudo update-alternatives –set cc /usr/bin/gccsudo update-alternatives –install /usr/bin/c++ c++ /usr/bin/g++ 30sudo update-alternatives –set c++ /usr/bin/g++gcc –version2.2 一个小依赖sudo apt-get install freegl3 安装CUDA需要注意的是这个地方有个选择安装低版本驱动的地方,选n 大致的安装流程如下:3.1 安装CUDAchmod +x /cuda_8.0.27_linux.run./cuda_8.0.27_linux.run….Do you accept the previously read EULA?accept/decline/quit: acceptInstall NVIDIA Accelerated Graphics Driver for Linux-x86_64 361.62?(y)es/(n)o/(q)uit: nInstall the CUDA 8.0 Toolkit?(y)es/(n)o/(q)uit: yEnter Toolkit Location[ default is /usr/local/cuda-8.0 ]: Do you want to install a symbolic link at /usr/local/cuda?(y)es/(n)o/(q)uit: yInstall the CUDA 8.0 Samples?(y)es/(n)o/(q)uit: yEnter CUDA Samples Location[ default is /home/h ]: /home/h/Documents/cuda_samples….3.2 写入环境变量vim ~/.bashrc#添加下面变量export PATH=/usr/local/cuda-8.0/bin${PATH:+:${PATH}}export LD_LIBRARY_PATH=/usr/local/cuda-8.0/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}3.3 安装好后简单验证a. 进入刚配置时指定的cuda sample所在文件夹,NVIDIA_CUDA-8.0_Samples/b. cd 0_Simple/asyncAPI;sudo makec. NVIDIA_CUDA-8.0_Samples/0_Simple/asyncAPI$ ./asyncAPI [./asyncAPI] – Starting… GPU Device 0: “GeForce GTX 1080” with compute capability 6.1 CUDA device [GeForce GTX 1080] time spent executing by the GPU: 10.94 time spent by CPU in CUDA calls: 0.19 CPU executed 50591 iterations while waiting for GPU to finish4 安装cuDNN[email protected]:~/Downloads$ tar xvzf cudnn-8.0-linux-x64-v5.0-ga.tgz cuda/include/cudnn.hcuda/lib64/libcudnn.socuda/lib64/libcudnn.so.5cuda/lib64/libcudnn.so.5.0.5cuda/lib64/libcudnn_static.a[email protected]:~/Downloads$ sudo cp -R cuda/lib64 /usr/local/cuda/lib64[email protected]:~/Downloads$ sudo mkdir -p /usr/local/cuda/include[email protected]:~/Downloads/cuda$ sudo cp include/cudnn.h /usr/local/cuda/include/sudo chmod a+r /usr/local/cuda/include/cudnn.h /usr/local/cuda/lib64/libcudnn*5 clone, configure tensorflow5.1 clone源码$ git clone 5.2 configure配置整个配置流程应该跟下面的基本一样的[email protected]:~/Downloads/tensorflow$ cd ./tensorflow/[email protected]:~/Downloads/tensorflow$ ./configurePlease specify the location of python. [Default is /usr/bin/python]: ***Do you wish to build TensorFlow with Google Cloud Platform support? [y/N] N***No Google Cloud Platform support will be enabled for TensorFlow***Do you wish to build TensorFlow with GPU support? [y/N] y***GPU support will be enabled for TensorFlowPlease specify which gcc nvcc should use as the host compiler. [Default is /usr/bin/gcc]: **Please specify the location where CUDA toolkit is installed. Refer to README.md for more details. [Default is /usr/local/cuda]: /usr/local/cuda-8.0 ****Please specify the Cudnn version you want to use. [Leave empty to use system default]: 5.0.5****Please specify the location where cuDNN 5.0.5 library is installed. Refer to README.md for more details. [Default is /usr/local/cuda-8.0]: /usr/local/cuda**Please specify a list of comma-separated Cuda compute capabilities you want to build with.You can find the compute capability of your device at: **Please note that each additional compute capability significantly increases your build time and binary size.[Default is: “3.5,5.2”]: 6.1**Setting up Cuda includeSetting up Cuda lib64Setting up Cuda binSetting up Cuda nvvmSetting up CUPTI includeSetting up CUPTI lib64Configuration finished6 编译安装6.1 编译工具Bazel安装配置先看一眼文档然后就执行下面的流程:#安装java 1.8sudo add-apt-repository ppa:webupd8team/javasudo apt-get updatesudo apt-get install oracle-java8-installer#安装好后车参考下java -version#添加源echo “deb [arch=amd64] stable jdk1.8” | sudo tee /etc/apt/sources.list.d/bazel.listcurl | sudo apt-key add -#下载sudo apt-get update && sudo apt-get install bazel#升级sudo apt-get upgrade bazel6.2 编译tensorflow的pip版本并安装$ bazel build -c opt //tensorflow/tools/pip_package:build_pip_package# To build with GPU support:$ bazel build -c opt –config=cuda //tensorflow/tools/pip_package:build_pip_package$ bazel-bin/tensorflow/tools/pip_package/build_pip_package /tmp/tensorflow_pkg# The name of the .whl file will depend on your platform.#注意编译完成后生成的文件名字和官方doc里面的是不一定一致的$ sudo pip install /tmp/tensorflow_pkg/tensorflow-0.*-linux_x86_64.whli6700k 32g编译时间:只编译代码不带pip INFO: Elapsed time: 967.271s, Critical Path: 538.38sbazel-bin/tensorflow/tools/pip_package/build_pip_package INFO: Elapsed time: 65.183s, Critical Path: 48.587 最后测试前面都整完了,现在该测试了,注意前面有两个动态链接库的位置,cuDNN在/usr/local/cuda/lib64, 而cuda在/usr/local/cuda-8.0/lib64,所以这个时候的bashrc应该这么写:export PATH=/usr/local/cuda-8.0/bin${PATH:+:${PATH}}export LD_LIBRARY_PATH=/usr/local/cuda/lib64:/usr/local/cuda-8.0/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}写完后,source ~/.bashrccd tensorflow/tensorflow/models/image/mnistpython convolutional.py成功的话会出现流畅的跑动:[email protected]:~/Downloads/tensorflow/tensorflow/models/image/mnist$ python convolutional.pyI tensorflow/stream_executor/dso_loader.cc:108] successfully opened CUDA library libcublas.so locallyI tensorflow/stream_executor/dso_loader.cc:108] successfully opened CUDA library libcudnn.so.5.0.5 locallyI tensorflow/stream_executor/dso_loader.cc:108] successfully opened CUDA library libcufft.so locallyI tensorflow/stream_executor/dso_loader.cc:108] successfully opened CUDA library libcuda.so.1 locallyI tensorflow/stream_executor/dso_loader.cc:108] successfully opened CUDA library libcurand.so locallyExtracting data/train-images-idx3-ubyte.gzExtracting data/train-labels-idx1-ubyte.gzExtracting data/t10k-images-idx3-ubyte.gzExtracting data/t10k-labels-idx1-ubyte.gzI tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:925] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zeroI tensorflow/core/common_runtime/gpu/gpu_init.cc:102] Found device 0 with properties: name: GeForce GTX 1080major: 6 minor: 1 memoryClockRate (GHz) 1.8475pciBusID 0000:01:00.0Total memory: 7.92GiBFree memory: 7.41GiBI tensorflow/core/common_runtime/gpu/gpu_init.cc:126] DMA: 0 I tensorflow/core/common_runtime/gpu/gpu_init.cc:136] 0: Y I tensorflow/core/common_runtime/gpu/gpu_device.cc:838] Creating TensorFlow device (/gpu:0) -> (device: 0, name: GeForce GTX 1080, pci bus id: 0000:01:00.0)Initialized!Step 0 (epoch 0.00), 8.4 msMinibatch loss: 12.054, learning rate: 0.010000Minibatch error: 90.6%Validation error: 84.6%……Minibatch error: 0.0%Validation error: 0.7%Step 8500 (epoch 9.89), 4.7 msMinibatch loss: 1.601, learning rate: 0.006302Minibatch error: 0.0%Validation error: 0.9%Test error: 0.8%

③ 如何用python解析mnist

1.我们首先看一下mnist的数据结构:2. 可以看出在train-images.idx3-ubyte中,第一个数为32位的整数(魔数,图片类型的数),第二个数为32位的整数(图片的个数),第三和第四个也是32为的整数(分别代表图片的行数和列数),接下来的都是一个字节的无符号数(即像素,值域为0~255),因此,我们只需要依次获取魔数和图片的个数,然后获取图片的长和宽,最后逐个像素读取就可以了。3.如何使用Python解析数据呢? 首先需要安装python的图形处理库PIL,这个库支持像素级别的图像处理,对于学习数字图像处理有很大的帮助。安装完成之后,就可以进行图像的解析了。看一下代码:4.首先打开文件,然后分别读取魔数,图片个数,以及行数和列数,在struct中,可以看到,使用了’>IIII’,这是什么意思呢?意思就是使用大端规则,读取四个整形数(Integer),如果要读取一个字节,则可以用’>B’(当然,这里用没用大端规则都是一样的,因此只有两个或两个以上的字节才有用)。5.什么是大端规则呢?不懂的可以网络一下,这个不再赘述(http://ke..com/link?url=Bgg8b0vRr3b_SeGyOl8U4DmAbIQT9swGuNtD_21ctEI_NliqsQ-mKF73YT90EILF2EQy50mEua_M4z6Cma3rmK)6.然后对于每张图片,先创建一张空白的图片,其中的’L’代表这张图片是灰度图,最后逐个像素读取,然后写进空白图片里,最后保存图片,就可以了7.再来看一下mnist标签的数据结构:可以发现,与上面的非常相似,只不过这里每一个字节变成了标签而已(标签大小为0~9)8.好了,通过上述讲解,最后我们可以通过python将mnist解析出来了,看一下效果:程序源代码如下:#!/usr/bin/env python# -*- coding: utf-8 -*-from PIL import Imageimport structdef read_image(filename): f = open(filename, 'rb')index = 0 buf = f.read()f.close()magic, images, rows, columns = struct.unpack_from('>IIII' , buf , index) index += struct.calcsize('>IIII')for i in xrange(images): #for i in xrange(2000): image = Image.new('L', (columns, rows))for x in xrange(rows): for y in xrange(columns): image.putpixel((y, x), int(struct.unpack_from('>B', buf, index)[0])) index += struct.calcsize('>B')print 'save ' + str(i) + 'image' image.save('test/' + str(i) + '.png')def read_label(filename, saveFilename): f = open(filename, 'rb') index = 0 buf = f.read()f.close()magic, labels = struct.unpack_from('>II' , buf , index) index += struct.calcsize('>II') labelArr = [0] * labels #labelArr = [0] * 2000for x in xrange(labels): #for x in xrange(2000): labelArr[x] = int(struct.unpack_from('>B', buf, index)[0]) index += struct.calcsize('>B')save = open(saveFilename, 'w')save.write(','.join(map(lambda x: str(x), labelArr))) save.write('\n')save.close() print 'save labels success'if __name__ == '__main__': read_image('t10k-images.idx3-ubyte') read_label('t10k-labels.idx1-ubyte', 'test/label.txt')

④ 如何生成.idx3-ubyte 格式的文件

其实就是python怎么读取binnaryfilemnist的结构如下,选取train-imagesTRAININGSETIMAGEFILE(train-images-idx3-ubyte):[offset][type][value][description]000032bitinteger0x00000803(2051)??pixel0017unsignedbyte??pixel..xxxxunsignedbyte??pixel也就是之前我们要读取4个32bitinteger试过很多方法,觉得最方便的,至少对我来说还是使用struct.unpack_from()filename='train-images.idx3-ubyte'binfile=open(filename,'rb')buf=binfile.read()先使用二进制方式把文件都读进来index=0magic,numImages,numRows,numColumns=struct.unpack_from('>IIII',buf,index)index+=struct.calcsize('>IIII')然后使用struc.unpack_from'>IIII'是说使用大端法读取4个unsingedint32然后读取一个图片测试是否读取成功im=struct.unpack_from('>784B',buf,index)index+=struct.calcsize('>784B')im=np.array(im)im=im.reshape(28,28)fig=plt.figure()plotwindow=fig.add_subplot(111)plt.imshow(im,cmap='gray')plt.show()'>784B'的意思就是用大端法读取784个unsignedbyte完整代码如下.pyplotaspltfilename='train-images.idx3-ubyte'binfile=open(filename,'rb')buf=binfile.read()index=0magic,numImages,numRows,numColumns=struct.unpack_from('>IIII',buf,index)index+=struct.calcsize('>IIII')im=struct.unpack_from('>784B',buf,index)index+=struct.calcsize('>784B')im=np.array(im)im=im.reshape(28,28)fig=plt.figure()plotwindow=fig.add_subplot(111)plt.imshow(im,cmap='gray')plt.show()

⑤ .idx3-ubyte怎么打开

.idx3-ubyte文件是一种二进纳拆制文件,可以使用专野缓用软件,例如ImageJ或洞脊枣其他图像处理软件,来打开和查看该文件。此外,还可以使用Libtiff程序来处理这种文件,或者使用开发人员开发的应用程序也可以打开和查看这种文件。

⑥ 用cnn时必须用mnist.uint8数据库吗

首先上搜索引擎,无论是网络还是google,搜“MNIST”第一个出来的肯定是http://yann.lecun.com/exdb/mnist/ 没错,就是它!这个网页上面有四个压缩包的链接,下载下来吧少年!然后别忙着关掉这个网页,因为后面的读取数据还得依靠这个网页的说明。下面用其中一个包t10k-images_idx3为例子,写代码说明如何使用这个数据库。这是从verysource.com上面下载的源码,赞一个!and再赞一个!% Matlab_Read_t10k-images_idx3.m% 用于读取MNIST数据集中t10k-images.idx3-ubyte文件并将其转换成bmp格式图片输出。% 用法:运行程序,会弹出选择测试图片数据文件t10k-labels.idx1-ubyte路径的对话框和% 选择保存测试图片路径的对话框,选择路径后程序自动运行完毕,期间进度条会显示处理进度。% 图片以TestImage_00001.bmp~TestImage_10000.bmp的格式保存在指定路径,10000个文件占用空间39M。。% 整个程序运行过程需几分钟时间。% Written By [email protected] IPRAI% 2009-2-22clear all;clc;%读取训练图片数据文件[FileName,PathName] = uigetfile('*.*','选择测试图片数据文件t10k-images.idx3-ubyte');TrainFile = fullfile(PathName,FileName);fid = fopen(TrainFile,'r'); %fopen()是最核心的函数,导入文件,‘r’代表读入a = fread(fid,16,'uint8'); %这里需要说明的是,包的前十六位是说明信息,从上面提到的那个网页可以看到具体那一位代表什么意义。所以a变量提取出这些信息,并记录下来,方便后面的建立矩阵等动作。MagicNum = ((a(1)*256+a(2))*256+a(3))*256+a(4);ImageNum = ((a(5)*256+a(6))*256+a(7))*256+a(8);ImageRow = ((a(9)*256+a(10))*256+a(11))*256+a(12);ImageCol = ((a(13)*256+a(14))*256+a(15))*256+a(16);%从上面提到的网页可以理解这四句if ((MagicNum~=2051)||(ImageNum~=10000)) error('不是 MNIST t10k-images.idx3-ubyte 文件!'); fclose(fid); return; end %排除选择错误的文件。savedirectory = uigetdir('','选择测试图片路径:');h_w = waitbar(0,'请稍候,处理中>>');for i=1:ImageNum b = fread(fid,ImageRow*ImageCol,'uint8'); %fread()也是核心的函数之一,b记录下了一副图的数据串。注意这里还是个串,是看不出任何端倪的。 c = reshape(b,[ImageRow ImageCol]); %亮点来了,reshape重新构成矩阵,终于把串转化过来了。众所周知图片就是矩阵,这里reshape出来的灰度矩阵就是该手写数字的矩阵了。 d = c'; %转置一下,因为c的数字是横着的。。。 e = 255-d; %根据灰度理论,0是黑色,255是白色,为了弄成白底黑字就加入了e e = uint8(e); savepath = fullfile(savedirectory,['TestImage_' num2str(i,'d') '.bmp']); imwrite(e,savepath,'bmp'); %最后用imwrite写出图片 waitbar(i/ImageNum);endfclose(fid);close(h_w);在选择好的路径中,就有了一大堆MNIST的手写数字的图片。想弄哪个,就用imread()弄它!

⑦ 如何读取t10k-images

# 默认open(…,'r') 是指用文本方式打开文件 trainfile = open('train-images.idx3-ubyte', 'r') print 'start train file' trainfile.read(16) matrix_number = 10000 y =28 * 28 * matrix_number line = trainfile.read(y) # 读取大小为y的或…

⑧ 谁可以告诉我后缀名是.idx3-ubyte的文件怎么用

额,正好刚刚遇到这个问题。idx3-ubyte应该是这个网站http://yann.lecun.com/exdb/mnist/上提供的手写数字识别的源数据,在这个网站上有对这种数据的说明。这里提供一个 matlab读取这种数据的M文件,函数名叫readMNIST 。老外写的,文件下载地址http://www.mathworks.com/matlabcentral/fileexchange/27675-read-digits-and-labels-from-mnist-database , 点击该网站右手边的download submission . 接下来,就看你matlab了,搞这个的,matlab肯定会用吧。

⑨ 如何制作像mnist,CIFAR-10格式的数据集

MNIST 数据集混合的国家标准和技术 (简称 MNIST) 由红外研究员,作为基准来比较不同的红外算法创建数据集。 其基本思想是如果你有你想要测试红外的算法或软件的系统,可以运行您的算法或系统针对 MNIST 的数据集和比较您的结果与其他系统以前发布成果。数据集包含的共 70,000 图像 ; 60,000 训练图像 (用于创建红外模型) 和 10,000 测试图像 (用于评估模型的精度)。 每个 MNIST 图像是一个单一的手写的数字字符的数字化的图片。 每个图像是 28 x 28 像素大小。 每个像素值是 0,表示白色,至 255,表示黑。 中间像素值表示的灰度级。 图 2 显示了训练集的前八位的图像。 对应于每个图像的实际数字是显然对人,但确定数字是非常困难的挑战的计算机。图 2 首八 MNIST 训练图像奇怪的是,训练数据和测试数据均存储在两个文件中,而不是在单个文件中。 其中一个文件包含图像的像素值和,另一个包含图像的标签信息 (0 到 9)。 每个的四个文件还包含标头信息,和所有的四个文件都存储在已经使用 gzip 格式压缩的二进制格式。注意在图 1,该演示程序使用仅 60,000 项目训练集。 测试集的格式是相同的训练集。 MNIST 文件的主存储库是目前位于 yann.lecun.com/exdb/mnist。 培训的像素数据存储在文件火车-图像-idx3-ubyte.gz 和培训标签数据存储在文件火车-标签-idx1-ubyte.gz。 若要运行该演示程序,您需要转到 MNIST 的存储库站点,下载并解压的两个培训数据文件。 将文件解压缩,我用的免费的开源 7-Zip 实用程序。创建 MNIST 查看器若要创建 MNIST 演示程序,我发起了 Visual Studio,创建一个名为 MnistViewer 的新 C# Windows 窗体项目。 演示有没有重大的.NET 版本依赖关系,因此,任何版本的 Visual Studio 应该工作。模板代码加载到 Visual Studio 编辑器后,我设置的 UI 控件。 我添加了两个 TextBox 控件 (textBox1,textBox2) 要坚持两个解压后的培训文件的路径。 我添加一个按钮控件 (button1),并给了它一个标签加载图像。 我添加了两个多个 TextBox 控件 (textBox3,textBox4) 以保存当前图像索引和下一个图像索引的值。 我使用 Visual Studio 设计器,分别设置"NA"和"0,"这些控件的初始值。我添加了一个 ComboBox 控件 (comboBox1) 的图像放大倍数值。 使用设计器,我去到该控件的项集合,添加字符串"1"到"10"。我添加了第二个按钮控件 (button2),并给了它一个标签的显示下一次。 我添加了 PictureBox 控件 (pictureBox1),将其背景色属性设置为 ControlDark,以便看到控件的轮廓。 我将图片框大小设置为 280 x 280 允许最多 10 倍的放大倍率 (回顾 MNIST 图像是 28 x 28 像素为单位)。 我添加了第五个 (textBox5) 文本框以显示十六进制值的图像,然后将其多行属性设置为 True 和其字体属性设置为 8.25 磅 Courier New 和扩大其大小到 606 x 412。 而且,最后,我添加了一个列表框控件 (listBox1) 的日志记录消息。后放置 UI 控件拖到 Windows 窗体,添加三个类范围字段:public partial class Form1 : Form{private string pixelFile =@"C:\MnistViewer\train-images.idx3-ubyte";private string labelFile =@"C:\MnistViewer\train-labels.idx1-ubyte";private DigitImage[] trainImages = null;…第一次两个字符串指向解压后的培训数据文件的位置。 你会需要编辑这些要运行演示的两个字符串。 第三个字段是一个程序定义 DigitImage 对象的数组。我编辑窗体的构造函数略成 textBox1 和 textBox2 地点的文件路径,并给予放大倍数初始值 6:public Form1(){InitializeComponent();textBox1.Text = pixelFile;textBox2.Text = labelFile;comboBox1.SelectedItem = "6";this.ActiveControl = button1;}我用的 ActiveControl 属性来设置初始焦点到 button1 控件,只是为了方便。

⑩ 普通电脑PC怎样跑TensorFlow的GPU模式

首先需要看你的PC配置是否够,TF的GPU模式只支持N卡,然后计算能力高于3.0,具体可以查:https://developer.nvidia.com/cuda-gpus

安装教程可以参考:http://haiy.github.io/2016/07/17/ubuntu16.04%E4%B8%8AGTX1080%E7%9A%84CUDA%E5%AE%89%E8%A3%85.html

http://blog.csdn.net/zhaoyu106/article/details/52793183

Ubuntu16.04上gtx1080的cuda安装

July 17 2016

目前tensorflow是一个非常流行的深度学习计算框架,常规硬件及系统的安装方法官方的doc已经说的很清楚了,但是 因为系统是ubuntu16.04,显卡是GTX1080,所以不可避免的要折腾起来。在上一篇已经在16.04上安装好了驱动。接下来其实 重点安装的是CUDA和cuDNN.

首先说为什么要安装CUDA和cuDNN,关于采用GPU计算比CPU有速度有多少提升的benchmark找找就有,这次重点是怎么让tensorflow充分用的 上GTX1080能力。具体的就是如何把支持GTX1080的CUDA和cuDNN装起来,然后让tensorflow认识我们新装的CUDA和cuDNN。

首先总体说下安装步骤:

1 首先要注册NVIDIA developer的帐号,分别下载CUDA和cuDNN

2 确认准备gcc版本,安装依赖库sudo apt-get install freegl

3 安装CUDA

4 解压cuDNN

5 clone tensorflow源码,configure配置

6 编译安装

7 最后一哆嗦,测试!

准备工作

在正式开始前,猜核尺需要做几个准备工作,主要是大概先看下文档

cuda FAQ

tensorflow 的安装文档

cuda-gpu的支持列表/计算能力/FAQ

cudnn 5.1有多牛

cuda tookit下载页面

CUDA_Installation_Guide_Linux.pdf

cudnn User Guide

文档看过之后接下来就是实际动手的过程:

1 注册NVIDIA developer的帐号,分别下载CUDA和cuDNN

1.1 下载CUDA 打开cuda toolkit下载页面,GTX1080 要用的是CUDA 8。先点击JOIN,注册帐号。 完了后,再回到cuda toolkit下载页面。选择 linux, x86-64, ubuntu, 16.04, runfile(local)

1.2 下载cuDNN 进入cudnn的下载页,一堆调查,日志写时下载的是[Download cuDNN v5 (May 27, 2016), for CUDA 8.0 RC],点开选linux,不出意外的话这个就是下载地址.

2 确认GCC版本,安装依赖库

确认本机穗高gcc版本,16.04默认的是gcc 5,这里安装需要的最高是gcc 4.9。接下来就氏答安装配置gcc 4.9.

2.1 安装gcc 4.9,并修改系统默认为4.9

sudo apt-get install gcc-4.9 gcc-4.9 g++-4.9 g++-4.9gcc –versionsudo update-alternatives –install /usr/bin/g++ g++ /usr/bin/g++-4.9 10sudo update-alternatives –install /usr/bin/cc cc /usr/bin/gcc 30sudo update-alternatives –set cc /usr/bin/gccsudo update-alternatives –install /usr/bin/c++ c++ /usr/bin/g++ 30sudo update-alternatives –set c++ /usr/bin/g++gcc –version

2.2 一个小依赖

sudo apt-get install freegl

3 安装CUDA

需要注意的是这个地方有个选择安装低版本驱动的地方,选n 大致的安装流程如下:

3.1 安装CUDA

chmod +x /cuda_8.0.27_linux.run./cuda_8.0.27_linux.run….Do you accept the previously read EULA?accept/decline/quit: acceptInstall NVIDIA Accelerated Graphics Driver for Linux-x86_64 361.62?(y)es/(n)o/(q)uit: nInstall the CUDA 8.0 Toolkit?(y)es/(n)o/(q)uit: yEnter Toolkit Location[ default is /usr/local/cuda-8.0 ]: Do you want to install a symbolic link at /usr/local/cuda?(y)es/(n)o/(q)uit: yInstall the CUDA 8.0 Samples?(y)es/(n)o/(q)uit: yEnter CUDA Samples Location[ default is /home/h ]: /home/h/Documents/cuda_samples….

3.2 写入环境变量

vim ~/.bashrc#添加下面变量export PATH=/usr/local/cuda-8.0/bin${PATH:+:${PATH}}export LD_LIBRARY_PATH=/usr/local/cuda-8.0/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}

3.3 安装好后简单验证

a. 进入刚配置时指定的cuda sample所在文件夹,NVIDIA_CUDA-8.0_Samples/

b. cd 0_Simple/asyncAPI;sudo make

c. NVIDIA_CUDA-8.0_Samples/0_Simple/asyncAPI$ ./asyncAPI [./asyncAPI] – Starting… GPU Device 0: “GeForce GTX 1080” with compute capability 6.1 CUDA device [GeForce GTX 1080] time spent executing by the GPU: 10.94 time spent by CPU in CUDA calls: 0.19 CPU executed 50591 iterations while waiting for GPU to finish

4 安装cuDNN

[email protected]:~/Downloads$ tar xvzf cudnn-8.0-linux-x64-v5.0-ga.tgz cuda/include/cudnn.hcuda/lib64/libcudnn.socuda/lib64/libcudnn.so.5cuda/lib64/libcudnn.so.5.0.5cuda/lib64/libcudnn_static.a[email protected]:~/Downloads$ sudo cp -R cuda/lib64 /usr/local/cuda/lib64[email protected]:~/Downloads$ sudo mkdir -p /usr/local/cuda/include[email protected]:~/Downloads/cuda$ sudo cp include/cudnn.h /usr/local/cuda/include/sudo chmod a+r /usr/local/cuda/include/cudnn.h /usr/local/cuda/lib64/libcudnn*

5 clone, configure tensorflow

5.1 clone源码

$ git clone https://github.com/tensorflow/tensorflow

5.2 configure配置整个配置流程应该跟下面的基本一样的

[email protected]:~/Downloads/tensorflow$ cd ./tensorflow/[email protected]:~/Downloads/tensorflow$ ./configurePlease specify the location of python. [Default is /usr/bin/python]: ***Do you wish to build TensorFlow with Google Cloud Platform support? [y/N] N***No Google Cloud Platform support will be enabled for TensorFlow***Do you wish to build TensorFlow with GPU support? [y/N] y***GPU support will be enabled for TensorFlowPlease specify which gcc nvcc should use as the host compiler. [Default is /usr/bin/gcc]: **Please specify the location where CUDA toolkit is installed. Refer to README.md for more details. [Default is /usr/local/cuda]: /usr/local/cuda-8.0 ****Please specify the Cudnn version you want to use. [Leave empty to use system default]: 5.0.5****Please specify the location where cuDNN 5.0.5 library is installed. Refer to README.md for more details. [Default is /usr/local/cuda-8.0]: /usr/local/cuda**Please specify a list of comma-separated Cuda compute capabilities you want to build with.You can find the compute capability of your device at: https://developer.nvidia.com/cuda-gpus.**Please note that each additional compute capability significantly increases your build time and binary size.[Default is: "3.5,5.2"]: 6.1**Setting up Cuda includeSetting up Cuda lib64Setting up Cuda binSetting up Cuda nvvmSetting up CUPTI includeSetting up CUPTI lib64Configuration finished

6 编译安装

6.1 编译工具Bazel安装配置先看一眼文档然后就执行下面的流程:

#安装java 1.8sudo add-apt-repository ppa:webupd8team/javasudo apt-get updatesudo apt-get install oracle-java8-installer#安装好后车参考下java -version#添加源echo "deb [arch=amd64] http://storage.googleapis.com/bazel-apt stable jdk1.8" | sudo tee /etc/apt/sources.list.d/bazel.listcurl https://storage.googleapis.com/bazel-apt/doc/apt-key.pub.gpg | sudo apt-key add -#下载sudo apt-get update && sudo apt-get install bazel#升级sudo apt-get upgrade bazel

6.2 编译tensorflow的pip版本并安装

$ bazel build -c opt //tensorflow/tools/pip_package:build_pip_package# To build with GPU support:$ bazel build -c opt –config=cuda //tensorflow/tools/pip_package:build_pip_package$ bazel-bin/tensorflow/tools/pip_package/build_pip_package /tmp/tensorflow_pkg# The name of the .whl file will depend on your platform.#注意编译完成后生成的文件名字和官方doc里面的是不一定一致的$ sudo pip install /tmp/tensorflow_pkg/tensorflow-0.*-linux_x86_64.whl

i6700k 32g编译时间:

只编译代码不带pip INFO: Elapsed time: 967.271s, Critical Path: 538.38s

bazel-bin/tensorflow/tools/pip_package/build_pip_package INFO: Elapsed time: 65.183s, Critical Path: 48.58

7 最后测试

前面都整完了,现在该测试了,注意前面有两个动态链接库的位置,cuDNN在/usr/local/cuda/lib64, 而cuda在/usr/local/cuda-8.0/lib64,所以这个时候的bashrc应该这么写:

export PATH=/usr/local/cuda-8.0/bin${PATH:+:${PATH}}export LD_LIBRARY_PATH=/usr/local/cuda/lib64:/usr/local/cuda-8.0/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}

写完后,

source ~/.bashrccd tensorflow/tensorflow/models/image/mnistpython convolutional.py

成功的话会出现流畅的跑动:

[email protected]:~/Downloads/tensorflow/tensorflow/models/image/mnist$ python convolutional.pyI tensorflow/stream_executor/dso_loader.cc:108] successfully opened CUDA library libcublas.so locallyI tensorflow/stream_executor/dso_loader.cc:108] successfully opened CUDA library libcudnn.so.5.0.5 locallyI tensorflow/stream_executor/dso_loader.cc:108] successfully opened CUDA library libcufft.so locallyI tensorflow/stream_executor/dso_loader.cc:108] successfully opened CUDA library libcuda.so.1 locallyI tensorflow/stream_executor/dso_loader.cc:108] successfully opened CUDA library libcurand.so locallyExtracting data/train-images-idx3-ubyte.gzExtracting data/train-labels-idx1-ubyte.gzExtracting data/t10k-images-idx3-ubyte.gzExtracting data/t10k-labels-idx1-ubyte.gzI tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:925] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zeroI tensorflow/core/common_runtime/gpu/gpu_init.cc:102] Found device 0 with properties: name: GeForce GTX 1080major: 6 minor: 1 memoryClockRate (GHz) 1.8475pciBusID 0000:01:00.0Total memory: 7.92GiBFree memory: 7.41GiBI tensorflow/core/common_runtime/gpu/gpu_init.cc:126] DMA: 0 I tensorflow/core/common_runtime/gpu/gpu_init.cc:136] 0: Y I tensorflow/core/common_runtime/gpu/gpu_device.cc:838] Creating TensorFlow device (/gpu:0) -> (device: 0, name: GeForce GTX 1080, pci bus id: 0000:01:00.0)Initialized!Step 0 (epoch 0.00), 8.4 msMinibatch loss: 12.054, learning rate: 0.010000Minibatch error: 90.6%Validation error: 84.6%……Minibatch error: 0.0%Validation error: 0.7%Step 8500 (epoch 9.89), 4.7 msMinibatch loss: 1.601, learning rate: 0.006302Minibatch error: 0.0%Validation error: 0.9%Test error: 0.8%


赞 (0)