我正在尝试使用Chainer (v4.0.0b1)构建一个包含多个GPU的LSTM网络。如以下代码所示。
import numpy as np
import chainer
from chainer import optimizers, Chain, training, iterators, serializers, cuda, Variable
import chainer.functions as F
import chainer.links as L
...
class Network(Chain):
def __init__(self):
super(Network, self).__init__()
with self.init_scope():
...
self.fc1 = L.Liner(3000, 1000).to_gpu(1)
self.lstm = L.LSTM(1000, 1000).to_gpu(1)
self.fc2 = L.Liner(1000, 3000).to_gpu(1)
...
def __call__(self, x, t):
...
...然而,LSTM链接变成了"NoneType“。如以下调用中的错误所示。
TypeError: 'NoneType' object is not callble我觉得这很奇怪,所以我显示了"self.lstm“。结果,显示了'None‘。例如,“链接”的fc1显示如下。
<chainer.links.connection.linear.Linear object at hogehoge>我发现"self.lstm“不能在"self.lstm = L.LSTM(1000,1000).to_gpu(1)”中声明为链接。但是,我不知道为什么我不能声明它。
我使用Chainer's Docker作为执行环境。
感谢您的回复。
发布于 2018-09-11 14:35:23
这个错误是一袋链接器。它已经修复,正在等待检查。一段时间后,它将被提交。
发布于 2018-09-04 12:05:05
简而言之,使用
class Network(Chain):
def __init__(self):
super(Network, self).__init__()
with self.init_scope():
...
self.fc1 = L.Liner(3000, 1000)
self.lstm = L.LSTM(1000, 1000)
self.fc2 = L.Liner(1000, 3000)
...
def __call__(self, x, t):
...
model = Network()
model.to_gpu()详细信息:
在链接器中,to_gpu()几乎在所有情况下都返回None,因此您不能使用方法链。(唯一的例外是chainer.backends.cuda.to_gpu(),它返回GPU化的数组。)
相反,Link.to_gpu()将其所有属性(变量和链接)发送到GPU,并替换从CPU上的对象到GPU上的对象的引用。
因此,您不必用self.lstm属性替换LSTM.to_gpu()的返回值。
https://stackoverflow.com/questions/52147876
复制相似问题