I am using Colab, Torch, in GPU env. But when i start to merge images that are produced by Cycle-Gan, error occurs.
TypeError: can’t convert CUDA tensor to numpy. Use Tensor.cpu() to copy the tensor to host memory first.
So i tried to solve problem by use .cpu…
but i don’t know where to use it. because i don’t know what is the exact problem.
def merge_images(self, sources, targets, k=10):
    _, _, h, w = sources.shape
    row = int(np.sqrt(self.batch_size))
    merged = np.zeros([3, row * h, row * w * 2])
    for idx, (s, t) in enumerate(zip(sources, targets)):
        i = idx // row
        j = idx % row
        merged[:, i * h:(i + 1) * h, (j * 2) * h:(j * 2 + 1) * h] = s
        merged[:, i * h:(i + 1) * h, (j * 2 + 1) * h:(j * 2 + 2) * h] = t
    return merged.transpose(1, 2, 0)

I want to know why this kind of problem occurs and how to solve this.
(sorry to write raw)