Skip to content

Conversation

ProGamerGov
Copy link
Contributor

@ProGamerGov ProGamerGov commented Jan 10, 2022

  • Added color space support to save_tensor_as_image & ImageTensor.export.
  • Added image grid creation support to ImageTensor.export , ImageTensor.show , show & save_tensor_as_image via a new make_grid_image function. This makes it easier for users to view multiple images stacked across the batch dimension without having to scroll horizontally.
  • Added user agent to ImageTensor.open as sites like Wikipedia require user agents.

* Added color space support to `save_tensor_as_image` & `ImageTensor.export`.
* Added image grid creation support to `ImageTensor.export` , `ImageTensor.show` , `show` & `save_tensor_as_image` via a new `make_grid_image` function.
* Added user agent to `ImageTensor.open` as sites like Wikipedia require user agents.
]
]
)
self.assertEqual(list(expected_output.shape), [1, 1, 7, 10])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The transformation doesn't seem very clear. Do you mind adding more details how 6 x 1 x 2 x 2 transforms into 1 x 1 x 7 x 10 ? nrow argument looks a bit unclear to me.

Copy link
Contributor Author

@ProGamerGov ProGamerGov Jan 18, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@NarineK

# Border has a size of 1, and we are using 3 in a row:
total_w = (n_row * border) + border + (n_row * tensor_dim_w)
total_h = (n_column * border) + border + (n_column * tensor_dim_h)

(3 * 1) + 1+ (3 * 2) = 10
(2 * 1) + 1+ (2 * 2) = 7

The n_column value is calculated based on the given nrow value and how tensors in the list / batch dimension there are.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added the above comment to the tests!

@NarineK
Copy link
Contributor

NarineK commented Jan 17, 2022

@ProGamerGov, where is this "make image grid" functionality used now ? Are we using it in activation atlas ?

@ProGamerGov
Copy link
Contributor Author

ProGamerGov commented Jan 18, 2022

@NarineK The functionality is currently used for when visualizations are displayed to the user, and when they wish to save them as images. Previously users would might have to scroll a lot horizontally when viewing multiple visualizations stacked across the batch dimension, or the image displayed would too small to be useful. The activation atlas grids are different as not every cell has a visualization, and the atlas grid is defined based on the dimensionality reduced point graph.

In this PR for displaying images we simply specify how many images per row and if we want any padding.

@ProGamerGov
Copy link
Contributor Author

ProGamerGov commented Jan 18, 2022

@NarineK Currently this is what happens for example if a user uses the show function to display 12 visualizations stacked across the batch dimension:

image().show(figsize=(12, 10))

no_grid_example

With this PR, the same user could specify nrow=4 and create a much better looking display for their visualizations:

image().show(nrow=4, figsize=(12, 10))

with_grid_example

A similar thing happens with image saving, and this PR lets users fix that as well by specifying what they want for nrow.

@NarineK
Copy link
Contributor

NarineK commented Jan 18, 2022

Thank you for the explanation, @ProGamerGov ! In that case it's would be better to call it images_per_row. I originally thought that we are expected to see four rows.

The documentation says:

The number of rows to use for the grid image.
            Default: 4

At this point it looks to me number of columns 4 and rows 3

@ProGamerGov
Copy link
Contributor Author

@NarineK Ah, I see the problem! I've changed nrow to images_per_row and corrected the documentation for the images_per_row argument.

@ProGamerGov ProGamerGov requested a review from NarineK February 15, 2022 01:52
@NarineK NarineK merged commit d272be7 into meta-pytorch:optim-wip May 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants