{"id":21802464,"url":"https://github.com/qengineering/realsr-ncnn-jetson-nano","last_synced_at":"2025-07-31T08:38:32.399Z","repository":{"id":41251261,"uuid":"363891823","full_name":"Qengineering/realsr-ncnn-Jetson-Nano","owner":"Qengineering","description":"Award winning RealSR super resolution with ncnn on Jetson Nano","archived":false,"fork":false,"pushed_at":"2023-11-24T08:41:27.000Z","size":18,"stargazers_count":41,"open_issues_count":3,"forks_count":12,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-01-26T03:45:44.235Z","etag":null,"topics":["deep-learning","jetson-nano","ncnn","ncnn-framework","realsr","realsr-ncnn-vulkan","super-resolution","vulkan"],"latest_commit_sha":null,"homepage":"https://qengineering.eu/deep-learning-examples-on-raspberry-32-64-os.html","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Qengineering.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-05-03T10:22:21.000Z","updated_at":"2025-01-25T15:25:59.000Z","dependencies_parsed_at":"2023-11-24T09:44:23.120Z","dependency_job_id":null,"html_url":"https://github.com/Qengineering/realsr-ncnn-Jetson-Nano","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Qengineering%2Frealsr-ncnn-Jetson-Nano","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Qengineering%2Frealsr-ncnn-Jetson-Nano/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Qengineering%2Frealsr-ncnn-Jetson-Nano/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Qengineering%2Frealsr-ncnn-Jetson-Nano/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Qengineering","download_url":"https://codeload.github.com/Qengineering/realsr-ncnn-Jetson-Nano/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244752360,"owners_count":20504256,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["deep-learning","jetson-nano","ncnn","ncnn-framework","realsr","realsr-ncnn-vulkan","super-resolution","vulkan"],"created_at":"2024-11-27T11:28:52.896Z","updated_at":"2025-03-21T07:14:53.027Z","avatar_url":"https://github.com/Qengineering.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# realsr-ncnn-Jetson-Nano\n![output image]( https://qengineering.eu/images/SRflat.png )\n## Real Super Resolution with the ncnn framework. \u003cbr/\u003e\n[![License](https://img.shields.io/badge/License-BSD%203--Clause-blue.svg)](https://opensource.org/licenses/BSD-3-Clause)\u003cbr/\u003e\u003cbr/\u003e\nPaper :https://openaccess.thecvf.com/content_CVPRW_2020/papers/w31/Ji_Real-World_Super-Resolution_via_Kernel_Estimation_and_Noise_Injection_CVPRW_2020_paper.pdf\u003cbr/\u003e\u003cbr/\u003e\nMade for a Jetson Nano see [Q-engineering deep learning examples](https://qengineering.eu/deep-learning-examples-on-raspberry-32-64-os.html)\u003cbr/\u003e\u003cbr/\u003e\nThe solution of the _Tencent YouTu Lab_ is the winner of **CVPR NTIRE 2020 Challenge on Real-World Super-Resolution** in both tracks.\u003cbr/\u003e\nhttps://arxiv.org/abs/2005.01996\n\n------------\n\n## Dependencies.\nWe could fork the original code, but to keep the code up to the minute, we'll use a link to the original [repo](https://github.com/nihui/realsr-ncnn-vulkan).\u003cbr/\u003e\nNo need to have the ncnn framework on your Jetson Nano on forehand.\n\n------------\n\n## Installing the app.\nThe Jetson Nano is getting old. More than ten years now. Many software packages evolve and require more up-to-date environments. For example, in the case of glslang, a more recent version of Cmake and GNU compiler. Both will first need to be updated before the realsr app can be installed.\n### CMake\nThe current CMake is the 3.10.2 version. That is too old. \u003cbr/\u003e\nLet's update the latest version by building it from scratch\nFirst, remove the old version.\u003cbr/\u003e\nThe old version is located at `/usr/bin`, which is visited before the new version at `/usr/local/bin` is scanned.\u003cbr/\u003e\nThis way, you still keep using the old version.\n```\nsudo apt-get remove --purge cmake\n```\nDownload the new version and a single dependency.\n```\nsudo apt-get install libssl-dev\nwget https://cmake.org/files/v3.20/cmake-3.20.0.tar.gz\ntar -xzvf cmake-3.20.0.tar.gz\n```\nCompile the package. It takes a while\n```\ncd cmake-3.20.0\n./bootstrap\nmake -j4\nsudo make install\n```\nAnd test the new version\n```\ncmake --version\n```\n![output image]( https://qengineering.eu/images/Cmake_3_20_Rdy_Nano.png)\u003cbr/\u003e\n### GNU\nOn the Jetpack 4.5.1, the GNU compiler is version 7.5.0. That is also too old. \u003cbr/\u003e\nLet's install version 10.1. It will take a while, more than 3 hours!\u003cbr/\u003e\nStart with the dependencies.\n```\n$ sudo apt-get install build-essential wget m4 flex bison\n```\nDownload GNU 10.1\n```\n$ cd\n$ wget https://ftpmirror.gnu.org/gcc/gcc-10.1.0/gcc-10.1.0.tar.xz\n$ tar xf gcc-10.1.0.tar.xz\n$ cd gcc-10.1.0\n$ sudo contrib/download_prerequisites\n```\nCreate a build folder and run Cmake and Make. \n```\n$ cd\n$ mkdir gcc10build\n$ cd gcc10build\n$ ../gcc-10.1.0/configure -v \\\n  --build=aarch64-linux-gnu \\\n  --host=aarch64-linux-gnu \\\n  --target=aarch64-linux-gnu \\\n  --prefix=/usr/local/gcc-10.1.0 \\\n  --enable-checking=release \\\n  --enable-languages=c,c++ \\\n  --disable-multilib \\\n  --program-suffix=-10.1\n$ make -j4\n$ sudo make install-strip\n```\nIt is time to activate the GNU-10.1 compiler. It can be a _temporary_ or _permanent_ activation.\u003cbr\u003e \nIt seems logical to set the compiler to the new GNU-10.1 version. However, previously compiled code with the GNU-7.5.0 version may conflict with the newly installed version.\nCare must be taken!\u003cbr\u003e\u003cbr\u003e\nIn our case, with the realsr app, we using temporary activation.\u003cbr\u003e\n#### Temporarily activation.\nSet a path to the GNU-10.1 location in ~/.bashrc\n```\n$ cd\n$ nano .bashrc\n\n#at the end insert these two lines\nexport PATH=/usr/local/gcc-10.1.0/bin:$PATH\nexport LD_LIBRARY_PATH=/usr/local/gcc-10.1.0/lib64:$LD_LIBRARY_PATH\n#close with \u003cCtrl\u003e+\u003cX\u003e, \u003cY\u003e, \u003cEnter\u003e\n$ source ~/.bashrc\n```\nActivate the GNU-10.1 compiler in the SAME terminal window where you are going to compile glslang.\n```\n$ export CC=gcc-10.1\n$ export CXX=g++-10.1\n```\nAt this point, CMake will select the GNU-10.1 version (only in this terminal). \nAll other terminals are still using the original GNU-7.5.0 version.\n#### Permanently activation.\nTo set the GNU-10.1 compiler permantly, you modify a few symbolic links.\n```\n$ sudo rm cpp\n$ sudo ln -s /usr/local/gcc-10.1.0/bin/cpp-10.1 /usr/bin/cpp\n$ sudo rm g++\n$ sudo ln -s /usr/local/gcc-10.1.0/bin/aarch64-linux-gnu-g++-10.1 /usr/bin/g++\n$ sudo rm gcc\n$ sudo ln -s /usr/local/gcc-10.1.0/bin/aarch64-linux-gnu-gcc-10.1 /usr/bin/gcc\n$ sudo rm gcc-ar\n$ sudo ln -s /usr/local/gcc-10.1.0/bin/aarch64-linux-gnu-gcc-ar-10.1 /usr/bin/gcc-ar\n$ sudo rm gcc-nm\n$ sudo ln -s /usr/local/gcc-10.1.0/bin/aarch64-linux-gnu-gcc-nm-10.1 /usr/bin/gcc-nm\n$ sudo rm gcc-ranlib\n$ sudo ln -s /usr/local/gcc-10.1.0/bin/aarch64-linux-gnu-gcc-ranlib-10.1 /usr/bin/gcc-ranlib\n\n$ sudo rm aarch64-linux-gnu-cpp\n$ sudo ln -s /usr/local/gcc-10.1.0/bin/cpp-10.1 /usr/bin/aarch64-linux-gnu-cpp\n$ sudo rm aarch64-linux-gnu-g++\n$ sudo ln -s /usr/local/gcc-10.1.0/bin/aarch64-linux-gnu-g++-10.1 /usr/bin/aarch64-linux-gnu-g++\n$ sudo rm aarch64-linux-gnu-gcc\n$ sudo ln -s /usr/local/gcc-10.1.0/bin/aarch64-linux-gnu-gcc-10.1 /usr/bin/aarch64-linux-gnu-gcc\n$ sudo rm aarch64-linux-gnu-gcc-ar\n$ sudo ln -s /usr/local/gcc-10.1.0/bin/aarch64-linux-gnu-gcc-ar-10.1 /usr/bin/aarch64-linux-gnu-gcc-ar\n$ sudo rm aarch64-linux-gnu-gcc-nm\n$ sudo ln -s /usr/local/gcc-10.1.0/bin/aarch64-linux-gnu-gcc-nm-10.1 /usr/bin/aarch64-linux-gnu-gcc-nm\n$ sudo rm aarch64-linux-gnu-gcc-ranlib\n$ sudo ln -s /usr/local/gcc-10.1.0/bin/aarch64-linux-gnu-gcc-ranlib-10.1 /usr/bin/aarch64-linux-gnu-gcc-ranlib\n```\nNow, the GNU-10.1 will be your compiler system-wide.\u003cbr\u003e\n![Screenshot from 2023-11-14 12-29-26](https://github.com/Qengineering/realsr-ncnn-Jetson-Nano/assets/44409029/73394793-137b-410d-8035-6d4f7da3b7f0)\u003cbr\u003e\nNote that you can always replace the symbolic links to their original values, thereby restoring the GNU-7.5.1 again.\u003cbr\u003e\nAnd, once again, you may run into problems mixing the two compilers!\n\n### glslang\nWith CMake up to date, the next package to install is glslang.\nStart with downloading the code.\n```\ncd ~\ngit clone https://github.com/KhronosGroup/glslang.git\n```\nInstall other tools\n```\ncd glslang\ngit clone https://github.com/google/googletest.git External/googletest\n./update_glslang_sources.py\n```\n![output image]( https://qengineering.eu/images/glslang_external_nano.png)\u003cbr/\u003e\nNow the configuration can be set\n```\nmkdir build\ncd build\n```\nCompile and install\n```\ncmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=\"$(pwd)/install\" ..\nmake -j4 install\n```\n![output image]( https://qengineering.eu/images/glslang_rdy_nano.png)\u003cbr/\u003e\u003cbr/\u003e\nMost important is the folder where the binaries are stored.\u003cbr/\u003e This directory must be given in the `CMakeLists.txt` later on.\u003cbr/\u003e\u003cbr/\u003e\n![output image]( https://qengineering.eu/images/glslang_folder_nano.png)\u003cbr/\u003e\n### realsr-ncnn-vulkan\nNow we can install the realsr ncnn framework.\u003cbr/\u003e\nAlthough your Nano has Vulkan, ncnn still needs the header files, hence the installation.\n```\ncd ~\nsudo apt-get install libvulkan-dev\ngit clone https://github.com/nihui/realsr-ncnn-vulkan.git\ncd realsr-ncnn-vulkan\ngit submodule update --init --recursive\n```\nBefore building the framework, we need to set the path to the glslang folder in de make file.\u003cbr/\u003e\n![output image]( https://qengineering.eu/images/CMakeLists_nano.png)\u003cbr/\u003e\nOpen `~/realsr-ncnn-vulkan/src/CMakeLists.txt` and alter line 19.\u003cbr/\u003e \nIf you have the glslang installed in the same folder as we did, you can change the line to\n```\nfind_program(GLSLANGVALIDATOR_EXECUTABLE NAMES glslangValidator PATHS /home/\u003cusername\u003e/glslang/build/install/bin)\n```\nOur username was _jetson_ in the screen dump above. Yours will undoubtedly be different.\u003cbr/\u003e\n![output image]( https://qengineering.eu/images/CmakeLists_Edit_nano2.png)\u003cbr/\u003e\u003cbr/\u003e\nLast step is the building of the realsr framework.\n```\nmkdir build\ncd build\ncmake ../src\n```\nIf you end up during `cmake` with errors like the one below, you still have the old verion 3.10.2 CMake running.\u003cbr/\u003e\n![output image]( https://qengineering.eu/images/realsr_error_nano.png)\u003cbr/\u003e\nCompile.\n```\ncmake --build . -j 4\n```\nOnce done, you can test your software. \n```\n./realsr-ncnn-vulkan -i ../images/0.png -o ../images/out.png -s 4 -x -m ../models/models-DF2K\n\n```\n![output image]( https://qengineering.eu/images/realsr_nano_run.png)\u003cbr/\u003e\nBe patient, it will take quite a while to process. The image is cut into small tiles.\u003cbr/\u003e\nThese are processed one by one. When done, they are glued together with the exception of a 10-pixel border to avoid border artefacts.\u003cbr/\u003e\nThe `models-DF2K_JPEG` is intended for use with jpeg images. Jpeg images can have specific compression artifacts that the regular `models-DF2K` cannot handle.\u003cbr/\u003e\nAdditional information can be found on this [blog](https://linuxreviews.org/RealSR).\u003cbr/\u003e\u003cbr/\u003e\n## Enjoy!\n![output image]( https://qengineering.eu/images/SRgarden.png)\u003cbr/\u003e\u003cbr/\u003e\n![output image]( https://qengineering.eu/images/SRcat.png)\u003cbr/\u003e\u003cbr/\u003e\nMany thanks to [nihui](https://github.com/nihui/) again!\u003cbr/\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fqengineering%2Frealsr-ncnn-jetson-nano","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fqengineering%2Frealsr-ncnn-jetson-nano","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fqengineering%2Frealsr-ncnn-jetson-nano/lists"}