How do I use the Tensorboard callback of Keras?

前端 未结 10 622
名媛妹妹
名媛妹妹 2020-12-04 04:57

I have built a neural network with Keras. I would visualize its data by Tensorboard, therefore I have utilized:

keras.         


        
10条回答
  •  悲&欢浪女
    2020-12-04 05:35

    Here is some code:

    K.set_learning_phase(1)
    K.set_image_data_format('channels_last')
    
    tb_callback = keras.callbacks.TensorBoard(
        log_dir=log_path,
        histogram_freq=2,
        write_graph=True
    )
    tb_callback.set_model(model)
    callbacks = []
    callbacks.append(tb_callback)
    
    # Train net:
    history = model.fit(
        [x_train],
        [y_train, y_train_c],
        batch_size=int(hype_space['batch_size']),
        epochs=EPOCHS,
        shuffle=True,
        verbose=1,
        callbacks=callbacks,
        validation_data=([x_test], [y_test, y_test_coarse])
    ).history
    
    # Test net:
    K.set_learning_phase(0)
    score = model.evaluate([x_test], [y_test, y_test_coarse], verbose=0)
    

    Basically, histogram_freq=2 is the most important parameter to tune when calling this callback: it sets an interval of epochs to call the callback, with the goal of generating fewer files on disks.

    So here is an example visualization of the evolution of values for the last convolution throughout training once seen in TensorBoard, under the "histograms" tab (and I found the "distributions" tab to contain very similar charts, but flipped on the side):

    tensorboard weights monitoring

    In case you would like to see a full example in context, you can refer to this open-source project: https://github.com/Vooban/Hyperopt-Keras-CNN-CIFAR-100

提交回复
热议问题