安装 Torch

发布于 2021-07-04 21:02:09 字数 3267 浏览 1961 评论 0

官方提供在 Mac OS X 和 Ubuntu 12+ 上安装Torch:

你可以通过如下三个命令把 Torch 安装到你的 home 文件夹中,注意:包比较大,需要耐心等待:

#在终端运行命令没有sudo
git clone https://github.com/torch/distro.git ~/torch --recursive
cd ~/torch; bash install-deps;
./install.sh

第一个脚本安装基本的软件包的依赖关系,要求 LuaJIT 和 Torch。第二脚本安装 LuaJITluarocks,然后使用 luarocks(Lua包管理器)安装核心包像 TorchNN 和路径,以及一些其他的包。 该脚本添加到您的路径变量 Torch。你只需要一次就可以刷新你的环境变量。安装脚本将检测您当前的 shell,并在正确的配置文件中修改路径。

# On Linux with bash
source ~/.bashrc
# On Linux with zsh
source ~/.zshrc
# On OSX or in Linux with none of the above.
source ~/.profile

如果你需要卸载 Torch,只需运行命令:

rm -rf ~/torch

如果你想安装 Torch 的 lua 5.2 代替 LuaJIT,简单地运行:

git clone https://github.com/torch/distro.git ~/torch --recursive
cd ~/torch

# clean old torch installation
./clean.sh
# optional clean command (for older torch versions)
# curl -s https://raw.githubusercontent.com/torch/ezinstall/master/clean-old.sh | bash

# https://github.com/torch/distro : set env to use lua
TORCH_LUA_VERSION=LUA52 ./install.sh

新的软件包,可以使用命令行 luarocks 安装:

# run luarocks WITHOUT sudo
$ luarocks install image
$ luarocks list

一旦安装好,你就可以用你的命令运行 Torch 了! 在学习和试验Torch的最简单的方法是启动一个交互式会话(也被称为 TorchRead-Eval-Print-Loop 或 trepl):

$ th

  ______             __   |  Torch7                                   
 /_  __/__  ________/ /   |  Scientific computing for Lua.         
  / / / _ \/ __/ __/ _ \  |                                           
 /_/  \___/_/  \__/_//_/  |  https://github.com/torch   
                          |  http://torch.ch            

th> torch.Tensor{1,2,3}
 1
 2
 3
[torch.DoubleTensor of dimension 3]

th>

退出交互会话,型 ^C 两控制键和C键,两次,或类型的操作系统。exit()。一旦用户输入了一个完整的表达式,如 1 + 2,并点击进入,交互会话将计算表达式并显示其值。 评价写在一个源文件file.lua表达式,写dofile”文件。lua”。 要在非交互式的文件中运行代码,可以将它作为第一个参数传递给TH命令::

$ th file.lua

有不同的方法来运行 lua 代码和提供选项,类似于那些用于 Perl 和 Ruby 程序:

$ th -h
Usage: th [options] [script.lua [arguments]]

Options:
  -l name            load library name
  -e statement       execute statement
  -h,--help          print this help
  -a,--async         preload async (libuv) and start async repl (BETA)
  -g,--globals       monitor global variables (print a warning on creation/access)
  -gg,--gglobals     monitor global variables (throw an error on creation/access)
  -x,--gfx           start gfx server and load gfx env
  -i,--interactive   enter the REPL after executing a script

TREPL充满了方便的特性:

  1. tab补齐在嵌套名称空间
  2. 打开磁盘文件(打开字符串时)
  3. 历史(会话之间保存)
  4. 漂亮的打印(表内省和着色)
  5. eval(可以停止)自动打印(可以停止)
  6. 每个命令都被提交,时间被报告
  7. 不需要“=”打印
  8. 简单的帮助:?funcname
  9. 自助:?
  10. Shell命令:$ cmd(示例:$ ls)

接下来的步骤 除了这本手册,还有各种其他的资源,可以帮助新用户开始使用Torch,都总结在本列表 该控件提供的教程,演示,包总结和大量有用的信息。 如果你有问题,请加入Torch手用户名单。

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

关于作者

JSmiles

生命进入颠沛而奔忙的本质状态,并将以不断告别和相遇的陈旧方式继续下去。

0 文章
0 评论
84959 人气
更多

推荐作者

花开柳相依

文章 0 评论 0

zyhello

文章 0 评论 0

故友

文章 0 评论 0

对风讲故事

文章 0 评论 0

Oo萌小芽oO

文章 0 评论 0

梦明

文章 0 评论 0

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文