# How to use RGBA or 4 channel images in a DCGAN model in pytorch

**URL:** <https://discuss.pytorch.org/t/how-to-use-rgba-or-4-channel-images-in-a-dcgan-model-in-pytorch/158252>\
**Category:** Uncategorized\
**Created:** [August 3, 2022, 4:23pm UTC](https://discuss.pytorch.org/t/how-to-use-rgba-or-4-channel-images-in-a-dcgan-model-in-pytorch/158252 "2022-08-03T16:23:30Z")\
**Posts on this page:** 1\
**Showing post:** 5

<div class="post-metadata">

**Author:** ![Faezeh\_Bidjarchian](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/faezeh_bidjarchian/32/64134_2.png) [@Faezeh\_Bidjarchian](https://discuss.pytorch.org/u/Faezeh_Bidjarchian)\
**Post date:** [September 22, 2023, 2:38pm UTC](https://discuss.pytorch.org/t/how-to-use-rgba-or-4-channel-images-in-a-dcgan-model-in-pytorch/158252/5 "2023-09-22T14:38:26Z")

</div>

Hi,  
As you know, we can use only 1 and 3 channels in Keras, etc. But I just realized that  
we can use the desired channels in Pytorch based on this link:

> [@Number of input channels in pytorch](https://discuss.pytorch.org/t/number-of-input-channels-in-pytorch/68171/7):
>
> thanks for your help may you explain more about how can I fuse 16 images to one image? if I shape an array with 16 channels does it work in pyotch as input? does pytorch give image as input or can I input array of numbers in the train and test folders? thanks in advance

“You can write a custom dataset class for reading images and make them **16** channels input.  
Check [link] for writing a custom dataset.”  
But according to what you wrote here, finally “ImageFolder” converts the input to RGB channels?  
def pil\_loader(path: str) → Image.Image:  
with open(path, “rb”) as f:  
img = Image.open(f)  
return img.convert(“ **RGB** ”)  
Is that correct?

---

_[View the full topic](https://discuss.pytorch.org/t/how-to-use-rgba-or-4-channel-images-in-a-dcgan-model-in-pytorch/158252)._
