Preprocessing of the target image #16
-
In some applications there is a need to repeatedly compare generated images with only one target image, and if all needed independent precalculations on this image could be done beforehand, this could save a lot of gpu/cpu calculation time. How can this be implemented, for example, in subclass of some metrica? Or pytorch can cache this calculations by himself? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
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 ( 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 z = metric(x, y) In this case, the "preprocessing" of the target image is shared among the |
Beta Was this translation helpful? Give feedback.
Hello @ruguevara,
Comparing sequentially several images with a single target is indeed wasteful.
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 batchy
of target images of shape(1, C, ...)
and still perform the comparison …