【问题标题】:attempt to index field 'icgnn' (a nil value)尝试索引字段“icgnn”(零值)
【发布时间】:2018-12-30 22:24:19
【问题描述】:

这是我正在使用的代码:

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 是一个模块。

【问题讨论】:

    标签: lua torch


    【解决方案1】:

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

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

    【讨论】:

    • 我认为 icgnn 是一个模块。我很困惑的是为什么不使用 icgnn.IcgResample_updateOutput(self,input) 而不是 input.icgnn.IcgResample_updateOutput(self, input)
    • 我想这一定是火炬的事情,是什么叫function IcgResample:updateOutput(input)?你能找出它被调用的地方以及它作为“输入”传递的内容吗?
    • input是一个cudaTensor,IcgResample_updateOutput是c语言实现的,我不知道在哪里调用。
    猜你喜欢
    • 2012-03-12
    • 2020-05-28
    • 1970-01-01
    • 2019-10-10
    • 2013-06-18
    • 2011-11-05
    • 1970-01-01
    相关资源
    最近更新 更多