2
votes

I'm using keras with tensorflow 1.9 backend and I have made my custom loss function. I got confused how to plot my custom loss function into tensorboard. I have tried several examples but none of them plot into tensorboard.

Here I add the example of my custom loss function code. What I want here is to plot this loss_1, loss_2, and loss_total in tensorboard. Does anyone know how to do it?

Thank you

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()

1
Welcome to SO. Its a good question. But it can be a better question if you can add what you have tried so far. - Ashwin Geet D'Sa
Well, first I tried to put my custom loss into keras .fit but it gave me error, second I tried to make a Class that define my custom loss and put into .fit, but still tensorboard won't plot it - user12488189
Could you please post the code as part of question. - Ashwin Geet D'Sa
check my updates - user12488189

1 Answers

0
votes

Good afternoon! Perhaps such an implementation can solve the problem:

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
                )

in another terminal run

tensorboard --logdir=YOUR_LOG_FOLDER