Skip to content

Preprocessing of the target image #16

Answered by francois-rozet
ruguevara asked this question in Q&A
Discussion options

You must be logged in to vote

Hello @ruguevara,

Comparing sequentially several images with a single target is indeed wasteful.

z = []
for i in range(len(x)):
    z.append(metric(x[i], y))

In PyTorch (and NumPy) there is something called broadcasting. For most operations (+, *, /, ...), if a tensor has a shape (..., N, ...) and the other (..., 1, ...), the backend will cast the shape of the latter to the shape of the former while performing the operation.

As a result, if the metric is parallelized (meaning that it does not split the batch dimension during the processing), it should accept a batch x of input images of shape (N, C, ...) and a batch y of target images of shape (1, C, ...) and still perform the comparison …

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by francois-rozet
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants