解決import tensorflow as tf 出錯的原因
阿新 • • 發佈:2020-04-17
筆者在執行 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,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,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了,特此分享!
到此這篇關於解決import tensorflow as tf 出錯的原因的文章就介紹到這了,更多相關import tensorflow as tf 內容請搜尋我們以前的文章或繼續瀏覽下面的相關文章希望大家以後多多支援我們!