我想繪製錯誤與keras中的時代數量。爲此,我發現了一個非常有用的帖子here。它在本地就像一個魅力,但如果我想在某些遠程GPU /羣集中運行我的腳本,那麼它就不那麼有用,因爲我需要發送自己的數據以便能夠實際繪製圖形。有沒有辦法運行類似的東西,但將錯誤存儲在某個文件/ csv/json中,然後用rysnc/scp/dropbox等標準工具發送給我自己?如何存儲信息以便能夠在Keras中繪製錯誤和時代?
現在我唯一的想法是醃製該文件,然後將其發送給自己,並取消它,但它根本不起作用。我得到的錯誤:
Traceback (most recent call last):
File "store_data.py", line 71, in <module>
pickle.dump(history, open("history.p", "wb"))
_pickle.PicklingError: Can't pickle <class 'module'>: attribute lookup module on builtins failed
是否有不同的方式使用Keras和python?我只需要能夠存儲這種類型的數據,以便我可以以某種方式將它發送到本地計算機。
目前我完全重複性誤差可以做如下:
store_data.py
# Visualize training history
from keras.models import Sequential
from keras.layers import Dense, Dropout, Activation, Flatten
from keras.datasets import cifar10
from keras.utils import np_utils
import numpy
import pickle
print('start visualization example')
#params
nb_classes = 10
data_augmentation = False
units_single_layer = 10
actication_func = 'relu'
actication_func = 'sigmoid'
nb_epoch = 3
batch_size = 64
#optimizer = 'adam'
optimizer = 'rmsprop'
# input image dimensions
img_rows, img_cols = 32, 32
# The CIFAR10 images are RGB.
img_channels = 3
# The data, shuffled and split between train and test sets:
(X_train, y_train), (X_test, y_test) = cifar10.load_data()
X_train = X_train.reshape((X_train.shape[0],32*32*3))
X_test = X_test.reshape((X_test.shape[0],32*32*3))
print('X_train shape:', X_train.shape)
print(X_train.shape[0], 'train samples')
print(X_test.shape[0], 'test samples')
# Convert class vectors to binary class matrices.
Y_train = np_utils.to_categorical(y_train, nb_classes)
Y_test = np_utils.to_categorical(y_test, nb_classes)
# create model
print('\n ---- Singled Layer Model ----')
print('units_single_layer: ', units_single_layer)
print('actication_func: ', actication_func)
model = Sequential()
model.add(Dense(units_single_layer, input_shape=(32*32*3,)))
model.add(Activation(actication_func))
model.add(Dense(nb_classes))
model.add(Activation('softmax'))
# Compile model
print('\n ---- Optimizer ----')
print('optimizer: ', optimizer)
print('batch_size: ', optimizer)
print('')
model.compile(loss='categorical_crossentropy',
optimizer=optimizer,
metrics=['accuracy'])
# Fit the model
#history = model.fit(X, Y, validation_split=0.33, nb_epoch=150, batch_size=10, verbose=0)
history = model.fit(X_train, Y_train,
batch_size=batch_size,
nb_epoch=nb_epoch,
validation_data=(X_test, Y_test),
shuffle=True)
pickle.dump(history, open("history.p", "wb"))
,並繪製它:
plot.py
# Visualize training history
from keras.models import Sequential
from keras.layers import Dense, Dropout, Activation, Flatten
from keras.datasets import cifar10
from keras.utils import np_utils
import matplotlib.pyplot as plt
import numpy
import pickle
history = pickle.load(open("history.p", "rb"))
# list all data in history
print(history.history.keys())
# summarize history for accuracy
plt.plot(history.history['acc'])
plt.plot(history.history['val_acc'])
plt.title('model accuracy')
plt.ylabel('accuracy')
plt.xlabel('epoch')
plt.legend(['train', 'test'], loc='upper left')
plt.show()
# summarize history for loss
plt.plot(history.history['loss'])
plt.plot(history.history['val_loss'])
plt.title('model loss')
plt.ylabel('loss')
plt.xlabel('epoch')
plt.legend(['train', 'test'], loc='upper left')
plt.show()
另外,如果你有hav與matplot LIB荷蘭國際集團的問題,由於框架構建只使用已經解決了這個問題你與虛擬ENV:
python3 -m venv <my-virtual-env-name>
http://matplotlib.org/faq/osx_framework.html#virtualenv
http://matplotlib.org/faq/osx_framework.html
http://matplotlib.org/faq/virtualenv_faq.html
的-m venv
使用python3的實現的virtualenv,並且該實現使python成爲一個框架。
有我的答案幫助? –