Skip to content

Commit

Permalink
handle single channel images in tensor_to_img
Browse files Browse the repository at this point in the history
  • Loading branch information
alik-git committed Nov 24, 2023
1 parent 6123386 commit 9bf8d0d
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lucent/optvis/render.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,10 @@ def closure():
def tensor_to_img_array(tensor):
image = tensor.cpu().detach().numpy()
image = np.transpose(image, [0, 2, 3, 1])
# Check if the image is single channel and convert to 3-channel
if len(image.shape) == 4 and image.shape[3] == 1: # Single channel image
image = np.repeat(image, 3, axis=3)
image = (image * 255).astype(np.uint8)
return image


Expand Down

0 comments on commit 9bf8d0d

Please sign in to comment.