jcjohnson / neural-style

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

Wrong JPEG library version #132

Open cloudsere opened 8 years ago

cloudsere commented 8 years ago

Hello! I'm running on mac OS X El Capitan 10.11.2

I tried to install neural-stype following the instructions here But when I try to run th neural_style.lua -gpu -1 -print_iter -1, I got these errors:

[libprotobuf WARNING google/protobuf/io/coded_stream.cc:569] Reading dangerously large protocol message. If the message turns out to be larger than 1073741824 bytes, parsing will be halted for security reasons. To increase the limit (or to disable these warnings), see CodedInputStream::SetTotalBytesLimit() in google/protobuf/io/coded_stream.h. [libprotobuf WARNING google/protobuf/io/coded_stream.cc:81] The total number of bytes read was 574671192 Successfully loaded models/VGG_ILSVRC_19_layers.caffemodel conv1_1: 64 3 3 3 conv1_2: 64 64 3 3 conv2_1: 128 64 3 3 conv2_2: 128 128 3 3 conv3_1: 256 128 3 3 conv3_2: 256 256 3 3 conv3_3: 256 256 3 3 conv3_4: 256 256 3 3 conv4_1: 512 256 3 3 conv4_2: 512 512 3 3 conv4_3: 512 512 3 3 conv4_4: 512 512 3 3 conv5_1: 512 512 3 3 conv5_2: 512 512 3 3 conv5_3: 512 512 3 3 conv5_4: 512 512 3 3 fc6: 1 1 25088 4096 fc7: 1 1 4096 4096 fc8: 1 1 4096 1000 /Users/lesley/torch/install/bin/luajit: /Users/lesley/torch/install/share/lua/5.1/image/init.lua:219: Wrong JPEG library version: library is 90, caller expects 62 stack traceback: [C]: in function 'load' /Users/lesley/torch/install/share/lua/5.1/image/init.lua:219: in function 'loader' /Users/lesley/torch/install/share/lua/5.1/image/init.lua:367: in function 'load' neural_style.lua:82: in function 'main' neural_style.lua:500: in main chunk [C]: in function 'dofile' ...gqiu/torch/install/lib/luarocks/rocks/trepl/scm-1/bin/th:145: in main chunk [C]: at 0x010f8c0bc0

