11. 直方圖cv2.calcHist()、直方圖均衡化cv2.equalizeHist(gray)、cv2.createCLAHE()、直方圖比較cv2.compareHist()
Win 10 解決執行Keras中的plot_model()函式時的報錯,ImportError: 'Failed to import pydot. You must `pip install pydot` and install graphviz (https://graphviz.gitlab.io/download/), ', 'for `pydotprint` to work.'
Keras.__version__ == 2.4.3
plot_model()是將Keras中的神經網路的模型進行視覺化處理的函式。當win 10 中執行時,會出現以下報錯:ImportError: 'Failed to import pydot. You must `pip install pydot` and install graphviz
看了其他許多部落格後,都無法解決。在這些部落格的基礎上,和檢視原始碼後,我總結了以下的解決方法:
START:
STEP 1. 下載並安裝graphviz 2.38。注意:設定安裝路徑為"C:\ProgramFiles\att\Graphviz\bin",並將該路徑新增到系統的Path環境變數中。軟體下載連結為 https://softpedia-secure-download.com/dl/b07f24905c8ad73c39308d61e31f96dc/5fe6c2c9/100124651/software/other_tools/graphviz-2.38.msi
STEP 2. 在cmd命令列中執行pip install pydot_ng,來安裝pydot_ng包。
END.
from keras.models import Model from keras.layers import LSTM, Activation, Input import numpy as np from keras.utils.vis_utils import plot_model data_dim = 1 timesteps = 12 num_classes = 4 inputs = Input(shape=(12,1)) lstm1 = LSTM(32, return_sequences=True)(inputs) lstm2 = LSTM(4 , return_sequences=True)(lstm1) outputs = Activation('softmax')(lstm2) model = Model(inputs=inputs,outputs=outputs) model.compile(loss='categorical_crossentropy', optimizer='rmsprop', metrics=['accuracy']) x_train = np.random.random((1000, timesteps, data_dim)) y_train = np.random.random((1000, timesteps, num_classes)) x_val = np.random.random((100, timesteps, data_dim)) y_val = np.random.random((100, timesteps, num_classes)) model.fit(x_train, y_train, batch_size=64, epochs=5, validation_data=(x_val, y_val)) #模型視覺化 plot_model(model, to_file='model.png') x = np.arange(12).reshape(1,12,1) a = model.predict(x,batch_size=64) print a
Result: