求助大家帮我看看下面代码报错DeviceContextPool的原因

头像中二柚 · 提问于2021.08.05浏览量:615

我在paddle改写波士顿房价预测代码运行时报错,如下:

`class Regressor(fluid.dygraph.Layer):
def init(self):
super(Regressor, self).init()

 
 
 
  1. # 定义一层全连接层,输出维度是1,激活函数为None,即不使用激活函数
  2. self.fc = Linear(input_dim=13, output_dim=1, act=None)
  3. # 网络的前向计算函数
  4. def forward(self, inputs):
  5. x = self.fc(inputs)
  6. return x

定义飞桨动态图的工作环境

with fluid.dygraph.guard():

 
 
 
  1. # 声明定义好的线性回归模型
  2. model = Regressor()
  3. # 开启模型训练模式
  4. model.train()
  5. # 加载数据
  6. training_data, test_data = load_data()
  7. # 定义优化算法,这里使用随机梯度下降-SGD
  8. # 学习率设置为0.01
  9. opt = fluid.optimizer.SGD(learning_rate=0.01, parameter_list=model.parameters())

Error: Need to Create DeviceContextPool first!
[Hint: pool should not be null.] at (/paddle/paddle/fluid/platform/device_context.h:336)`

全部回答 · 1
最新最热
  • 用户头像
    澜川若宁2021.08.05 11:00

    重启一下,再次执行就好啦,因为在计算过程中与服务器失去连接,某些中间变量出错了。