1
トーチのnngraphパッケージのグラフモジュール(gModule)に新しいノードを追加するにはどうすればよいですか?私はadd関数を使用しようとしましたが、gModulesオブジェクトのモジュールスロットにノードを追加しました。ただし、出力は前の最後のノードから取得されます。トーチのグラフモジュールにレイヤーを追加する方法
簡体コード:
require "nn"
require "nngraph"
-- Function that builds a gModule
function buildModule(input_size,hidden_size)
local x = nn.Identity()()
local out = x - nn.Linear(input_size,hidden_size) - nn.Tanh()
return nn.gModule({x},{out})
end
network = buildModule(5,3)
-- Additional layer to add
l2 = nn.Linear(3,10)
network:add(l2)
-- Expected a tensor of size 10 but got one with size 3
print(network:forward(torch.randn(5)))
ありがとうございます – nist