ubuntu14.04安装matconvnet:
1.首先你的显卡得是INVIDA的,并且需要compute compability>2.0.
可以通过MATLAB输入:gpuDevice来确定你的显卡:
>> gpuDevice
ans =
CUDADevice with properties:
Name: 'GeForce 920M'
Index: 1
ComputeCapability: '3.5'
SupportsDouble: 1
DriverVersion: 8
ToolkitVersion: 5.5000
MaxThreadsPerBlock: 1024
MaxShmemPerBlock: 49152
MaxThreadBlockSize: [1024 1024 64]
MaxGridSize: [2.1475e+09 65535 65535]
SIMDWidth: 32
TotalMemory: 2.1010e+09
FreeMemory: 2.0546e+09
MultiprocessorCount: 2
ClockRateKHz: 954000
ComputeMode: 'Default'
GPUOverlapsTransfers: 1
KernelExecutionTimeout: 0
CanMapHostMemory: 1
DeviceSupported: 1
DeviceSelected: 1
cuda的话,可以去下载最高版本的。
下载地址:https://developer.nvidia.com/cuda-downloads 。(我的已安装好,没安装的可以百度其他的网址安装)
2.下载matconvnet:http://www.vlfeat.org/matconvnet/
解压tar -xzvf matconvnet-1.0-beta24.tar.gz
3.
本机配置:
Ubuntu 14.04 + MATLAB 2014a + Cuda8.0
4.安装libjpeg:
sudo apt-get install libjpeg-dev
5.修改MatConvNet工具包下的makefile:ENABLE_GPU ?= y
ENABLE_IMREADJPEG ?= y
ARCH ?= glnxa64
CUDAROOT ?= /usr/local/cuda-6.5
MATLABROOT ?= /usr/local/MATLAB/R2014a
CUDAMETHOD ?= nvcc
打开matlab:
一般编译:
vl_compilenn
使用CUDA编译:
vl_compilenn('enableGpu',true)
使用cudnn编译(路径名需要根据实际情况设置):
- vl_compilenn('enableGpu',true,...
- 'cudaMethod','nvcc',...
- 'cudaRoot','/usr/local/cuda/',...
- 'enableCudnn',...
- 'cudnnRoot','/usr/local/cuda')
vl_testnn
8.测试GPU可以用
- %setupMtConvNetinMATLAB
- runmatlab/vl_setupnn
- %downloadapre-trainedCNNfromtheweb
- urlwrite('http://www.vlfeat.org/sandBox-matconvnet/models/imagenet-vgg-f.mat',...
- 'imagenet-vgg-f.mat');
- net=load('imagenet-vgg-f.mat');
- %obtainandpreprocessanimage
- im=imread('peppers.png');
- im_=single(im);%note:255range
- im_=imresize(im_,net.normalization.imageSize(1:2));%resize为224*224大小的矩阵
- im_=im_-net.normalization.averageImage;%averageImage代表ImageNet统计到的图像均值信息,为224*224*3的矩阵<pre
- %runtheCNN
- res=vl_simplenn(net,im_);
- %showtheclassificationresult
- scores=squeeze(gather(res(end).x));
- [bestscore,best]=max(scores);
- figure(1);clf;imagesc(im);
- title(sprintf('%s(%d),score%.3f',...
- net.classes.description{best},best,bestscore));