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

Torch failed to build (How to install waifu2x in ubuntu 16.04 tutorial for dummies) #222

Closed
RaitaroH opened this Issue Feb 17, 2018 · 12 comments

Comments

Projects
None yet
4 participants
@RaitaroH

RaitaroH commented Feb 17, 2018

EDIT: Please check at the bottom for the tutorial.

So I am running KDE Neon 5.12, and I really want to install this program.

These are the steps I followed:

# Installing cuda
sudo dpkg -i cuda-repo-ubuntu1604-9-1-local_9.1.85-1_amd64.deb
sudo apt-key add /var/cuda-repo-9-1-local/7fa2af80.pub
sudo apt-get update
sudo apt-get install cuda -y
sudo dpkg -i cuda-repo-ubuntu1604-9-1-local-cublas-performance-update-1_1.0-1_amd64.deb

Cuda went pretty nicely. I also went ahead and installed the update too. I have a GeForce GTX 1050 Ti and it does support Cuda. I also made sure everything was there by following the instructions on the cuda page.

Now I tried torch.

git clone https://github.com/torch/distro.git ~/torch --recursive
cd ~/torch
bash install-deps
./install.sh

Yeah so install.sh fails to build. Firstly I am missing many libs:

Checking for [mkl_gf - mkl_intel_thread - mkl_core - pthread - m]
--   Library mkl_gf: not found
-- Checking for [mkl_intel_lp64 - mkl_gnu_thread - mkl_core - pthread - m]
--   Library mkl_intel_lp64: not found
-- Checking for [mkl_intel_lp64 - mkl_intel_thread - mkl_core - pthread - m]
--   Library mkl_intel_lp64: not found
-- Checking for [mkl_intel - mkl_gnu_thread - mkl_core - pthread - m]
--   Library mkl_intel: not found
-- Checking for [mkl_intel - mkl_intel_thread - mkl_core - pthread - m]
--   Library mkl_intel: not found
etc etc etc

But it always fails here:

-- Build files have been written to: /home/raitaro/torch/extra/cutorch/build
[  2%] Building NVCC (Device) object lib/THC/CMakeFiles/THC.dir/THC_generated_THCHalf.cu.o
[  4%] Building NVCC (Device) object lib/THC/CMakeFiles/THC.dir/THC_generated_THCStorage.cu.o
[  4%] Building NVCC (Device) object lib/THC/CMakeFiles/THC.dir/THC_generated_THCSleep.cu.o
[  5%] Building NVCC (Device) object lib/THC/CMakeFiles/THC.dir/THC_generated_THCStorageCopy.cu.o
[  6%] Building NVCC (Device) object lib/THC/CMakeFiles/THC.dir/THC_generated_THCTensor.cu.o
[  7%] Building NVCC (Device) object lib/THC/CMakeFiles/THC.dir/THC_generated_THCBlas.cu.o
[  1%] Building NVCC (Device) object lib/THC/CMakeFiles/THC.dir/THC_generated_THCReduceApplyUtils.cu.o
[  8%] Building NVCC (Device) object lib/THC/CMakeFiles/THC.dir/THC_generated_THCTensorCopy.cu.o
[ 10%] Building NVCC (Device) object lib/THC/CMakeFiles/THC.dir/THC_generated_THCTensorMath.cu.o
[ 11%] Building NVCC (Device) object lib/THC/CMakeFiles/THC.dir/THC_generated_THCTensorMath2.cu.o
[ 12%] Building NVCC (Device) object lib/THC/CMakeFiles/THC.dir/THC_generated_THCTensorMathBlas.cu.o
[ 13%] Building NVCC (Device) object lib/THC/CMakeFiles/THC.dir/THC_generated_THCTensorMathMagma.cu.o
[ 14%] Building NVCC (Device) object lib/THC/CMakeFiles/THC.dir/THC_generated_THCTensorMathPairwise.cu.o
/home/raitaro/torch/extra/cutorch/lib/THC/generic/THCTensorMathPairwise.cu(66): error: more than one operator "!=" matches these operands:
            function "operator!=(const __half &, const __half &)"
            function "operator!=(half, half)"
            operand types are: half != half

/home/raitaro/torch/extra/cutorch/lib/THC/generic/THCTensorMath.cu(393): error: more than one operator "==" matches these operands:
            function "operator==(const __half &, const __half &)"
            function "operator==(half, half)"
            operand types are: half == half

/home/raitaro/torch/extra/cutorch/lib/THC/generic/THCTensorMath.cu(414): error: more than one operator "==" matches these operands:
            function "operator==(const __half &, const __half &)"
            function "operator==(half, half)"
            operand types are: half == half

