FAQ Database Discussion Community

How to read Torch Tensor from C [closed]

I have to train a convolutional neural network using the Torch framework and then write the same network in C. To do so, I have to read somehow the learned parameters of the net from my C program, but I can't find a way to convert or write to a...

How to get a layer from a caffe model using torch

In python when I want to get the data from a layer using caffe I have the following code input_image = caffe.io.load_image(imgName) input_oversampled = caffe.io.resize_image(input_image, self.net.crop_dims) prediction = self.net.predict([input_image]) caffe_input = np.asarray(self.net.preprocess('data', prediction)) self.net.forward(data=caffe_input) data = self.net.blobs['fc7'].data[4] // I want to get this value in lua Hoever when I'm using...

torch7 : how to connect the neurons of the same layer?

Is it possible to implement, using torch, an architecture that connects the neurons of the same layer?

Why does torch.Tensor have a libjpeg field?

I see this: ./install/share/lua/5.1/image/init.lua: return torch.Tensor().libjpeg.size(filename) How does Tensor get the field libjpeg? I don't see it referenced in Tensor.lua. For more context, I am trying to debug this error: /Users/un/torch/install/share/lua/5.1/image/init.lua:140: attempt to index field 'libjpeg' (a nil value) stack traceback: /Users/un/torch/install/share/lua/5.1/image/init.lua:140: in function 'loader' /Users/un/torch/install/share/lua/5.1/image/init.lua:276: in function 'load'...

Strange C syntax in Lua library

I see functions like this throughout the torch library's C code: long THTensor_(storageOffset)(const THTensor *self) { return self->storageOffset; } Is this a preprocessor thing, or something lua specific? The idea, I think has something to do with the fact that storageOffset is a method of sorts on the THTensor "class",...

Issue with neuralnetwork_turial.lua with data preprocessing

I have installed the torch deep learning module by first git clone-ing and later using luarocks make and the installation was succussful. The require 'dp' works well in the torch prompt. But when I try to execute the neuralnetwork_tutorial.lua(th neuralnetwork_tutorial.lua), it throws the following errors. Tanny @neuralnetwork_tutorial.lua: About to initiate:...

Torch Lua: Why is my gradient descent not optimizing the error?

I've been trying to implement a siamese neural network in Torch/Lua, as I already explained here. Now I have my first implementation, that I suppose to be good. Unfortunately, I'm facing a problem: during training back-propagation, the gradient descent does not update the error. That is, it always computes the...

itorch creates a python console, not a torch console

When I call itorch I don't get a torch console but an ipython console: ~$ itorch Python 2.7.3 (default, Dec 18 2014, 19:10:20) Type "copyright", "credits" or "license" for more information. IPython 0.12.1 -- An enhanced Interactive Python. ? -> Introduction and overview of IPython's features. %quickref -> Quick reference....

How to permanently add directory to Lua search path?

What's a simple way to permanently add a directory to the Lua search path?

Torch tensor equivalent command to matlab's “find”?

In a nutshell, I would like to know if there is a tensor command in torch that gives me the indices of elements in a tensor that satisfy a certain criteria. Here is matlab code that illustrates what I would like to be able to do in torch: my_mat =...

How to change working directory in Torch REPL

Title says it all, how can one change the working directory inside the Torch REPL? I tried using calls to os.execute('cd some_dir') but this doesn't work, as demonstrated here. th> pwd() --prints: /home/user/Code th> os.execute('cd ..') --prints: true exit 0 th> pwd() -- prints: /home/user/Code where pwd() is a a...

How to specify startup file for Torch REPL

I'd like to define some command line convenience functions to be run every time I start the Torch REPL. For example, function cl() os.execute('clear') end and things of that nature. How can I have functions like this added to the namespace every time I start the REPL? I web searched...

In trepl or luajit, how can I find the source code of a library I'm using?

Let's say I'm working with a lua library I installed using luarocks, and I want to see the definition of a function from that library. In ipython in could use ??function_name to see the definition in the terminal, in matlab I could use which function_name then use my editor to...

Fast way to initialize a tensor in torch7

I need to initialize a 3D tensor with an index-dependent function in torch7, i.e. func = function(i,j,k) --i, j is the index of an element in the tensor return i*j*k --do operations within func which're dependent of i, j end then I initialize a 3D tensor A like this: for...

How to disable omp in Torch nn package?

Specifically I would like nn.LogSoftMax to not use omp when the size of the input tensor is small. I have a small script to test the run time. require 'nn' my_lsm = function(t) o = torch.zeros((#t)[1]) sum = 0.0 for i = 1,(#t)[1] do o[i] = torch.exp(t[i]) sum = sum...

Convolution Neural Network in torch. Error when training the network

I am trying to base my Convolution neural network upon the following tutorial: https://github.com/torch/tutorials/tree/master/2_supervised The issue is that my images are of different dimensions than those used in the tutorial. (3x200x200). Also I have only two classes. The following are the changes that I made : Changing the dataset to...

Lua error loading module 'libpng' (Torch, MacOSX)

How do I make libpng load properly in Lua? I am running Lua/Torch in iTorch Notebook in Mac OSX 10.10.3, where other basic functions in Lua work, such as plotting and calculations. brew install libpng Warning: libpng-1.6.17 already installed If I run: require 'nn'; require 'image'; itorch.image(image.lena()) error loading module...