Lib graphviz cannot be loaded when using itorch - lua

I'm learning the torch following the tutorials provided by torch team. When I typed lines below as provided by 'NNGraph Tutorial', sth unexpected happened:
-- it is common style to mark inputs with identity nodes for clarity.
input = nn.Identity()()
-- each hidden layer is achieved by connecting the previous one
-- here we define a single hidden layer network
h1 = nn.Tanh()(nn.Linear(20, 10)(input))
output = nn.Linear(10, 1)(h1)
mlp = nn.gModule({input}, {output})
x = torch.rand(20)
dx = torch.rand(1)
mlp:updateOutput(x)
mlp:updateGradInput(x, dx)
mlp:accGradParameters(x, dx)
-- draw graph (the forward graph, '.fg')
-- this will produce an SVG in the runtime directory
graph.dot(mlp.fg, 'MLP', 'MLP')
itorch.image('MLP.svg')
Error information:
...s/noahcao/torch/install/share/lua/5.2/graph/graphviz.lua:157: graphviz library could not be loaded.
stack traceback:
/Users/noahcao/torch/install/share/lua/5.2/itorch/main.lua:167: in function </Users/noahcao/torch/install/share/lua/5.2/itorch/main.lua:160>
[C]: in function 'error'
...s/noahcao/torch/install/share/lua/5.2/graph/graphviz.lua:157: in function 'graphvizFile'
...s/noahcao/torch/install/share/lua/5.2/graph/graphviz.lua:197: in function 'dot'
[string "-- it is common style to mark inputs with ide..."]:18: in main chunk
[C]: in function 'xpcall'
/Users/noahcao/torch/install/share/lua/5.2/itorch/main.lua:210: in function </Users/noahcao/torch/install/share/lua/5.2/itorch/main.lua:174>
(...tail calls...)
/Users/noahcao/torch/install/share/lua/5.2/lzmq/poller.lua:75: in function 'poll'
...s/noahcao/torch/install/share/lua/5.2/lzmq/impl/loop.lua:307: in function 'poll'
...s/noahcao/torch/install/share/lua/5.2/lzmq/impl/loop.lua:325: in function 'sleep_ex'
...s/noahcao/torch/install/share/lua/5.2/lzmq/impl/loop.lua:370: in function 'start'
/Users/noahcao/torch/install/share/lua/5.2/itorch/main.lua:389: in main chunk
[C]: in function 'require'
(command line):1: in main chunk
[C]: in ?
But I checked the graphviz.lua file, that seems OK. I couldn't understand what the information wants to tell me.

I have also faced the same issue. This solved my issue:
# Mac users
brew install graphviz
# Debian/Ubuntu users
sudo apt-get install graphviz -y
Hope this might help someone.
Please check this link for Graph package of Torch.

Related

neovim init.lua module "lua.plguins" not found

I'm in the configuration neovim
I added the configuration file in C:\Users\wupan\AppData\Local\nvim\init.lua
require("lua.plugins")
and C:\Users\wupan\AppData\Local\nvim\lua\plugins.lua
return require('packer').startup(function()
use "wbthomason/packer.nvim"
end)
After the start-up neovim
Error detected while processing C:\Users\wupan\AppData\Local\nvim\init.lua:
E5113: Error while calling lua chunk: C:\Users\wupan\AppData\Local\nvim\init.lua:1: module 'lua.plugins' not found:
no field package.preload['lua.plugins']
no file '.\lua\plugins.lua'
no file 'C:\Users\wupan\scoop\apps\neovim\current\bin\lua\lua\plugins.lua'
no file 'C:\Users\wupan\scoop\apps\neovim\current\bin\lua\lua\plugins\init.lua'
no file '.\lua\plugins.dll'
no file 'C:\Users\wupan\scoop\apps\neovim\current\bin\lua\plugins.dll'
no file 'C:\Users\wupan\scoop\apps\neovim\current\bin\loadall.dll'
no file '.\lua.dll'
no file 'C:\Users\wupan\scoop\apps\neovim\current\bin\lua.dll'
no file 'C:\Users\wupan\scoop\apps\neovim\current\bin\loadall.dll'
stack traceback:
[C]: in function 'require'
C:\Users\wupan\AppData\Local\nvim\init.lua:1: in main chunk
Press ENTER or type command to continue
May I ask why
I tried to install Lua test the require
scoop install lua
C:\Users\wupan\code\lua\test.lua
require("hello")
C:\Users\wupan\code\lua\hello.lua
print("hello world")
There are also problems
C:\Users\wupan\scoop\apps\lua\current\lua54.exe: .\test.lua:1: module 'hello' not found:
no field package.preload['hello']
no file 'C:\Users\wupan\scoop\apps\lua\current'
no file 'C:\Users\wupan\scoop\apps\lua\current'
stack traceback:
[C]: in function 'require'
.\test.lua:1: in main chunk
[C]: in ?
Problem analysis
Let's use the following example which you gave us:
C:\Users\wupan\AppData\Local\nvim\init.lua
require("lua.plugins")
C:\Users\wupan\AppData\Local\nvim\lua\plugins.lua
return require('packer').startup(function()
use "wbthomason/packer.nvim"
end)
And now let's take a look into your error message:
no file 'C:\Users\wupan\scoop\apps\neovim\current\bin\lua\lua\plugins.lua'
The important part is the bin\lua\lua thing here. It's because your
require("lua.plugins") starts to look up a directory in one of your runtime
path (see :h rtp for more information).
Solution
You just need to fix your content in
C:\Users\wupan\AppData\Local\nvim\init.lua to:
require("plugins")
because then neovim will look up a directory which is named plugins in
C:\Users\wupan\scoop\apps\neovim\current\bin\lua for example, since its in
your runtime path.
Little note
You can change your content from
C:\Users\wupan\AppData\Local\nvim\lua\plugins.lua to:
require('packer').startup(function()
use "wbthomason/packer.nvim"
end)
or how I did it:
local packer = require('packer')
packer.startup(function(use)
use 'wbthomason/packer.nvim'
end)
That makes it a little bit more readable in my opinion :)