1 error detected in the compilation of "/tmp/tmpxft_00006e48_00000000-6_THCTensorMathPairwise.cpp1.ii".
CMake Error at THC_generated_THCTensorMathPairwise.cu.o.cmake:267 (message):
  Error generating file
  /home/raitaro/torch/extra/cutorch/build/lib/THC/CMakeFiles/THC.dir//./THC_generated_THCTensorMathPairwise.cu.o


lib/THC/CMakeFiles/THC.dir/build.make:140: recipe for target 'lib/THC/CMakeFiles/THC.dir/THC_generated_THCTensorMathPairwise.cu.o' failed
make[2]: *** [lib/THC/CMakeFiles/THC.dir/THC_generated_THCTensorMathPairwise.cu.o] Error 1
make[2]: *** Waiting for unfinished jobs....
2 errors detected in the compilation of "/tmp/tmpxft_00006e29_00000000-6_THCTensorMath.cpp1.ii".
CMake Error at THC_generated_THCTensorMath.cu.o.cmake:267 (message):
  Error generating file
  /home/raitaro/torch/extra/cutorch/build/lib/THC/CMakeFiles/THC.dir//./THC_generated_THCTensorMath.cu.o


lib/THC/CMakeFiles/THC.dir/build.make:112: recipe for target 'lib/THC/CMakeFiles/THC.dir/THC_generated_THCTensorMath.cu.o' failed
make[2]: *** [lib/THC/CMakeFiles/THC.dir/THC_generated_THCTensorMath.cu.o] Error 1
CMakeFiles/Makefile2:172: recipe for target 'lib/THC/CMakeFiles/THC.dir/all' failed
make[1]: *** [lib/THC/CMakeFiles/THC.dir/all] Error 2
Makefile:127: recipe for target 'all' failed
make: *** [all] Error 2

Error: Build error: Failed building.

I tried to ./clean.sh then I tried again with no luck.

I also tried this:

If you want to install torch with Lua 5.2 instead of LuaJIT, simply run:

git clone https://github.com/torch/distro.git ~/torch --recursive
cd ~/torch
bash install-deps
./install.sh

It doesn't work ;(
Obviously after this point I really don't know what to do honestly. Any suggestions? Can I use waifu2x with only Cuda?

@magiruuvelvet

This comment has been minimized.

Contributor

magiruuvelvet commented Feb 18, 2018

This is not a waifu2x issue. Please report this to the torch developers.

Btw, from my experience w2x doesn't work with CUDA 9. Please downgrade to CUDA 8.0.61.

Regards

EDIT: Also if you want to use cudnn in w2x, the latest version which seems to work (at least for me) is 5.1.10.

@RaitaroH

This comment has been minimized.

RaitaroH commented Feb 18, 2018

@magiruuvelvet Ok, sorry for the post.

@RaitaroH RaitaroH closed this Feb 18, 2018

@nagadomi

This comment has been minimized.

Owner

nagadomi commented Feb 18, 2018

You can solve this error with the following steps.

cd ~/torch
export TORCH_NVCC_FLAGS="-D__CUDA_NO_HALF_OPERATORS__"
./clean.sh
./update.sh

It is a known issue of Torch with CUDA 9.x. torch/cutorch#797

@RaitaroH

This comment has been minimized.

RaitaroH commented Feb 18, 2018

I managed to get it going after a while. I removed everything, including cuda. I installed cuda 8-61. Then I did this:

$ sudo ln -s /usr/bin/gcc-4.9 /usr/local/cuda/bin/gcc
$ sudo ln -s /usr/bin/g++-4.9 /usr/local/cuda/bin/g++
$ sudo ln -s /usr/bin/gcc-4.9 /usr//bin/gcc
$ sudo ln -s /usr/bin/g++-4.9 /usr/bin/g++

Then I did manage to get thorch to install.

I installed the luarocks things, tho as sudo because I couldn't in any other way. Then I used chown -R to give myself ownership of the dir.

cd into waifu2x and trying th waifu2x.lua yields this:

~/waifu2x $ th waifu2x.lua 

images/miku_small_noise_scale.png: 0.25775909423828 sec
/home/raitaro/torch/install/bin/luajit: lib/image_loader.lua:66: IO error: images/miku_small_noise_scale.png
stack traceback:
        [C]: in function 'error'
        lib/image_loader.lua:66: in function 'save_png'
        waifu2x.lua:139: in function 'convert_image'
        waifu2x.lua:291: in function 'waifu2x'
        waifu2x.lua:296: in main chunk
        [C]: in function 'dofile'
        ...taro/torch/install/lib/luarocks/rocks/trepl/scm-1/bin/th:150: in main chunk
        [C]: at 0x00405e90

