尝试索引字段“ icgnn”(nil值)

时间:2018-07-23 12:50:44

标签: lua torch

这是我使用的代码:

local IcgResample, Parent = torch.class('icgnn.IcgResample', 'nn.Module')

function IcgResample:__init(inter_method, height_factor, width_factor, antialiasing)
  Parent.__init(self)

  if inter_method then
    self.inter_method = inter_method 
  else 
    error('you have to specify an interpolation method')
  end

  self.height_factor = height_factor or 2
  self.width_factor = width_factor or height_factor

  if self.height_factor <= 0 or self.width_factor <= 0 then
    error('factors have to be > 0')
  end

  if antialiasing then 
    self.antialiasing = true
  else
    self.antialiasing = false
  end
end 

function IcgResample:updateOutput(input)
  input.icgnn.IcgResample_updateOutput(self, input)
  return self.output
end 

function IcgResample:updateGradInput(input, gradOutput)
  input.icgnn.IcgResample_updateGradInput(self, input, gradOutput)
  return self.gradInput
end

我遇到了标题错误。我是lua的新手,所以我急于运行此代码,有人知道如何解决该问题吗? 我已经打印了输入,这是一个cudaTensor。 icgnn是一个模块。

1 个答案:

答案 0 :(得分:0)

问题是输入没有有一个icgnn字段。该错误告诉您您正在尝试somevariable.icgnn.someproperty,但是somevariable.icgnn为nil。 “索引”是指尝试访问命名字段上的属性:codepad sample

local variable = {}
variable.exists = {}
print(variable.exists.message) -- fine
print(variable.icgnn.message)  -- error, trying to index field icgnn that is nil