SimilarityMeasure is an invalid module name

This is a follow-up to my earlier question Lua: Semantic Similarity using Neural Networks.
For Semantic similarity I've execute the following code,
include('Conv.lua')
modelTrained = torch.load("download_local_location/modelSTS.trained.th", 'ascii')
modelTrained.convModel:evaluate()
modelTrained.softMaxC:evaluate()
local linputs = torch.zeros(rigth_sentence_length, emd_dimension)
linpus = XassignEmbeddingValuesX
local rinputs = torch.zeros(left_sentence_length, emd_dimension)
rinpus = XassignEmbeddingValuesX
local part2 = modelTrained.convModel:forward({linputs, rinputs})
local output = modelTrained.softMaxC:forward(part2)
local val = torch.range(0, 5, 1):dot(output:exp())
return val/5
And Execute it using the following command in terminal,
> th similarity.lua
But the error it displays is,
while creating metatable similarityMeasure.Conv: bad argument #1 (similarityMeasure is an invalid module name)
stack traceback:
[C]: in function 'newmetatable'
/torch/install/share/lua/5.2/torch/init.lua:102: in function 'class'
.../textSimilarityConvNet-master/Conv.lua:1: in main chunk
[C]: in function 'dofile'
/torch/install/share/lua/5.2/paths/init.lua:84: in function 'dofile'
/torch/install/share/lua/5.2/torch/init.lua:49: in function 'include'
similarity.lua:1: in main chunk
[C]: in function 'dofile'
.../torch/install/lib/luarocks/rocks/trepl/scm-1/bin/th:150: in main chunk
[C]: in ?
First few lines in Conv.lua is,
local Conv = torch.class('similarityMeasure.Conv')
function Conv:__init(config)
self.mem_dim = config.mem_dim or 150
self.learning_rate = config.learning_rate or 0.01
self.batch_size = config.batch_size or 1 --25
self.num_layers = config.num_layers or 1
self.reg = config.reg or 1e-4
self.structure = config.structure or 'lstm' -- {lstm, bilstm}
self.sim_nhidden = config.sim_nhidden or 150
self.task = config.task or 'sic' -- or 'vid'
-- word embedding
self.emb_vecs = config.emb_vecs
self.emb_dim = config.emb_vecs:size(2)
Please guide me to solve this.
You are missing the similarityMeasure module (and likely other modules as well). I'm guessing that the things you are missing are dependencies that are not included with the default Torch installation. The installation instructions in the Github respository's readme file say the following:
Please install Torch deep learning library. We recommend this local
installation which includes all required packages our tool needs,
simply follow the instructions here: https://github.com/torch/distro
If you installed Torch some other way, try doing it using the linked distro instead and see if that fixes the problem.
It should work. Also the repo has been recently updated.
https://github.com/castorini/MP-CNN-Torch
Once you installed the torch library properly, then you can check and see the newly added/provided testDeployment.lua file, as an example to see how to use the trained model properly.

Got `internal error in __sub: no metatable` error in Lua and Torch

