天天看點

python accuracy_人工智能-Keras 基于 Python 的深度學習庫module 'pandas' has no attribute 'computation'

python accuracy_人工智能-Keras 基于 Python 的深度學習庫module 'pandas' has no attribute 'computation'

Keras 是一個用 Python 編寫的進階神經網絡 API,它能夠以CNTK, Theano或TensorFlow 作為後端運作。Keras 的開發重點是支援快速的實驗。能夠以最小的時延把你的想法轉換為實驗結果,是做好研究的關鍵。

指導原則:

使用者友好。 Keras 是為人類而不是為機器設計的 API。它把使用者體驗放在首要和中心位置。Keras 遵循減少認知困難的最佳實踐:它提供一緻且簡單的 API,将常見用例所需的使用者操作數量降至最低,并且在使用者錯誤時提供清晰和可操作的回報。

子產品化。 模型被了解為由獨立的、完全可配置的子產品構成的序列或圖。這些子產品可以以盡可能少的限制組裝在一起。特别是神經網絡層、損失函數、優化器、初始化方法、激活函數、正則化方法,它們都是可以結合起來建構新模型的子產品。

易擴充性。 新的子產品是很容易添加的(作為新的類和函數),現有的子產品已經提供了充足的示例。由于能夠輕松地建立可以提高表現力的新子產品,Keras 更加适合進階研究。

基于 Python 實作。 Keras 沒有特定格式的單獨配置檔案。模型定義在 Python 代碼中,這些代碼緊湊,易于調試,并且易于擴充。

Keras 相容的 Python 版本: Python 2.7-3.6。

安裝日志:

我用的環境是 python 3.5.2,AnaConda 4.5.11,建議一定使用conda安裝,會省很多事。如果你喜歡挑戰,那就用pip試一下。

python accuracy_人工智能-Keras 基于 Python 的深度學習庫module 'pandas' has no attribute 'computation'
python accuracy_人工智能-Keras 基于 Python 的深度學習庫module 'pandas' has no attribute 'computation'

指令:conda install keras ,具體執行效果如下:

python accuracy_人工智能-Keras 基于 Python 的深度學習庫module 'pandas' has no attribute 'computation'
python accuracy_人工智能-Keras 基于 Python 的深度學習庫module 'pandas' has no attribute 'computation'

我後端安裝的是Tensorflow,使用的是K+T的組合。

python accuracy_人工智能-Keras 基于 Python 的深度學習庫module 'pandas' has no attribute 'computation'
python accuracy_人工智能-Keras 基于 Python 的深度學習庫module 'pandas' has no attribute 'computation'

基于該環境做了一例子:

Multilayer Perceptron (MLP) for multi-class softmax classification:

import keras

from keras.models import Sequential

from keras.layers import Dense, Dropout, Activation

from keras.optimizers import SGD

# Generate dummy data

import numpy as np

x_train = np.random.random((1000, 20))

y_train = keras.utils.to_categorical(np.random.randint(10, size=(1000, 1)), num_classes=10)

x_test = np.random.random((100, 20))

y_test = keras.utils.to_categorical(np.random.randint(10, size=(100, 1)), num_classes=10)

model = Sequential()

# Dense(64) is a fully-connected layer with 64 hidden units.

# in the first layer, you must specify the expected input data shape:

# here, 20-dimensional vectors.

model.add(Dense(64, activation='relu', input_dim=20))

model.add(Dropout(0.5))

model.add(Dense(64, activation='relu'))

model.add(Dropout(0.5))

model.add(Dense(10, activation='softmax'))

sgd = SGD(lr=0.01, decay=1e-6, momentum=0.9, nesterov=True)

model.compile(loss='categorical_crossentropy',

optimizer=sgd,

metrics=['accuracy'])

model.fit(x_train, y_train,

epochs=20,

batch_size=128)

score = model.evaluate(x_test, y_test, batch_size=128)

系統會提示了一個錯誤:

Message=softmax() got an unexpected keyword argument 'axis'

針對該問題, 是因為keras和tensorflow的版本比對問題,基本比對表是:

python accuracy_人工智能-Keras 基于 Python 的深度學習庫module 'pandas' has no attribute 'computation'
python accuracy_人工智能-Keras 基于 Python 的深度學習庫module 'pandas' has no attribute 'computation'

我安裝的Tensorflow版本是 1.2.1, keras是最新版本

python accuracy_人工智能-Keras 基于 Python 的深度學習庫module 'pandas' has no attribute 'computation'

重新安裝2.0.6,conda沒找到,然後安裝2.0.8

python accuracy_人工智能-Keras 基于 Python 的深度學習庫module 'pandas' has no attribute 'computation'
python accuracy_人工智能-Keras 基于 Python 的深度學習庫module 'pandas' has no attribute 'computation'
python accuracy_人工智能-Keras 基于 Python 的深度學習庫module 'pandas' has no attribute 'computation'

更新完成後遇到新問題:

module 'pandas' has no attribute 'computation'

更新dask,如下:

python accuracy_人工智能-Keras 基于 Python 的深度學習庫module 'pandas' has no attribute 'computation'
python accuracy_人工智能-Keras 基于 Python 的深度學習庫module 'pandas' has no attribute 'computation'

重新運作上面的例子

Multilayer Perceptron (MLP) for multi-class softmax classification:

結果如下:

python accuracy_人工智能-Keras 基于 Python 的深度學習庫module 'pandas' has no attribute 'computation'
python accuracy_人工智能-Keras 基于 Python 的深度學習庫module 'pandas' has no attribute 'computation'