Torch中多GPU运行代码学习

Main.lua  

 

-- Copyright (c) 2014, Facebook, Inc.

 

-- All rights reserved.

 

--

 

-- This source code is licensed under the BSD-style license found in the

 

-- LICENSE file in the root directory of this source tree. An additional grant

 

-- of patent rights can be found in the PATENTS file in the same directory.

 

--

 

require 'torch'

 

require 'cutorch'

 

require 'paths'

 

require 'xlua'

 

require 'optim'

 

require 'nn'

 

 

 

torch.setdefaulttensortype('torch.FloatTensor')

 

 

 

local opts= paths.dofile('opts.lua')

 

 

 

opt = opts.parse(arg)

 

 

 

nClasses = opt.nClasses

 

 

 

paths.dofile('util.lua')

 

paths.dofile('model.lua')

 

opt.imageSize = model.imageSizeor opt.imageSize

 

opt.imageCrop = model.imageCropor opt.imageCrop

 

 

 

print(opt)

 

 

 

cutorch.setDevice(opt.GPU)-- by default, use GPU 1

 

torch.manualSeed(opt.manualSeed)

 

 

 

print('Saving everything to: ' .. opt.save)

 

os.execute('mkdir -p ' .. opt.save)

 

 

 

paths.dofile('data.lua')

 

paths.dofile('train.lua')

 

paths.dofile('test.lua')

 

 

 

epoch = opt.epochNumber

 

 

 

for i=1,opt.nEpochsdo

 

train()

 

test()

 

epoch = epoch+ 1

 

end

 

The training scripts come with several options which can be listed by running the script with the flag --help

th main.lua --help

To run the training, simply run main.lua By default, the script runs 1-GPU AlexNet with the CuDNN backend and 2 data-loader threads.

th main.lua -data [imagenet-folder with train and val folders]

For 2-GPU model parallel AlexNet + CuDNN, you can run it this way:

th main.lua -data [imagenet-folder with train and val folders] -nGPU 2 -backend cudnn -netType alexnet

Similarly, you can switch the backends to 'cunn' to use a different set of CUDA kernels.

You can also alternatively train OverFeat using this following command:

th main.lua -data [imagenet-folder with train and val folders] -netType overfeat

# multi-GPU overfeat (let's say 2-GPU)

th main.lua -data [imagenet-folder with train and val folders] -netType overfeat -nGPU 2

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值