I tried to create a image-to-image model by pix2pix (https://github.com/phillipi/pix2pix) and followed Getting Started instruction.
Then, downloaded facades dataset by bash ./datasets/download_dataset.sh facades
and run DATA_ROOT=./datasets/facades name=facades_generation which_direction=BtoA th train.lua
but I got the following error.
~/torch-cl/install/bin/luajit: ./models.lua:69: internal error in
__sub: no metatable stack traceback: [C]: in function '__sub' ./models.lua:69: in function 'defineG_unet' train.lua:110: in
function 'defineG' train.lua:146: in main chunk [C]: in function
'dofile'
...i/torch-cl/install/lib/luarocks/rocks/trepl/scm-1/bin/th:145: in
main chunk [C]: at 0x010ec81ce0
Does anyone know how I can fix this?
I'm new to Lua and Torch, so have no idea how to fix this.
Thank you
this is run on Mac OSX
python2.7

Bug encountered When running Google's Deep Q Network Code

Google's Deep Q Network for Atari Games is here.
https://github.com/rahular/deepmind-dqn
When I run it with GPU setting
./run_gpu <game name>
I had this error
../torch/bin/luajit: ./convnet.lua:22: attempt to call local 'convLayer' (a nil value)
stack traceback:
./convnet.lua:22: in function 'network'
./NeuralQLearner.lua:89: in function '__init'
...einforcement_Learning/torch/share/lua/5.1/torch/init.lua:51: in function <...einforcement_Learning/torch/share/lua/5.1/torch/init.lua:47>
[C]: at 0x7f419423d380
./initenv.lua:133: in function 'setup'
train_agent.lua:52: in main chunk
[C]: at 0x00406230
The code that caused this issue is in this file https://github.com/rahular/deepmind-dqn/blob/master/dqn/convnet.lua
and it is in this function
function create_network(args)
local net = nn.Sequential()
net:add(nn.Reshape(unpack(args.input_dims)))
--- first convolutional layer
local convLayer = nn.SpatialConvolution
if args.gpu >= 0 then
net:add(nn.Transpose({1,2},{2,3},{3,4}))
convLayer = nn.SpatialConvolutionCUDA
end
net:add(convLayer(args.hist_len*args.ncols, args.n_units[1],
args.filter_size[1], args.filter_size[1],
args.filter_stride[1], args.filter_stride[1],1))
net:add(args.nl())
The net:add(convLayer( is 22th line.
I used gpu setting so it seems
convLayer = nn.SpatialConvolutionCUDA
caused convLayer to be nil.
Does anyone know why nn.SpatialConvolutionCUDA returns a nil ?
Did the code originally come with GPU support, or did you add it yourself?
You should replaced the depreceated layers, i.e. replace:
net:add(nn.Transpose({1,2},{2,3},{3,4}))
convLayer = nn.SpatialConvolutionCUDA
with
convLayer = nn.SpatialConvolution
Check the documentation for the layers.
Edit: Use this branch, I fixed it for GPU support.
Found the solution.
using this github branch
https://github.com/soumith/deepmind-atari
After cloning this branch, then install cutorch and cunn using luarocks.
Now you can run the code.

Sublime Text FormatLua Error

I'm trying to format code with a package I installed for Sublime Text 3 - FormatLua.
However, I'm getting this error when I try to use it...
/usr/local/bin/lua: ./metalua/compiler.lua:119:
./metalua/compiler/bytecode/lopcodes.lua:284: attempt to call field
'gfind' (a nil value) stack traceback:
[C]: in function 'error'
./metalua/compiler.lua:119: in function 'get_bytecode_compiler'
./metalua/compiler.lua:125: in function 'f'
./metalua/compiler.lua:153: in function <./metalua/compiler.lua:150>
(...tail calls...)
[C]: in function 'require'
formatter.lua:24: in main chunk
[C]: in ?
Does anyone know what I must do to fix this issue? I must be missing some files - I see that gfind is nil (this was taken out after 5.0), but I don't want to mess with anything unless I'm sure I know what I'm doing. Thanks!
Yes, gfind was deprecated. You can replace string.gfind with string.gmatch. I applied a similar change for the same reason; here is the commit.
Works well after downgrading lua version to 5.1.4
Compiling from source code:
Lua 5.1.4 here: http://www.lua.org/ftp/lua-5.1.4.tar.gz:
Open your Terminal.app
wget http://www.lua.org/ftp/lua-5.1.4.tar.gz
tar xvzf lua-5.1.4.tar.gz
cd lua-5.1.4
make macosx
make install

Resources