Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
GrandArth opened this issue Apr 29, 2024 · 6 comments
Open

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

GrandArth opened this issue Apr 29, 2024 · 6 comments
Labels
a:cli Area: Client c:table Component: Table

Comments

@GrandArth
Copy link

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!

@GrandArth
Copy link
Author

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

@kptkin kptkin added c:table Component: Table a:cli Area: Client labels Apr 29, 2024
@umakrishnaswamy
Copy link
Contributor

hey @GrandArth - what wandb SDK version are you running? looking into reproducing this on my end

@dirtycomputer
Copy link

maybe you need wandb.Image()

@umakrishnaswamy
Copy link
Contributor

umakrishnaswamy commented May 24, 2024

hey @GrandArth - you can add this to add the data row by row:

# Add images to the wandb Table row by row
for lr_img, rc_img, hr_img in zip(lr_images_list, rc_images_list, hr_images_list):
    image_table.add_data(wandb.Image(lr_img), wandb.Image(rc_img), wandb.Image(hr_img))

wandb.log({"Image Comparison": image_table})

and this should log the table. I tested this out on my end and this worked with 0.17.0

@umakrishnaswamy
Copy link
Contributor

Hi @GrandArth, since we have not heard back from you we are going to close this request. If you would like to re-open the conversation, please let us know!

Copy link

WandB Internal User commented:
dirtycomputer commented:
maybe you need wandb.Image()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a:cli Area: Client c:table Component: Table
Projects
None yet
Development

No branches or pull requests

4 participants