Also using the command outside the folder gives an error because file was not found. Trying to do something like this also gives me an error:

th ~/waifu2x/waifu2x.lua -m noise_scale -noise_level 2 -i test.png -o test2x.png
/home/raitaro/torch/install/bin/luajit: cannot open <./models/upconv_7/art/noise2_model.t7> in mode r  at /home/raitaro/torch/pkg/torch/lib/TH/THDiskFile.c:673
stack traceback:
        [C]: at 0x7fc86b548450
        [C]: in function 'DiskFile'
        /home/raitaro/torch/install/share/lua/5.1/torch/File.lua:405: in function 'load'
        /home/raitaro/waifu2x/lib/w2nn.lua:23: in function 'load_model'
        /home/raitaro/waifu2x/waifu2x.lua:106: in function 'convert_image'
        /home/raitaro/waifu2x/waifu2x.lua:291: in function 'waifu2x'
        /home/raitaro/waifu2x/waifu2x.lua:296: in main chunk
        [C]: in function 'dofile'
        ...taro/torch/install/lib/luarocks/rocks/trepl/scm-1/bin/th:150: in main chunk
        [C]: at 0x00405e90
@nagadomi

This comment has been minimized.

Owner

nagadomi commented Feb 19, 2018

You do not need to downgrade CUDA. By the above steps, it can be worked with CUDA 9.1.

If you want to run waifu2x outside the folder, specify the -model_dir option.
See #175

@RaitaroH

This comment has been minimized.

RaitaroH commented Feb 19, 2018

@nagadomi Ah, I see. Thank you. Now it actually works, thank you for the patience.

@RaitaroH

This comment has been minimized.

RaitaroH commented Feb 19, 2018

