jcjohnson / neural-style

Torch implementation of neural style algorithm
MIT License
18.31k stars 2.7k forks source link

png_create_write_struct failed #138

Open gravesee opened 8 years ago

gravesee commented 8 years ago

Everything appears to be working until neural-style tries to write to a png. This is how I'm invoking the process on OS X El Capitan:

th neural_style.lua -style_image ~/Pictures/picaso.jpg -content_image ~/Pictures/inpic.jpg -gpu -1 -num_iterations 1 -output_image ~/Pictures/test.png

There is a warning that my installed version of libpng is ahead of the one the application is using. Could this be a problem linking to the wrong dylib?

These are the libpng libraries I have installed:

$ ls /usr/local/lib/libpng*
/usr/local/lib/libpng.a          /usr/local/lib/libpng16.16.dylib /usr/local/lib/libpng16.dylib
/usr/local/lib/libpng.dylib      /usr/local/lib/libpng16.a

The full output of neural-style when it crashes:

libpng warning: Application built with libpng-1.4.12 but running with 1.5.23
/Users/Zelazny7/torch/install/bin/luajit: /Users/Zelazny7/torch/install/share/lua/5.1/image/init.lua:175: [write_png_file] png_create_write_struct failed
stack traceback:
    [C]: in function 'save'
    /Users/Zelazny7/torch/install/share/lua/5.1/image/init.lua:175: in function 'saver'
    /Users/Zelazny7/torch/install/share/lua/5.1/image/init.lua:386: in function 'save'
    neural_style.lua:307: in function 'maybe_save'
    neural_style.lua:329: in function 'opfunc'
    /Users/Zelazny7/torch/install/share/lua/5.1/optim/lbfgs.lua:66: in function 'lbfgs'
    neural_style.lua:339: in function 'main'
    neural_style.lua:500: in main chunk
    [C]: in function 'dofile'
    ...zny7/torch/install/lib/luarocks/rocks/trepl/scm-1/bin/th:145: in main chunk
    [C]: at 0x0104a99bc0
doomedramen commented 8 years ago

Same issue

libpng warning: Application built with libpng-1.4.12 but running with 1.6.21
/Users/pagem/torch/install/bin/luajit: /Users/pagem/torch/install/share/lua/5.1/image/init.lua:175: [write_png_file] png_create_write_struct failed
stack traceback:
    [C]: in function 'save'
    /Users/pagem/torch/install/share/lua/5.1/image/init.lua:175: in function 'saver'
    /Users/pagem/torch/install/share/lua/5.1/image/init.lua:386: in function 'save'
    neural_style.lua:307: in function 'maybe_save'
    neural_style.lua:329: in function 'opfunc'
    /Users/pagem/torch/install/share/lua/5.1/optim/lbfgs.lua:211: in function 'lbfgs'
    neural_style.lua:339: in function 'main'
    neural_style.lua:500: in main chunk
    [C]: in function 'dofile'
    ...agem/torch/install/lib/luarocks/rocks/trepl/scm-1/bin/th:145: in main chunk
    [C]: at 0x0104759bd0
K4stor commented 8 years ago

+1

maxmurder commented 8 years ago

For me this issue was being caused by outdated libpng libraries which had higher priority than the ones in /usr/local/include and /opt/usr/include. Specifically it was the libpng14 library included with the Mono framework (or at least Unity3d's bastardized version). Removing these and rebuilding the image module resolved the issue.

Steps to Resolve: 1) Find outdated libraries: find /System/Library/Frameworks -name "png*" find /Library/Frameworks/ -name "png*" Look for any old libpng libraries. For me they were in: /Library/Frameworks/Mono.framework/Versions/4.0.2/include/libpng14/

2) Delete or move the conflicting libs: sudo mv /Library/Frameworks/Mono.framework/Versions/4.0.2/include/libpng14/ /Library/Frameworks/Mono.framework/Versions/4.0.2/include/bak-libpng14/

3) Rebuild the image module: luarocks install image

4) Test that the errors are resolved: luajit -limage -e "image.test()" This should return 0 errors.

Now torch/neural-style will be able to output pngs normally! Link to the relevant torch bug

gvdb commented 8 years ago

@maxmurder Thanks for the clear steps to fix and test this. I actually had issues with this on some other work and was never able to figure out it. Had it again with neural-style your post has fixed it in both scenarios. Thank you.

QianchaoLiu commented 8 years ago

I meet the same problem, without using the method given by @maxmurder , I change the -output_image ~/Pictures/test.png to -output_image ~/Pictures/test.jpg, which will avoid the problem brought by conflict of different versions of libpng

anthnyprschka commented 5 years ago

Thanks @maxmurder for the detailed recipe. Yet when I try that i get the following error when trying to install the image package:

-- Build files have been written to: /Users/anthony/ml-dev/torch/pkg/image/build
Scanning dependencies of target lua_png
[ 12%] Building C object CMakeFiles/lua_png.dir/png.c.o
/Users/anthony/ml-dev/torch/pkg/image/png.c:14:10: fatal error: 'png.h' file not found
#include <png.h>
         ^~~~~~~
1 error generated.
make[2]: *** [CMakeFiles/lua_png.dir/png.c.o] Error 1
make[1]: *** [CMakeFiles/lua_png.dir/all] Error 2
make: *** [all] Error 2

Error: Build error: Failed building.

Installing image works fine when I leave Mono.framework the way it is, but then I run into the png_create_write_struct failed error.

Anyone know what could be the fix for this?