wandb / wandb

🔥 A tool for visualizing and tracking your machine learning experiments. This repo contains the CLI and Python API.

Home Page:https://wandb.ai

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Q] Logging Pytorch Images with wandb.Table()

GrandArth opened this issue · comments

I am trying to log images during training process, I followed info on "https://docs.wandb.ai/guides/integrations/pytorch" this page.

My codes looks like this:

image_table = wandb.Table()
    lr_images_list = []
    rc_images_list = []
    hr_images_list = []
    transform_2PIL = tvt.Compose([tvt.ToPILImage(mode='L')])
    for index in range(recon_images.size(0)):
        lr_images_list.append(transform_2PIL(low_res_images[index, :, :, :]))
        rc_images_list.append(transform_2PIL(recon_images[index, :, :, :]))
        hr_images_list.append(transform_2PIL(high_res_images[index, :, :, :]))

    image_table.add_column("Low Res Image", lr_images_list)
    image_table.add_column("Reconstruction Image", rc_images_list)
    image_table.add_column("High resolution Image", hr_images_list)
    image_table.add_column("Index of Batch", step_in_batch)
    image_table.add_column("Global Step", global_step)
    # Log your Table to W&B
    wandb.log({f"Result for {step_in_batch} at {global_step}": image_table})

But as soon as image_table.add_column("Low Res Image", lr_images_list) executes, it outputs:

Traceback (most recent call last):
  File "D:\Program Files\JetBrains\PyCharm 2020.3.5\plugins\python\helpers\pydev\_pydevd_bundle\pydevd_exec2.py", line 3, in Exec
    exec(exp, global_vars, local_vars)
  File "<input>", line 1, in <module>
  File "C:\Users\kousa\.conda\envs\UDPET_GPU\Lib\site-packages\wandb\data_types.py", line 774, in add_column
    assert is_first_col or len(data) == len(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: Expected length 0, found 4

low_res_images is a pytorch tensor, I am trying to turn them back to PIL and then log them in wandb, however, i couldn't get it to run.

I also tried something like:

image_table = wandb.Table(columns=["Low Res Image", "Reconstruction Image","High Resolution Image",
                                   "Index of Batch", "Global Step", "Index in Batch"])
for index in range(recon_images.size(0)):
    image_table.add_data(transform_2PIL(low_res_images[index, :, :, :]),
                         transform_2PIL(recon_images[index, :, :, :]),
                         transform_2PIL(high_res_images[index, :, :, :]),
                         step_in_batch,
                         global_step,
                         index)
wandb.log({f"Result for {step_in_batch} at {global_step}": image_table})

But it gives TypeError: Object of type Image is not JSON serializable.

What went wrong?
Any insight is appreciated!

Note the length of the list is 4, so that is where 4 is coming from