How to install waifu2x in ubuntu 16.04 - for dummies:

  1. Install CUDA (I went with 8.0.61.
  • verify everything here
  • install CUDA from here. Later versions may work, I will not bother right now with version 9.
sudo dpkg -i cuda-repo-ubuntu1604-8-0-local-ga2_8.0.61-1_amd64.deb
sudo apt-get update
sudo apt-get install cuda-8-0
  1. Go ahead and install torch7. As follows:
git clone https://github.com/torch/distro.git ~/torch --recursive
cd ~/torch; bash install-deps;

+You will have problems with gcc, fix found here. So do this

sudo ln -fs /usr/bin/gcc-4.9 /usr/local/cuda/bin/gcc
sudo ln -fs /usr/bin/g++-4.9 /usr/local/cuda/bin/g++
sudo ln -fs /usr/bin/gcc-4.9 /usr//bin/gcc
sudo ln -fs /usr/bin/g++-4.9 /usr/bin/g++
  • Now you can continue with installing the script:
    ./install.sh

  • Everything is ok if you get at the end something to add to your path. Something like this:
    . /home/raitaro/torch/install/bin/torch-activate

  • Now you can install the luarocks stuff you need.

luarocks install graphicsmagick # upgrade
luarocks install lua-csnappy
luarocks install md5
luarocks install uuid
luarocks install csvigo

# if you need to use web application
PREFIX=$HOME/torch/install luarocks install turbo

# if you need to use cuDNN library. cuDNN is required.
luarocks install cudnn
  • If you can't install without sudo, then install with sudo. After that do this:
    sudo chown -R $USER:$USER torch/ where $USER is your username of course.

So in essence use chown to give yourself rights to the folder recursively.

  1. Actually installing waifu2x
    git clone --depth 1 https://github.com/nagadomi/waifu2x.git

Now test it:

cd waifu2x
th waifu2x.lua

Yep, you are set now.

@RaitaroH RaitaroH changed the title from Torch failed to build to Torch failed to build (How to install waifu2x in ubuntu 16.04 tutorial for dummies) Feb 19, 2018

@RaitaroH

This comment has been minimized.

RaitaroH commented Feb 19, 2018

How to make it easier to use waifu2x

  1. Add this to your .bashrc
WAIFU2X_DIR=~/waifu2x
waifu2x()
{
    th ${WAIFU2X_DIR}/waifu2x.lua -model_dir ${WAIFU2X_DIR}/models/anime_style_art_rgb $@
}
waifu2x_photo()
{
    th ${WAIFU2X_DIR}/waifu2x.lua -model_dir ${WAIFU2X_DIR}/models/photo $@
}

Change the waifu directory to where you have it.

  1. Now you can use the following scripts:
  • waifu2xAndNoise noise file
#!/bin/bash
source ~/.bashrc
waifu2x -m noise_scale -noise_level $1 -i $2 -o %s_2x.png > /dev/null 2>&1
  • waifu2xPhotoAndNoise noise file
#!/bin/bash
source ~/.bashrc
waifu2x_photo -m noise_scale -noise_level $1 -i $2 -o %s_2x.png > /dev/null 2>&1
  • waifu2x_batch noise dir_to_pics dir_to_output_pics
    Note: you can also use the deskop entries as well. Simply select multiple files and use one of the options. It will act like batch, but you don't get the progress bar. Also please understand that this will build them at the SAME TIME thus it will take a lot of PROCESSING POWER. The batch script allows one by one coversion
#!/bin/bash
source .bashrc
noise=$1
dirin=$2
dirout=$3

find $dirin -name "*.png" -o -name "*.jpg" > ~/Desktop/image_list.txt

waifu2x -m noise_scale -noise_level $noise -l ./image_list.txt -o $dirout/%s_2x2.png

rm ~/Desktop/image_list
  1. Now in case you are also using KDE Plasma 5 you can add context menu entries as well. Keep in mind that if you select multiple files at once it will actually work as a batch.
    In the folder ~/.local/share/kservices5/ServiceMenus/ make a file called waifu2x.desktop:
[Desktop Entry]
Type=Service
X-KDE-ServiceTypes=KonqPopupMenu/Plugin
MimeType=image/*;
Actions=2x;2x_noise1;2x_noise2;2x_noise3;2x_photo;2x_noise1_photo;2x_noise2_photo;2x_noise3_photo
X-KDE-Submenu=waifu2x
Icon=zoom-in

[Desktop Action 2x]
Name=2x
Icon=zoom-in
Exec=waifu2xAndNoise 0 %u

[Desktop Action 2x_noise1]
Name=2x and noise reduction 1
Icon=labplot-1x-zoom
Exec=waifu2xAndNoise 1 %u

[Desktop Action 2x_noise2]
Name=2x  and noise reduction 2
Icon=labplot-2x-zoom
Exec=waifu2xAndNoise 2 %u

[Desktop Action 2x_noise3]
Name=2x  and noise reduction 3
Icon=labplot-3x-zoom
Exec=waifu2xAndNoise 3 %u

[Desktop Action 2x_photo]
Name=2x for photos
Icon=zoom-in
Exec=waifu2xPhotoAndNoise 0 %u

[Desktop Action 2x_noise1_photo]
Name=2x and noise reduction 1 for photos
Icon=labplot-1x-zoom
Exec=waifu2xPhotoAndNoise 1 %u

[Desktop Action 2x_noise2_photo]
Name=2x  and noise reduction 2 for photos
Icon=labplot-2x-zoom
Exec=waifu2xPhotoAndNoise 2 %u

[Desktop Action 2x_noise3_photo]
Name=2x  and noise reduction 3 for photos
Icon=labplot-3x-zoom
Exec=waifu2xPhotoAndNoise 3 %u
@nagadomi

This comment has been minimized.

Owner

nagadomi commented Feb 21, 2018

Note: you can also use the deskop entries as well. Simply select multiple files and use one of the options. It will act like batch, but you don't get the progress bar.

waifu2x.lua supports batch conversion.
https://github.com/nagadomi/waifu2x#batch-conversion

@RaitaroH

This comment has been minimized.

RaitaroH commented Feb 21, 2018

@nagadomi Yeah I know, but there is no point in conding a separate script for the context menu that can do batch where funny enough the ones I already provided do the trick anyway. I did use the batch script myself and was nice.

@tommay

This comment has been minimized.

tommay commented Mar 3, 2018

Nice! I'd failed six ways from Sunday to get waifu2x running on an EC2 g2,2xlarge instance running Ubuntu 16.04. Now I've got it up and running with your guide. Thank you!

But I found it necessary to make two small tweaks:

  • sudo apt-get install cuda became sudo apt-get install cuda-8-0 otherwise I got version 9-something.
  • sudo ln -s ... became sudo ln -sf because some of the symlinks already existed and needed to be overwritten.
@RaitaroH

This comment has been minimized.

RaitaroH commented Mar 3, 2018

@tommay Ah ok then. You are right cuda9 will end up being installed if you have it in the repos. Also I didn't have the symlinks there but sure why not, try to force them. I also hope my scripts will help you as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment