欢迎来到代码驿站!

Python代码

当前位置:首页 > 软件编程 > Python代码

解决import tensorflow as tf 出错的原因

时间:2021-04-05 10:09:29|栏目:Python代码|点击:

笔者在运行 import tensorflow as tf时出现下面的错误,但在运行import tensorflow时没有出错。

>>> import tensorflow as tf
RuntimeError: module compiled against API version 0xc but this version of numpy is 0xa
ImportError: numpy.core.multiarray failed to import
ImportError: numpy.core.umath failed to import
ImportError: numpy.core.umath failed to import
2018-12-09 01:22:17.925262: F tensorflow/python/lib/core/bfloat16.cc:675] Check failed: PyBfloat16_Type.tp_base != nullp
tr

后运行keras初级教程上的以下代码也报错:

# univariate lstm example
from numpy import array
from keras.models import Sequential
from keras.layers import LSTM
from keras.layers import Dense
# define dataset
X = array([[10, 20, 30], [20, 30, 40], [30, 40, 50], [40, 50, 60]])
y = array([40, 50, 60, 70])
# reshape from [samples, timesteps] into [samples, timesteps, features]
X = X.reshape((X.shape[0], X.shape[1], 1))
# define model
model = Sequential()
model.add(LSTM(50, activation='relu', input_shape=(3, 1)))
model.add(Dense(1))
model.compile(optimizer='adam', loss='mse')
# fit model
model.fit(X, y, epochs=1000, verbose=0)
# demonstrate prediction
x_input = array([50, 60, 70])
x_input = x_input.reshape((1, 3, 1))
yhat = model.predict(x_input, verbose=0)
print(yhat)


经查阅资料后,安装以下网站的pip install tf-nightly

https://pypi.org/project/tf-nightly/

安装完成后运行上面所有代码就OK了,特此分享!

上一篇:最基础的Python的socket编程入门教程

栏    目:Python代码

下一篇:使用PYTHON解析Wireshark的PCAP文件方法

本文标题:解决import tensorflow as tf 出错的原因

本文地址:http://www.codeinn.net/misctech/94806.html

推荐教程

广告投放 | 联系我们 | 版权申明

重要申明:本站所有的文章、图片、评论等,均由网友发表或上传并维护或收集自网络,属个人行为,与本站立场无关。

如果侵犯了您的权利,请与我们联系,我们将在24小时内进行处理、任何非本站因素导致的法律后果,本站均不负任何责任。

联系QQ:914707363 | 邮箱:codeinn#126.com(#换成@)

Copyright © 2020 代码驿站 版权所有