Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failed to Load Image #174

Closed
sagarwaghmare69 opened this issue Feb 23, 2017 · 18 comments
Closed

Failed to Load Image #174

sagarwaghmare69 opened this issue Feb 23, 2017 · 18 comments

Comments

@sagarwaghmare69
Copy link

Trying to run 'th waifu2x.lua'.
Following is the error log

All packages update to date. Using Lua5.2 instead of luajit.
Also tried with different images as well, same error.

waifu2x.lua:43: failed to load image: images/miku_small.png
stack traceback:
[C]: in function 'error'
waifu2x.lua:43: in function 'convert_image'
waifu2x.lua:291: in function 'waifu2x'
waifu2x.lua:296: in main chunk
[C]: in function 'dofile'
...mare/torch/install/lib/luarocks/rocks/trepl/scm-1/bin/th:150: in main chunk
[C]: in ?

Kind regards

@nagadomi
Copy link
Owner

nagadomi commented Feb 25, 2017

It seems that libpng or graphicsmagick (native or lua wrapper) failed to load a PNG image.
I am not sure why cannot load PNG on your runtime env.

@sagarwaghmare69
Copy link
Author

Thanks for your response. I couldnt resolve it. graphicsmagick and libpng are functional and I am using them. I might revisit this in future. Any plans for using torch image package or graphicsmagick directly instead of file io ?

@nagadomi
Copy link
Owner

nagadomi commented Mar 1, 2017

Try remove this pcall.

local state, ret = pcall(load_image)

-   local state, ret = pcall(load_image)
+  local ret = load_image()
+  local state = true

What a error is occurring?
Can not read binary file correctly with fp = io.open(file, "rb"), fp:read("*a") in Lua5.2?

waifu2x is strongly dependent on graphicsmagick package(I sent a lot of PR to graphicsmagick), and RPC server requires a function that decoding the image from the blob. so I have no plans to change that code.

@nagadomi
Copy link
Owner

nagadomi commented Mar 1, 2017

I fixed io.read option(*a ->*all)
780e22c

@nagadomi
Copy link
Owner

nagadomi commented Mar 2, 2017

Now I reinstalled Torch with lua5.2.

/home/nagadomi/torch/install/bin/lua: unable to convert argument 1 from cdata<double> to cdata<intptr_t>
stack traceback:
	[C]: in function 'tonumber'
	...omi/torch/install/share/lua/5.2/graphicsmagick/Image.lua:631: in function 'colorspace'
	lib/image_loader.lua:86: in function 'load_image'

That error is caused by FFI type mismatch in graphicsmagick.
I will investigate this error and try to fix graphicsmagick.

@nagadomi
Copy link
Owner

nagadomi commented Mar 2, 2017

Fixed some issues on lua 5.2 eb3926b .
and I have sent PR to graphicsmagick to fix the above issue clementfarabet/graphicsmagick#46.

waifu2x.lua, convert_data.lua, train.lua works on lua 5.2 but web.lua does not work on lua 5.2 because turbo only supports luajit 2.

@sagarwaghmare69
Copy link
Author

Nice. @nagadomi thank you. I will try it soon.

@nagadomi
Copy link
Owner

nagadomi commented Mar 2, 2017

PR has merged. After updating graphicsmagick, it probably works.

luarocks install graphicsmagick

@sagarwaghmare69
Copy link
Author

sagarwaghmare69 commented Mar 3, 2017 via email

@houguanqun
Copy link

I think I meet the same question ,could you help me ?

@JCBrouwer
Copy link

I also still run into this problem.

Often times it helps to just run

mogrify filename

But even that doesn't work sometimes.

It's especially weird as it seems to be deterministic which files don't work (running a script multiple times will always see the same files fail) even though in my case all the files were generated by another program in exactly the same way!

does-not-work

does-work

The first image gives:

~/torch/install/bin/luajit: waifu2x.lua:45: failed to load image: /Volumes/HDD/Pictures/image-sets/fluid-painting-pix/A/train/fluidpaint512-13.png
stack traceback:
[C]: in function 'error'
waifu2x.lua:45: in function 'convert_image'
waifu2x.lua:296: in function 'waifu2x'
waifu2x.lua:301: in main chunk
[C]: in function 'dofile'
...hans/torch/install/lib/luarocks/rocks/trepl/scm-1/bin/th:150: in main chunk
[C]: at 0x010daf6a10

While the second upscales just fine (both running with just '-noise_level 3 -tta 1').

@nagadomi
Copy link
Owner

nagadomi commented Apr 24, 2018

Both images worked in my environment. Perhaps it is the difference in graphicsmagick version or libpng version.

