# Conditional GAN concatenation of real image and label

**URL:** <https://discuss.pytorch.org/t/conditional-gan-concatenation-of-real-image-and-label/131552>\
**Category:** vision\
**Created:** [September 9, 2021, 7:06pm UTC](https://discuss.pytorch.org/t/conditional-gan-concatenation-of-real-image-and-label/131552 "2021-09-09T19:06:59Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ArshadIram](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/arshadiram/32/32886_2.png) [@ArshadIram](https://discuss.pytorch.org/u/ArshadIram)\
**Post date:** [September 9, 2021, 7:06pm UTC](https://discuss.pytorch.org/t/conditional-gan-concatenation-of-real-image-and-label/131552/1 "2021-09-09T19:06:59Z")

</div>

I am concatenating real images with labels and the output shape is [128, 11,28, 28]. How can I visualize this image?

```auto
encoded_labels = F.one_hot(reallabels, num_classes)
encoded_labels = encoded_labels [:, :, None, None]
encoded_labels = encoded_labels .repeat(1, 1, mnist_shape[1], mnist_shape[2]) 

```

Here the encoded\_labels size is torch.Size([128, 10, 28, 28])

Now I want to concatenate it with images  
`cat_real_labels = torch.cat((realImages.float(), encoded_labels .float()),1)`  
output: torch.Size([128, 11, 28, 28])

How can I visualize this image?

---

<div class="post-metadata">

**Author:** ![ptrblck](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/ptrblck/32/1823_2.png) [@ptrblck](https://discuss.pytorch.org/u/ptrblck)\
**Post date:** [September 10, 2021, 4:49am UTC](https://discuss.pytorch.org/t/conditional-gan-concatenation-of-real-image-and-label/131552/2 "2021-09-10T04:49:18Z")

</div>

You cannot visualize it directly, as the tensor doesn’t have a valid image shape.  
However, you could visualize the 11 channels separately of all 128 samples (so 1408 grayscale images).

---

<div class="post-metadata">

**Author:** ![ArshadIram](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/arshadiram/32/32886_2.png) [@ArshadIram](https://discuss.pytorch.org/u/ArshadIram)\
**Post date:** [September 10, 2021, 8:10am UTC](https://discuss.pytorch.org/t/conditional-gan-concatenation-of-real-image-and-label/131552/3 "2021-09-10T08:10:52Z")

</div>

Can you just give me a hint of code? How can I visualize it separately for all 128 samples?

---

<div class="post-metadata">

**Author:** ![ptrblck](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/ptrblck/32/1823_2.png) [@ptrblck](https://discuss.pytorch.org/u/ptrblck)\
**Post date:** [September 10, 2021, 8:12am UTC](https://discuss.pytorch.org/t/conditional-gan-concatenation-of-real-image-and-label/131552/4 "2021-09-10T08:12:28Z")

</div>

Something like [this approach](https://discuss.pytorch.org/t/activation-values-in-resnet/128029/19) would work. The difference would be that you would have to flatten the first two dimensions in case you want to visualize all `11*128` grayscale images.