I have spent much time on this issue, I uninstalled torch and loadcaffe , then installed them again for twice, but I still get this error, I really need some help :(

jcjohnson commented 8 years ago

I've never seen that one before. I don't think it's a problem with loadcaffe; maybe try reinstalling the image package?

cloudsere commented 8 years ago

@jcjohnson Thanks for the advice, I'll try it and report the result.

cloudsere commented 8 years ago

Hi, I tried to reinstall the image package,but still have this error.

I ran the error through google and found someone else met the same error, according to some of the solutions, this may caused by having two versions of libjpeg. So I tried to delete libjpeg 9 , and run th neural_style.lua -gpu -1 -print_iter -1 .Then I run into a different error:

conv1_1: 64 3 3 3 conv1_2: 64 64 3 3 conv2_1: 128 64 3 3 conv2_2: 128 128 3 3 conv3_1: 256 128 3 3 conv3_2: 256 256 3 3 conv3_3: 256 256 3 3 conv3_4: 256 256 3 3 conv4_1: 512 256 3 3 conv4_2: 512 512 3 3 conv4_3: 512 512 3 3 conv4_4: 512 512 3 3 conv5_1: 512 512 3 3 conv5_2: 512 512 3 3 conv5_3: 512 512 3 3 conv5_4: 512 512 3 3 fc6: 1 1 25088 4096 fc7: 1 1 4096 4096 fc8: 1 1 4096 1000 /Users/lesley/torch/install/share/lua/5.1/trepl/init.lua:384: ...eqingqiu/torch/install/share/lua/5.1/luarocks/loader.lua:117: error loading module 'libjpeg' from file '/Users/lesley/torch/install/lib/lua/5.1/libjpeg.so': dlopen(/Users/lesley/torch/install/lib/lua/5.1/libjpeg.so, 6): Library not loaded: libjpeg.8.dylib Referenced from: /Users/lesley/torch/install/lib/lua/5.1/libjpeg.so Reason: image not found
warning: could not be loaded (is it installed?)
/Users/lesley/torch/install/bin/luajit: /Users/lesley/torch/install/share/lua/5.1/dok/inline.lua:738: libjpeg package not found, please install libjpeg stack traceback: [C]: in function 'error' /Users/lesley/torch/install/share/lua/5.1/dok/inline.lua:738: in function 'error' /Users/lesley/torch/install/share/lua/5.1/image/init.lua:216: in function 'loader' /Users/lesley/torch/install/share/lua/5.1/image/init.lua:367: in function 'load' neural_style.lua:82: in function 'main' neural_style.lua:500: in main chunk [C]: in function 'dofile' ...gqiu/torch/install/lib/luarocks/rocks/trepl/scm-1/bin/th:145: in main chunk [C]: at 0x0104358bc0

I did install libjpeg 6 , but it seems that it cannot be loaded. If I install libjpeg 8, I will have another 'wrong JPEG library version' said:

library is 80, caller expects 62

At the end I still cannot solve this problem, so I tried to install neural-style on my mac mini , it worked well, but relatively slow , because I cannot use gpu on my mac mini . Anyway, thanks for your great work! @jcjohnson

phaseIV commented 8 years ago

I had the same issue (OSX 10.9) and found the solution here: https://github.com/torch/image/issues/16 Check the answer by JohnZed

mushoo commented 8 years ago

I'm still having this issue, and tried everything I could think of. I pulled any copies of libjpeg floating around and dumped 'em, I've reinstalled luarocks image, brew jpeg, relinked brew jpeg, reinstalled torch... Still always get the error: /Users/mushoo/torch/install/share/lua/5.1/image/init.lua:219: Wrong JPEG library version: library is 80, caller expects 62

Not sure where or why it's looking for version 62, and not really sure how I would go about force-installing 62 over 80. Any ideas?

Oh, almost forgot. OSX El Capitan 10.11.3.

randomrandom commented 8 years ago

what fixed it for me was:

  1. uninstall torch
  2. sudo apt-get install libjpeg-dev libpng12-dev I'm running Ubuntu 14.04, you might have to find the appropriate "lib" packages for your OS
leocck commented 8 years ago

I tried many things, including to remove all duplicated libjpeg.dylib files in my computer, but couldn't make it work. In the end, I tried to use only PNG's instead, and it works

monik3r commented 8 years ago

Try using libjpeg dev instead of libjpeg, it should be a bit more compatible(pretty much what randomrandom said)

morienor commented 8 years ago

Have anyone solved this? I am getting the following error

Wrong JPEG library version: library is 80, caller expects 90

I have tried to install version nine using instructions here: http://mac-dev-env.patrickbougie.com/libjpeg/

but I am still getting the same error. It also doesn't work with PNG images

UPD: I manage to solve this by replacing libjpeg.dylib files in usr/local/lib with the more recent version I guess changing path should work as well, but I have no idea which variable to change

romkri commented 8 years ago

I got same error, nothing helps, waiting for advice please.

tanvach commented 8 years ago

I found a solution by manually install the right libjpeg binary version. In my case I got this error:

Wrong JPEG library version: library is 80, caller expects 62

So I found an old libjpeg v62 binary from searching the internet: https://gitlab.com/xonotic/xonotic/raw/e81fb5aafb41d70897cafab7dcd5ceae17d13160/misc/buildfiles/osx/Xonotic.app/Contents/MacOS/libjpeg.62.dylib

Then you can copy to appropriate directory using:

cp ~/Downloads/libjpeg.62.dylib /usr/local/lib/

Now neural_style.lua runs fine :)

romkri commented 8 years ago

Thanks a lot tanvach, but now I got another error:

> th -limage -e "image.lena()"

~/torch/install/share/lua/5.1/image/init.lua:220: JPEG parameter struct mismatch: library thinks size is 632, caller expects 600

tanvach commented 8 years ago

Hey romkrl, what is the exact error you are getting?

romkri commented 8 years ago

> th -limage -e "image.lena()" .../torch/install/share/lua/5.1/image/init.lua:220: Wrong JPEG library version: library is 80, caller expects 62

that was before using old dlyb that you suggest me.

Thanks a lot for your help @tanvach!

And after I do:

`

rm /usr/local/lib/libjpeg.dylib rm /usr/local/lib/libjpeg.a rm /usr/local/lib/libjpeg.8.dylib cp ~/Downloads/libjpeg.62.dylib /usr/local/lib/libjpeg.62.dylib cp ~/Downloads/libjpeg.62.dylib /usr/local/lib/libjpeg.dylib luarocks install image `

And I got this error: `

th -limage -e "image.lena()" ...rs/romkri/torch/install/share/lua/5.1/image/init.lua:220: JPEG parameter struct mismatch: library thinks size is 632, caller expects 600 `

samyk commented 8 years ago

Hi all! I'm also getting this same error (on OS X 10.10.5)

For example:

$ th -limage -e "image.lena()"
/usr/local/torch/install/share/lua/5.1/image/init.lua:220: Wrong JPEG library version: library is 90, caller expects 62 

