Note that it is generally a bad idea to convert a medical image volume to a series 2D slices in jpg/png format. See related discussion in this topic:
If you work with medical images, I would recommend to use tools, frameworks, and tutorials developed specifically for medical imaging (monai, torchio, NVidia Clara, etc).