There are no operators in the program to be executed 可能的原因

2022-08-03,,,

出现场合:

使用paddlepaddle框架,运行以下代码:

import paddle.fluid as fluid
import numpy as np

# Creates a variable with fixed size [3, 2, 1]
# User can only feed data of the same shape to x
x = fluid.data(name='x', shape=[3, 2, 1], dtype='float32')

# Creates a variable with changable batch size -1.
# Users can feed data of any batch size into y,
# but size of each data sample has to be [2, 1]
y = fluid.data(name='y', shape=[-1, 2, 1], dtype='float32')

z = x+1

# In this example, we will feed x and y with np-ndarry "1"
# and fetch z, like implementing "1 + 1 = 2" in PaddlePaddle
feed_data = np.ones(shape=[3, 2, 1], dtype=np.float32)

exe = fluid.Executor(fluid.CPUPlace())
exe.run(fluid.default_startup_program())
out = exe.run(fluid.default_main_program(),
              feed={
                  'x': feed_data,
                  'y': feed_data
              },
              fetch_list=[z.name])

# np-ndarray of shape=[3, 2, 1], dtype=float32, whose elements are 2
print(out)

出现如下警告:

UserWarning: There are no operators in the program to be executed. If you pass Program manually, please use fluid.program_guard to ensure the current Program is being used.

解决方案:

去掉

exe.run(fluid.default_startup_program())

提示就没有了。

原因分析:

没有需要进行的初始化操作,所以不运行初始化程序就没有此警告。

本文地址:https://blog.csdn.net/yzlh2009/article/details/107325915

《There are no operators in the program to be executed 可能的原因.doc》

下载本文的Word格式文档,以方便收藏与打印。