% gm -help       
GraphicsMagick 1.3.23 2015-11-07 Q16 http://www.GraphicsMagick.org/
Copyright (C) 2002-2015 GraphicsMagick Group.
Additional copyrights and licenses apply to this software.
See http://www.GraphicsMagick.org/www/Copyright.html for details.
% gm convert -list format | grep PNG
      PNG P  rw-  Portable Network Graphics (libpng 1.2.54, zlib 1.2.8)
            See http://www.libpng.org/ for information on PNG..
    PNG00 P  rw-  PNG that inherits type and depth from original (libpng 1.2.54, zlib 1.2.8)
    PNG24 P  rw-  24-bit RGB PNG, opaque only (libpng 1.2.54, zlib 1.2.8)
    PNG32 P  rw-  32-bit RGBA PNG, semitransparency OK (libpng 1.2.54, zlib 1.2.8)
    PNG48 P  rw-  opaque or binary transparent 48-bit RGB (libpng 1.2.54, zlib 1.2.8)
    PNG64 P  rw-  opaque or transparent 64-bit RGBA (libpng 1.2.54, zlib 1.2.8)
     PNG8 P  rw-  8-bit indexed PNG, binary transparency only (libpng 1.2.54, zlib 1.2.8)

The difference between the two images is that the first image has ICC profile.
You can check the format difference with the following command.

% identify -verbose <image_path>

waifu2x uses GraphicsMagick, not ImageMagick. So you can try gm mogirfy instead of mogrify to fix the image.

@nagadomi
Copy link
Owner

nagadomi commented Apr 24, 2018

Is liblcms2(which is color management system library that is used for reading ICC profile) linked to graphicsmagick?

% gm version|grep cms
  LIBS     = -ljbig -lwebp -llcms2 -ltiff -lfreetype -ljasper -ljpeg -lpng12 -lwmflite -lXext -lSM -lICE -lX11 -llzma -lbz2 -lxml2 -lz -lm -lgomp -lpthread

@JCBrouwer
Copy link

gm -help
GraphicsMagick 1.3.28 2018-01-20 Q16 http://www.GraphicsMagick.org/

gm convert -list format | grep PNG
PNG P rw- Portable Network Graphics (libpng 1.6.34, zlib 1.2.8)
See http://www.libpng.org/ for information on PNG..
PNG00 P rw- PNG that inherits type and depth from original (libpng 1.6.34, zlib 1.2.8)
PNG24 P rw- 24-bit RGB PNG, opaque only (libpng 1.6.34, zlib 1.2.8)
PNG32 P rw- 32-bit RGBA PNG, semitransparency OK (libpng 1.6.34, zlib 1.2.8)
PNG48 P rw- opaque or binary transparent 48-bit RGB (libpng 1.6.34, zlib 1.2.8)
PNG64 P rw- opaque or transparent 64-bit RGBA (libpng 1.6.34, zlib 1.2.8)
PNG8 P rw- 8-bit indexed PNG, binary transparency only (libpng 1.6.34, zlib 1.2.8)

gm version | grep cms
./configure '--prefix=/usr/local/Cellar/graphicsmagick/1.3.28_1' '--disable-dependency-tracking' '--enable-shared' '--disable-static' '--with-modules' '--without-lzma' '--disable-openmp' '--with-quantum-depth=16' '--without-gslib' '--with-gs-font-dir=/usr/local/share/ghostscript/fonts' '--with-webp=no' '--without-x' '--without-lcms2' '--without-wmf' 'CC=clang' 'CXX=clang++'

gm mogrify did not help, still seeing the exact same issue. I'm running macOS Sierra 10.12.6 btw

@nagadomi
Copy link
Owner

nagadomi commented Apr 25, 2018

--without-lcms2

It seems that lcms2 is disabled.
I am not familiar with macOS, but homebrew 's graphicsmagick seems to have an option to enable lcms2.

https://github.com/Homebrew/homebrew-core/blob/53c669cfe80f52527c00bdb491dd8ba27a1460ae/Formula/graphicsmagick.rb#L26

Probably like this

brew install little-cms2
brew install graphicsmagick --with-little-cms2

@JCBrouwer
Copy link

Yes! Reinstalling with little-cms2 did the trick! Thank you so much!

@segalinc
Copy link

segalinc commented Aug 9, 2019

still having the problem... just reinstalled torch for cuda 10.0 using nagadomi instructions, installed all dependencies but still getting failed to load image error. I am on ubuntu 16.04

@nagadomi
Copy link
Owner

When reinstalling torch7, it will need to reinstall lua modules.

sudo apt-get install libsnappy-dev
sudo apt-get install libgraphicsmagick1-dev
sudo apt-get install libssl-dev
./install_lua_modules.sh

If you still get "failed to load image error", try #174 (comment) to see what kind of error you are actually getting in that exception.

local state, ret = pcall(load_image)

--   local state, ret = pcall(load_image)
   local ret = load_image()
   local state = true

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants