在将输入馈送到NN时出现分段错误(核心已转储)

时间:2019-06-27 13:38:04

标签: lua deep-learning torch

在将输入馈入神经网络时会出现问题,正确加载了模型,但在提供输入时将其转储了。

lua文件

require 'torch'   -- torch
require 'optim'
require 'nn'      -- provides a normalization operator

function string:split(sep)
  local sep, fields = sep, {}
  local pattern = string.format("([^%s]+)", sep)
  self:gsub(pattern, function(substr) fields[#fields + 1] = substr end)
  return fields
end

local f_file = io.open(arg[1], 'r')
local p_file = io.open(arg[2], 'w')
local data = torch.Tensor(1, 351)
local name = ''
for line in f_file:lines('*l') do
local l = line:split(',')
first = true
    for key, val in ipairs(l) do
      if first == false then
      data[1][key] = val
      else data[1][key] = 0
      first = false
      name = val
      end
    end
end

local X = data[{{},{2,-1}}]
print(X)
model = torch.load('estimation_model.dat')
local myPrediction = model:forward(X)
p_file:write('NAME,F1,F2,F3,F4\n')
p_file:write(name..','..tostring(1000*myPrediction[1] 
[1])..','..tostring(1000*myPrediction[1] 
[2])..','..tostring(1000*myPrediction[1] 
[3])..','..tostring(1000*myPrediction[1][4])..'\n')

输入是大小为(1,350)的张量

虽然我已经检查了模型是否正确加载,但我遇到了分割错误

0 个答案:

没有答案