DeepUPE
DeepUPE copied to clipboard
Installation Guide
I finally managed to make it work. It took me a week mainly because I tried on Windows 10 first, then I tried on lighter versions of Linux, battling with all the bugs and issues unrelated to the primary objective I was aiming at. I also spent some time taking notes and compiling this guide.
Save yourself a lot of time, effort and perhaps frustration, and follow the final steps I took, detailed below, although it is not guaranteed to work in your system.
UBUNTU 20.04 INSTALLATION (2.7GB download, ~25GB total installation):
Forget about Windows, DeepUPE is not intended for it out of the box. Instead, install Ubuntu 20.04 on a +32GB pendrive (64GB highly recommended, or on your computer, also it requires an NVIDIA card for CUDA to be enabled. I'm using a high speed 64GB Sandisk Extreme Pro SD card - 95MB/s).
Follow the OS instructions from: https://www.fosslinux.com/10212/how-to-install-a-complete-ubuntu-on-a-usb-flash-drive.htm
Do not install lighter versions like Ubuntu Bionic, MX Linux or Porteus as they lack important capabilities (apt package installation management tool and proper credentials management, like no password for root, which prevents software from installing properly) and there is really no relevant gain in performance by using them.
Download the image (https://ubuntu.com/download/desktop) and then, either burn it to a DVD, or use Rufus (https://rufus-usb.en.uptodown.com/windows) to "burn" it to another pendrive like I did, as I've got no DVD drive.
PACKAGES INSTALLATION:
Once the OS is installed and working properly, open a terminal window (CTRL+ALT+T), type the commands below (the software versions in brackets are the versions I installed, other versions might work if you do a case by case test):
Update list of packages: sudo apt update
Install python 2.7 (it must be 2.7): sudo apt install python
Install curl (7.68): sudo apt install curl
Install pip:
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python get-pip.py
Check pip version (+19.2): pip show pip
If needed, upgrade to latest (20.2): pip install pip --upgrade
(To install a specific version using pip: pip install software==version, i.e. pip install pillow==2.9.0).
Install git (2.25.1) by following the instructions: sudo apt-get install git-all
Add your "Home" binaries folder to path just in case packages also end up installed there, i.e.: export PATH="$HOME/bin:$PATH"
Type $PATH to confirm it was successful, edit file ".profile" in /Home/"your_user_name" to automatically add $HOME/bin to path next time (do this every time you are requested to make a change to the environment variable on this guide, otherwise it will reset as soon as the terminal is closed and possibly make a perfectly good installation stop working until the environment variables are populated again).
Clone the DeepUPE repository: git clone https://github.com/wangruixing/DeepUPE.git
Change to main folder: cd DeepUPE/main
Use pip to get missing packages (setproctitle, numpy, pyglib, scikit-image, tensorflow_gpu, python_gflags, python_magic, glog, six, Werkzeug, protobuf, mock, funcsigs, setproctitle, pyglib): pip install -r requirements.txt
You should see no errors, repeat the command pip install -r requirements.txt to confirm there are no errors.
Install Python 2.7 library (contains Python.h and the other python essential headers): sudo apt-get install python-dev
Install cython (0.29.21): pip install cython
Install tensorflow (2.1.0): pip install tensorflow
Install gcc 4.9 (up to 5.3 should work though, 5.5 probably will not), this is a deprecated version and one of the most difficult to get. I found a working version in debian ftp. Open the apt sources file in the text editor: "/etc/apt/sources.list"
Include debian ftp in the "sources.list" file by copying and pasting the server path into the file in the text editor:
deb http://ftp.us.debian.org/debian/ jessie main contrib non-free
Also include it as a source ftp in the "sources.list": deb-src http://ftp.us.debian.org/debian/ jessie main contrib non-free
Save "sources.list" and close the editor.
Update the repositories: sudo apt-get update --allow-insecure-repositories
Install gcc 4.9: sudo apt-get install gcc-4.9
Install g++ 4.9: sudo apt-get install g++-4.9
Create a link, so "gcc" command will mean "gcc4.9" and not a later version that would never work (check gcc and g++ path and edit this command as needed, i.e. if they were installed to "/Home/bin/gcc-4.9" then replace "/usr/bin/gcc-4.9" in the command):
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.9 10
Also create a link so "g++" command will mean "g++4.9" and not a later version:
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.9 10
Get opencv (4.2.0.32): pip install opencv-python
Install jpeg library: sudo apt-get install libjpeg-dev
Install png library (notice it is zlib "one g" and not zlib "L g"): sudo apt-get install zlib1g-dev
Install pillow (6.2.2): sudo apt-get install pillow
INSTALL GPU SUPPORT:
Install graphics card driver (i.e. if you've got a new NVIDIA GPU: v440): sudo ubuntu-drivers autoinstall
(or, i.e. sudo apt install nvidia-driver-440).
Activate NVIDIA driver and reboot (if you see a blank screen, flashing screen, thin rainbow line on top or colorful artifacts, reboot again and on the boot-up GRUB menu, select Ubuntu, type "e", append to the "linux" line -> nouveau.modeset=0 and press F10).
Create a free developer account on NVIDIA website.
Download CUDA 8.0 (1.9GB): file: https://developer.nvidia.com/compute/cuda/8.0/Prod2/local_installers/cuda-repo-ubuntu1604-8-0-local-ga2_8.0.61-1_amd64-deb source: (https://developer.nvidia.com/cuda-80-ga2-download-archive) Download CUDA 8.0 patch: file: https://developer.nvidia.com/compute/cuda/8.0/Prod2/patches/2/cuda-repo-ubuntu1604-8-0-local-cublas-performance-update_8.0.61-1_amd64-deb source: (https://developer.nvidia.com/cuda-80-ga2-download-archive) Download libcudnn 6.0 runtime: file: https://developer.download.nvidia.com/compute/machine-learning/repos/ubuntu1604/x86_64/libcudnn6_6.0.21-1+cuda8.0_amd64.deb source: (https://developer.download.nvidia.com/compute/machine-learning/repos/ubuntu1604/x86_64/) Download libcudnn 6.0 dev: https://developer.download.nvidia.com/compute/machine-learning/repos/ubuntu1604/x86_64/libcudnn6-dev_6.0.21-1+cuda8.0_amd64.deb Download libcudnn 5.0 runtime: https://developer.download.nvidia.com/compute/machine-learning/repos/ubuntu1604/x86_64/libcudnn5_5.1.10-1+cuda8.0_amd64.deb Download libcudnn 5.0 dev: https://developer.download.nvidia.com/compute/machine-learning/repos/ubuntu1604/x86_64/libcudnn5-dev_5.1.10-1+cuda8.0_amd64.deb Download TensorRT 4.0 for cuda 8.0 (0.5GB): https://developer.nvidia.com/compute/machine-learning/tensorrt/4.0/ga/nv-tensorrt-repo-ubuntu1604-cuda8.0-ga-trt4.0.1.6-20180612_1-1_amd64
Once downloaded, install CUDA 8.0:
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
Repeat the installation steps (sudo apt-get update and sudo apt-get install) for each pack:
CUDA 8.0 patch: sudo dpkg -i cuda-repo-ubuntu1604-8-0-local-cublas-performance-update_8.0.61-1_amd64-deb
Install libcudnn 6.0 runtime: sudo dpkg -i libcudnn6_6.0.21-1+cuda8.0_amd64.deb
Install libcudnn 6.0 dev: sudo dpkg -i libcudnn6-dev_6.0.21-1+cuda8.0_amd64.deb
Install libcudnn 5.0 runtime: sudo dpkg -i libcudnn5_5.1.10-1+cuda8.0_amd64.deb
Install libcudnn 5.0 dev: sudo dpkg -i libcudnn5-dev_5.1.10-1+cuda8.0_amd64.deb
Install TensorRT 4.0: sudo dpkg -i nv-tensorrt-repo-ubuntu1604-cuda8.0-ga-trt4.0.1.6-20180612_1-1_amd64.deb
Look for _"licublas" file in your system and make sure the environment variable LD_LIBRARY_PATH contains its path location: i.e. export LD_LIBRARY_PATH="/HOME/Lib:$LD_LIBRARY_PATH"
Set environment variable PATH to reflect CUDA 8.0 location (confirm its location in your system):
export PATH=/usr/local/cuda-8.0/bin:$PATH
Set environment variable for activating CUDA: export CUDA_VISIBLE_DEVICES="0" (use "-1" to deactivate, use "1" if you've got "2" NVDIA GPU's as they are numbered from 0).
You might need more folders to be added to both environment variables $PATH and $LD_LIBRARY_PATH like "/.../lib64" and others.
TEST GPU:
Test tensorflow installation: Create a temporary folder. Open a text editor and type the commands:
import tensorflow as tf
hello = tf.constant('Hello, TensorFlow!')
sess = tf.Session()
Save as "runme.py" in the newly created folder.
Close "runme.py".
Change to the new folder: cd foldername
Run the test: python runme.py
You should see some warnings (W) and information (I) but no errors (E)
COMPILING:
Ugrade numpy (1.16.6 instead of 1.12.0, check version by typing: pip show numpy): pip install numpy --upgrade
Build the files: make
You should see no errors.
EDIT THE ORIGINAL SCRIPTS
The original scripts are not going to work out of the box because of their age and other issues. In my system, the DeepUPE script could not find the "checkpoints" folder and could not find "main" folder, but as it runs from "main "and the python scripts are unique in the cloned structure, then it is actually unnecessary to mention the "main" folder in the script.
Open and edit "run.py" by removing "main." from "main.models" so it reads import models: line #30
Also remove "main." from "main.utils" so it reads import utils: line #31
Also locate the environment variable CUDA_VISIBLE_DEVICES and update it in accordance with the number of GPU's you've got ("0" for 1, "1" is for 2 GPU's and so on). It defaults to "1" which is incorrect if you've got only one NVIDIA GPU (I consider this a bug as it effectively prevents the software from running out of the box in single GPU machines and gives no clear clue of what is going on, making you waste time trying to figure out what failed. Is this command even necessary since the environment variable exists? It should warn the user or be disregarded once the environmental variable is confirmed to exist).
Save and close "run.py".
Open and edit "models.py" by removing "main." from "main.layers" so line #21 reads:
from layers import (conv, fc, bilateral_slice_apply)
Save and close "models.py".
Open and edit "layers.py" by removing "from main" from line #20 so it reads: import hdrnet.ops
Save and close "layers.py".
Copy folder "checkpoints" to main folder Create a sub-folder in "main" folder to house the input pictures (i.e. underex). Create a sub-folder in "main" folder to house the output pictures (i.e. rightex).
EDIT THIRD PARTY SCRIPT:
Find "pil_plugin.py" in "home/username/.local/lib/python2.7/site-packages/skimage/io/_plugins" (or search for it).
Open "pil_plugin.py" and modify line #112 because the function fromstring() has been replaced by frombytes() after revision 2.9.0 of pillow -> img = Image.frombytes(mode, (arr.shape[1], arr.shape[0]), arr)
Close and save "pil_plugin.py" (if you reinstall scikit-main or pillow, you will probably need to modify "pil_plugin.py" again)
FIRST RUN:
For a first run, place only one picture in the input folder you created (i.e. folder underex. If the extension is capital ".JPG", rename it to lowercase ".jpg", othwerwise the script will not find the picture). Make sure you are back at /DeepUPE/main before the next step.
Finally run the script: python run.py checkpoints underex rightex
It should take about a minute or more for the first picture. If it ran without errors or warnings, you should see a picture in the output folder (i.e folder rightex), there are no whistles and bells informing it has finished. It will process pictures in sequence if more than one exists in the input folder (i.e. folder underex). If you survived until here, enjoy.
thanks for your guide ,is there any way for cuda 10.2
I've got both cuda 10 and cuda 8 installed, I installed version 8 first but it should work in any order. One issue I had that was difficult to debug was related to the version of gcc/g++. DeepUPE needs gcc/g++4.9, but installing cuda 10 with the required latest NVIDIA driver will need the same version of gcc used to compile the kernel, which on my case was gcc/g++ 9.0. If you linked gcc/g++ 4.9, you need to remove the link, so when you type gcc it points out to the latest version and not version 4.9.
Thank you for your guide. What version of the Ubuntu kernel are you using and is it compatible with Ubuntu 20 and CUDA 8.0?I am in trouble when compiling CUDA files that are not in DEB format, although I have tried both on the website and the download link above. How should I solve this problem
Thank you for your guide. What version of the Ubuntu kernel are you using and is it compatible with Ubuntu 20 and CUDA 8.0?I am in trouble when compiling CUDA files that are not in DEB format, although I have tried both on the website and the download link above. How should I solve this problem
Currently I can run it on Ubuntu 20.04 with CUDA 8.0 no problem. What error message you get?
Thank you for your guide. What version of the Ubuntu kernel are you using and is it compatible with Ubuntu 20 and CUDA 8.0?I am in trouble when compiling CUDA files that are not in DEB format, although I have tried both on the website and the download link above. How should I solve this problem Currently I can run it on Ubuntu 20.04 with CUDA 8.0 no problem. What error message you get?
When I run CUDA 8.0 .run file, an error occurred: Samples: Cannot find Toolkit in /usr/local/cuda-8.0_ To solve this problem, type the command:sudo dpkg -i cuda-repo-ubuntu1604-8-0-local-ga2_8.0.61-1_amd64.deb, But there was a new error: dpkg-deb: error: 'cuda-repo-ubuntu1604-8-0-local-ga2_8.0.61-1_amd64.deb' is not a Debian format archive I'm not sure if it was an error when downloading the file, but I have repeatedly downloaded the file many times and have faced the same error every time.
When I run CUDA 8.0 .run file, an error occurred: Samples: Cannot find Toolkit in /usr/local/cuda-8.0_ To solve this problem, type the command:sudo dpkg -i cuda-repo-ubuntu1604-8-0-local-ga2_8.0.61-1_amd64.deb, But there was a new error: dpkg-deb: error: 'cuda-repo-ubuntu1604-8-0-local-ga2_8.0.61-1_amd64.deb' is not a Debian format archive I'm not sure if it was an error when downloading the file, but I have repeatedly downloaded the file many times and have faced the same error every time.
Try this solution (scroll down the linked page to see the answer): https://unix.stackexchange.com/questions/429549/cuda-on-debian-9-where-is-the-toolkit