Hello ! Im trying to run my CNN but it fails due to memory shortage. I guess the problem is that i have some variables which consume all the memory but i do not see the mistake. It is to say that i am quite new to working with neural networks and worring about memory ! 
I really appreciate any help.
Here is the code which i guess does the trouble :

Annotation (1)1077×610 37.2 KB

with the following error :
RuntimeError: CUDA out of memory. Tried to allocate 6.60 GiB (GPU 0; 31.75 GiB total capacity; 21.92 GiB already allocated; 1.87 GiB free; 28.56 GiB reserved in total by PyTorch)