簡體   English   中英

在 Tensorboard 中繪制 Keras 自定義損失

[英]Plot Keras Custom Loss in Tensorboard

我正在將 keras 與 tensorflow 1.9 后端一起使用,並且我已經制作了我的自定義損失函數。 我對如何將我的自定義損失函數繪制到張量板上感到困惑。 我嘗試了幾個示例,但沒有一個繪制到張量板中。

在這里,我添加了我的自定義損失函數代碼的示例。 我在這里想要的是在張量板中繪制這個 loss_1、loss_2 和 loss_total。 有誰知道怎么做?

謝謝

def loss_1():
   return K.mean(-0.5*var_1)

def loss_2(x, var2):
   return K.mean(0.5*x + var_2)

def loss_total(x, var_z):
   return 0.5 * loss_2(x, var_z) + loss_1()

下午好! 或許這樣的實現可以解決問題:

from keras.callbacks import TensorBoard
#create tensorboard callback
tensorboard = TensorBoard(log_dir=os.path.expanduser('./YOUR_LOG_FOLDER/some_name'), 
                          write_graph=True
                          #another code
                          )

YOUR_MODEL.compile(loss=custom_loss, optimizer=YOUR_OPTIMIZER)

#Specify tensorboard callback
YOUR_MODEL.fit(
                #another code
                callbacks = [tensorboard], 
                #another code
                )

在另一個終端運行中

tensorboard --logdir=YOUR_LOG_FOLDER

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM