今天使用Tensorflow创建占位符时出现这样一个错误:
RuntimeError: tf.placeholder() is not compatible with eager execution.
在参考了这位博主的文章后得到解决(具体)
出现错误的代码
# 创建占位符
def create_placeholders(n_H0,n_W0,n_C0,n_y):
X=tf.placeholder(tf.float32,[None,n_H0,n_W0,n_C0])
Y=tf.placeholder(tf.float32,[None,n_y])
return X,Y
X , Y = create_placeholders(64,64,3,6)
print ("X = " + str(X))
print ("Y = " + str(Y))
这里需要插入一条语句
tf.compat.v1.disable_eager_execution()
改正后能够成功运行
# 创建占位符
def create_placeholders(n_H0,n_W0,n_C0,n_y):
tf.disable_eager_execution()
X=tf.placeholder(tf.float32,[None,n_H0,n_W0,n_C0])
Y=tf.placeholder(tf.float32,[None,n_y])
return X,Y
X , Y = create_placeholders(64,64,3,6)
print ("X = " + str(X))
print ("Y = " + str(Y))
在使用Tensorflow创建占位符时遇到RuntimeError,提示不兼容eagerexecution。通过调用tf.compat.v1.disable_eager_execution()可以在创建占位符前禁用即时执行模式,从而解决问题。
https://blog.csdn.net/weixin_43763859/article/details/104537392?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522168265106216800213060694%2522%252C%2522scm%2522%253A%252220140713.130102334..%2522%257D&request_id=168265106216800213060694&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~all~top_positive~default-1-104537392-null-null.142^v86^insert_down28,239^v2^insert_chatgpt&utm_term=%20tf.placeholder%28%29%20is%20not%20compatible%20with%20eager%20execution.&spm=1018.2226.3001.4187
694

被折叠的 条评论
为什么被折叠?