I then tried to specify the version of libjpeg to use by doing:

$ mkdir samy-libs
$ ln -s /usr/local/lib/libjpeg.62.dylib samy-libs/
$ ln -s /usr/local/lib/libjpeg.62.dylib samy-libs/libjpeg.dylib
$ export CMAKE_LIBRARY_PATH=`pwd`/samy-libs
$ luarocks install image
$ th -limage -e "image.lena()"
/usr/local/torch/install/share/lua/5.1/image/init.lua:220: JPEG parameter struct mismatch: library thinks size is 632, caller expects 600

I've also downloaded jpeg-6b, compiled from source, and pointed both lib and include to the directory with the same issue:

$ export CMAKE_LIBRARY_PATH=/tmp/jpeg-6b CMAKE_INCLUDE_PATH=/tmp/jpeg-6b
$ luarocks install image
$ th -limage -e "image.lena()"
/usr/local/torch/install/share/lua/5.1/image/init.lua:220: JPEG parameter struct mismatch: library thinks size is 632, caller expects 600

Any suggestions? I tried tanvach's suggestion (which is the same library that I have, verified via md5) and getting the same issue.

samyk commented 8 years ago

I was able to solve this, though with a big hack. Running:

git clone https://github.com/torch/image
mkdir image/build
cd image/build
cmake .. && make
grep * -re jpeglib

The grep spit out:

CMakeFiles/jpeg.dir/C.includecache:/Library/Frameworks/SpeakerPhonePublicSupport.framework/Headers/jpeglib.h

Since I don't use that framework (SpeakerPhone) for anything anymore, I backed it up and copied all the jpeg-6b .h files into it (after downloading jpeg-6b from sourceforge):

cp /tmp/jpeg-6b/*.h /Library/Frameworks/SpeakerPhonePublicSupport.framework/Headers/
luarocks install image

And now

$ th -limage -e "image.lena()" && echo yay
yay
mkmohangb commented 7 years ago

I recently faced this problem with MacOS Sierra (10.12) because brew still has libjpeg version 80. The following procedure worked for me.

  1. Uninstall image (luarocks remove image)
  2. Remove libjpeg version 80(brew unlink libjpeg) and install libjpeg version 90 by following the procedure from here: http://mac-dev-env.patrickbougie.com/libjpeg/ (link mentioned previously by morienor)
  3. Install image (luarocks install image)

The key is to uninstall image and then install it after the libjpeg update so that it links against the newer version of libjpeg.

noamlerner commented 6 years ago

Figured out a hacky fix: when i ran luarocks install image it outputted -- Found JPEG: /usr/local/lib/libjpeg.dylib so i installed the correct version in that location.

tailsu commented 6 years ago

Frameworks with headers cause CMake to produce an incorrect build.

CMake has this funny parameter called CMAKE_FIND_FRAMEWORK which is set by default to FIRST. This means that CMake will first look for files first in all framework directories, and only then in regular include directories. Funnily enough frameworks (in my case it was Mono) may contain the headers for libjpeg and libpng. So, CMake finds the headers in Mono, but the library in the regular install location, e.g. /usr/local/lib and therefore a version mismatch happens.

Mono is a known menace (for some time brew doctor warned if Mono is installed that builds may fail). You can see this behavior if you create a CMakeLists.txt file with the single line find_package(JPEG), run cmake . and take a look at the paths in the generated CMakeCache.txt file.

The fix that definitively worked for me was to check out the project manually, add set(CMAKE_FIND_FRAMEWORK LAST) to CMakeLists.txt before the find_package calls and then run luarocks make. This way CMake found the headers in the right folder.

NightMachinery commented 6 years ago

@noamlerner How did you install the correct version there?

noamlerner commented 6 years ago

@NightMachinary I had the right version on my computer somewhere, I just copied (cp) it

vvzen commented 6 years ago

Ok I after trying without luck for more than a few hours, this is what worked for me, macOS Sierra 10.12.6. I was having the Wrong JPEG library version: library is 90, caller expects 62 error.

  1. I downloaded the version 62 of the library as showed by @tanvach (huge thanks for the link) !
  2. ls /usr/local/lib/libjpeg.*.dylib to show all of my libjpeg libraries, then moved them to a backup place, and removed the /usr/local/lib/libjpeg.dylib symlink .
  3. ln -s ~/YOUR/PATH/libjpeg.62.dylib /usr/local/lib/libjpeg.dylib to create a symlink to version 62
  4. luarocks remove image --force
  5. luarocks install image

To test if it works: th -limage -e "image.lena()" && echo "ok" just prints ok!

Huge thanks to everybody that posted here! 🥇