You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
require 'dpnn'
require 'cunn'
local deviceNumber = tonumber(os.getenv("CUDA_CARD_NR"))
cutorch.setDevice(deviceNumber)
local module = nn.Sequential():cuda()
module:add(nn.Linear(2,1):cuda())
module:add(nn.Sigmoid():cuda())
criterion = nn.BCECriterion():cuda() -- Binary Cross Entorpy Criteria
local targets = torch.CudaTensor(10):random(0,1)
local inputs = torch.CudaTensor(10,2):uniform(-1,1)
function trainEpoch(module,criterion,inputs,targets)
for i=1,inputs:size(1) do
local idx = math.random(1,inputs:size(1))
local input, target = inputs[idx], targets:narrow(1,idx,1)
-- forward
local output= module:forward(input)
local loss= criterion:forward(output,target)
-- backward
local gradOutput = criterion:backward(output,target)
module:zeroGradParameters()
local gradInput = module:backward(input,gradOutput)
--update
module:updateGradParameters(0.9) -- momentum
module:updateParameters(0.1) -- W = W -0.1*dL/dW
end
end
for i=1,100 do
trainEpoch(module,criterion,inputs,targets)
end
I am running above using the following command
`CUDA_CARD_NR=1 luajit feedforwad.lua
`
It gives the following error
luajit: feedforwad.lua:13: attempt to call method 'random' (a nil value)
stack traceback:
feedforwad.lua:13: in main chunk
[C]: at 0x004064f0
Hi,
I've only used torch.Tensor, nt CudaTensor.
I found this issue where they mention that the random API is not fully implemented in CudaTorch.
Can you try to use targets = torch.Tensor( .. ) instead, and later transfer it to the GPU by running targets:cuda()? That's how I've done training on the GPU.
Just as a note: None of this has anything to do with trAInsported code, though. You'll probably be getting more helpful comments on torch forums.
P.S. Training the trains with torch - awesome idea! I look forward to seeing the results! :)
Below is my code
I am running above using the following command
`
It gives the following error
I know that there is some error in the line
But I am not able to figure out. Any help would be appreciated.
Thanks in advance.
The text was updated successfully, but these errors were encountered: