简体   繁体   English

如何使用 TensorBoard write_grads 函数?

[英]How to use TensorBoard write_grads function?

i am using keras to train my sequential model with 3 layers and want to visualize gradient histograms in TensorBoard.我正在使用 keras 来训练我的 3 层序列模型,并希望在 TensorBoard 中可视化梯度直方图。 For that there is the function "write_grads" in keras.callbacks.Tensorboard which should work if you define histogram_freq greater than 0 ( keras docu ).为此,keras.callbacks.Tensorboard 中有函数“write_grads”,如果您定义 histogram_freq 大于 0( keras docu ),它应该可以工作。 What i did:我做了什么:

### tensorboard call
callback_tb = keras.callbacks.TensorBoard(log_dir="logs/"+ name, write_graph = True, write_grads = True, histogram_freq=10 )
### some other callbacks
reduce_lr = keras.callbacks.ReduceLROnPlateau(monitor='val_loss', factor=0.2, patience=10, min_lr=0.001, verbose = 1)
early = keras.callbacks.EarlyStopping(monitor='val_loss', min_delta=5, patience=10, verbose=1, mode='auto')
checkpointer = keras.callbacks.ModelCheckpoint(filepath='tmp/'+name+'.hdf5', verbose=1, save_best_only=True)

### model fit
model.fit(
        X_train, y_train,
        batch_size=1, nb_epoch=epochs, validation_split=0.05, verbose = 1,class_weight ={0: 1, 1: 0.5}, callbacks = [callback_tb, reduce_lr, early, checkpointer])

I have this model configuartion:我有这个模型配置:

model = Sequential()
layers = [1, 100, 100, 100, 1]

model.add(GRU(
        layers[1],
        #batch_size = 209,
        input_shape=(sequence_length, anzahl_features),
        return_sequences=True))
model.add(Dropout(dropout_1))
model.add(LSTM(
        layers[2],
        #batch_size = 209,
        return_sequences=True))
model.add(Dropout(dropout_2))
model.add(GRU(
        layers[3],
        #batch_size = 209,
        return_sequences=False))
model.add(Dropout(dropout_3))
model.add(Dense(
         layers[4]))
model.add(Activation('sigmoid'))

print(model.summary())

And the error message that i get is the following one:我得到的错误消息如下:

TypeError: init () got an unexpected keyword argument 'write_grads' TypeError: init () 得到了一个意外的关键字参数 'write_grads'

Is there something wrong with my configuartion?我的配置有问题吗? Can i use this model and get the gradient histograms?我可以使用这个模型并获得梯度直方图吗? Or are those histograms just available for a certain type of model?或者那些直方图仅适用于某种类型的模型?

You need to upgrade Keras to the latest release (2.0.5).您需要将 Keras 升级到最新版本 (2.0.5)。 Previous versions do not support the write_grads argument.以前的版本不支持 write_grads 参数。

pip install keras --upgrade pip 安装 keras --upgrade

write_grads seems to be depecrated. write_grads似乎已被弃用。 Here it is not among the parameters fo the callbacks, and on githubs there is a request to un-deprecate it.这里它不在回调的参数中,并且在 githubs 上有一个取消弃用它的请求。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM