Issue resolved. Updated code is here:

  
      
      GitHub
  
  
    

QuantScientist/PngTorch 4

An integration of the libpng /png++ libraries with the Libtorch C++ Deep Learning Library.  - QuantScientist/PngTorch