How do I access to the logs generated from training a model with tensorboard?

104 Views Asked by At

now That we cannot upload the logs to tensorboard dev I cannot transform the information from the logs to DataFrame as easily as before. So I wante to ask if anyone knows how to extract the data stored in the train and test logs programatically, that is, without using:

tensorboard --logdir=path_to_logs

in the console command.

I cannot do anything if first I cannot understand how I can unpack the data stores in the logs.

2

There are 2 best solutions below

1
hcharles25 On

You can use EventFileReader in TensorFlow to read event files, created by TensorFlow for TensorBoard logs. Here is a script I used before, printing information about each event in the TensorBoard logs, including the step, wall time and value.

from tensorflow.python.summary import event_file_reader

def read_tensorboard_logs(logdir):
    event_reader = event_file_reader.EventFileReader(logdir)
    tags = event_reader.GetTags()

    for tag in tags:
        print(f"Tag: {tag}")
        events = event_reader.TaggedEvents(tag)

        for event in events:
            wall_time = event.wall_time
            step = event.step
            value = event.summary.value[0].simple_value  
            print(f"Step: {step}, Wall Time: {wall_time}, Value: {value}")

log_directory = "/logs"
read_tensorboard_logs(log_directory)

1
Alejandro Riol Triviño On

I have asked chatGPT and after solving a few mistakes commited by the AI now I have a code that returns me some values:

import numpy as np
from tensorboard.backend.event_processing import event_accumulator

# Path to the directory containing your TensorBoard logs
route_log="logs"
log_dir_train = f"{route_log}/train"
# Create an EventAccumulator
event_acc = event_accumulator.EventAccumulator(log_dir_train)

# Reload the data from the logs
event_acc.Reload()


# obtain all tags from tensors
all_tensors=event_acc.Tags()['tensors']
print(all_tensors)

# Print the data
for tag in all_tensors:
    #I only write the loss
    if tag == "epoch_loss":
        loss_data = event_acc.Tensors(tag)
        for event in loss_data:
            tensor_data = event.tensor_proto
            tensor_content = np.frombuffer(tensor_data.tensor_content, dtype=np.float32)
            print(f"Tag: {tag}, Step: {event.step}, Tensor_Data:{tensor_content[0]}")