From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp11.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms5.migadu.com with LMTPS id gFffKgcDgmMByQAAbAwnHQ (envelope-from ) for ; Sat, 26 Nov 2022 13:13:59 +0100 Received: from aspmx1.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp11.migadu.com with LMTPS id UAHFKgcDgmMaUQEA9RJhRA (envelope-from ) for ; Sat, 26 Nov 2022 13:13:59 +0100 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 5CA2F108EE for ; Sat, 26 Nov 2022 13:13:59 +0100 (CET) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oyu3Y-0004rh-DO; Sat, 26 Nov 2022 07:13:16 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oyu3K-0004pF-FK for guix-patches@gnu.org; Sat, 26 Nov 2022 07:13:02 -0500 Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oyu3K-0005L6-6s for guix-patches@gnu.org; Sat, 26 Nov 2022 07:13:02 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1oyu3K-00018D-33 for guix-patches@gnu.org; Sat, 26 Nov 2022 07:13:02 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#59607] [PATCH 2/8] gnu: Add real-esrgan-ncnn. References: In-Reply-To: Resent-From: Liliana Marie Prikler Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Sat, 26 Nov 2022 12:13:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 59607 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 59607@debbugs.gnu.org Received: via spool by 59607-submit@debbugs.gnu.org id=B59607.16694647244230 (code B ref 59607); Sat, 26 Nov 2022 12:13:02 +0000 Received: (at 59607) by debbugs.gnu.org; 26 Nov 2022 12:12:04 +0000 Received: from localhost ([127.0.0.1]:38046 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oyu2N-00015s-1o for submit@debbugs.gnu.org; Sat, 26 Nov 2022 07:12:04 -0500 Received: from mail-wm1-f66.google.com ([209.85.128.66]:39926) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oyu2K-00014s-1K for 59607@debbugs.gnu.org; Sat, 26 Nov 2022 07:12:00 -0500 Received: by mail-wm1-f66.google.com with SMTP id 83-20020a1c0256000000b003d03017c6efso7358323wmc.4 for <59607@debbugs.gnu.org>; Sat, 26 Nov 2022 04:12:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:message-id:content-transfer-encoding:to:subject:date :from:from:to:cc:subject:date:message-id:reply-to; bh=S1xNGSAZzmOdxzyxcW8rowRjT/fDpcfR7DeQKFy4zRM=; b=GyO4KAMzldFwRpPgsoZGDlfRlqxHpwLguMhwN8mniBni+7HtqCblUpn6AIgyiHp2Ur WDdGKBuIvW7Nmm3sudaAjtQsgKgSFqdCfWDjG7n0Vz+P65LCNt3wwIN7DRHdh6xC9Yu/ okJsnwiJrZeo0nzXAJUZBCQvJNTUqx0W0W5c2tFVVRgwZC6lxBFMK+FlCiNb0EVrVbEM jb0UGjivXQ2HDwek69rsIWWGGMB1jNM40dzwMp6FcBSCWz2UEb1nJMP0QOOKD0h0JZmR rc+sh6TLgB3641D+IX18uDxMkVbJQ7FD8df1NICUyMNI4mfJAwtzCG6BOFy9FRUyifvb y+Fg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=mime-version:message-id:content-transfer-encoding:to:subject:date :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=S1xNGSAZzmOdxzyxcW8rowRjT/fDpcfR7DeQKFy4zRM=; b=jcpmG6A5VcIRyfsYeqDGW4ybw24wk5QRRNdMIJy7bsDDmFt1NCQWR2rp8dlPZ73ZnM 1ESky1YqTXOjHHcq+9UT5QzvGehW3aSdFgBWrf4iPLEGmYejZxSUXpCGsU5LI0iaBC81 Jr14pTk16NgQR4BIPHMlaCMdbK+kiKnT/5cVG9x/c+4EiefYXlqDk08MO37SttycRR5N xngggNkgm+E3Qzi5M82x6/9qqYxfw/POFf2Fo+k6E4CcUbYerjuNqlvcQ2btx8do28ke tDOMRNrGxLB/i0zOmQcpWTM73/X9TfRsAUMn0kzUFOwxoLat/Cd8dkX0xXVyWEPp6M4Y lBwg== X-Gm-Message-State: ANoB5plCuMInvSQMYit96SGRro/vkHeanfczP/+GHzSNvP9Xi1f+4Y2z nMZpA4S7d8/ujMfsKbtqbJSxHhltgA8= X-Google-Smtp-Source: AA0mqf4Sc52uA8BJQj96S24Vtwo9wWIvZDJKctone1zElAsOck6NFqAOL1xU9i8YBDZryaDYtdk4dA== X-Received: by 2002:a1c:2743:0:b0:3c6:e471:7400 with SMTP id n64-20020a1c2743000000b003c6e4717400mr17865844wmn.98.1669464714144; Sat, 26 Nov 2022 04:11:54 -0800 (PST) Received: from lumine.fritz.box (85-127-52-93.dsl.dynamic.surfer.at. [85.127.52.93]) by smtp.gmail.com with ESMTPSA id az26-20020a05600c601a00b003d01b84e9b2sm8695059wmb.27.2022.11.26.04.11.53 for <59607@debbugs.gnu.org> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 26 Nov 2022 04:11:53 -0800 (PST) From: Liliana Marie Prikler Date: Sun, 20 Nov 2022 02:16:54 +0100 Content-Transfer-Encoding: 7bit Message-ID: <3823ee69ed8ec08192f0c2ebc26fe8b3d399b381.camel@gmail.com> MIME-Version: 1.0 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+larch=yhetil.org@gnu.org Sender: guix-patches-bounces+larch=yhetil.org@gnu.org X-Migadu-Flow: FLOW_IN X-Migadu-Country: US ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1669464839; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding:resent-cc: resent-from:resent-sender:resent-message-id:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=S1xNGSAZzmOdxzyxcW8rowRjT/fDpcfR7DeQKFy4zRM=; b=L5XhtTYZGm8LBmhZ7l24Ca6t5KEEuPweXgxm03BWBIIpekRZyMlkGDaccrIifWU5NSmK5H hkR06as+WHg+RwaCnnCgv1hs2vdxUpq/LV92cdGcnz0cuBf5UeTNG1rXZE+Uv43z+bHXES NAGTFBh8+cwY8H4kFLYPaMV0h7QV33KRgQrffob9oU8txSCldp4xFvyYeJXdA6t8A48hpB uVfhfJGugJgT53SdO3vqRnymBR3nn8DHksR6BuAP8lqSiSkE+w6rIm5xNFyEX+EqFOeZOi 1q86OKobESBhAIfImBEy7fL4pvt+aNX4JBnz7DmxAQEC03KID1aKnYg3YjW6Qw== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1669464839; a=rsa-sha256; cv=none; b=as1RbitsPWUphT87WNfYucZ4AdozF6TpYg0ikl6aEprVCWggShBL7RHTWgPzespHZiToHh OjH6oIIRSWKG4fDqpHMkms29XPdB2ISHDjELhg9ZKRZhahuC3zLG4dVwNK5kKYPJZdLwsr IxTG+TGkXYlqAzTkr1EAnSR60oQae3z/dRt9BVVYkIEpKz95Npm7qlHr0KwgKWQEZ8KRyM 1aXvrC1fMojkZXtEAAWeDuz9eUUagqGEuPlSiqVTO8JWHKgf5XRlY88mYpnJxwMh2bn7jb 859aILXbZurHuhzWeN9A+WPQXlnvh8N3MFmDLLIMORcrO6uosXxIJtHJcAv2Ag== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=gmail.com header.s=20210112 header.b=GyO4KAMz; dmarc=fail reason="SPF not aligned (relaxed)" header.from=gmail.com (policy=none); spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org" X-Migadu-Spam-Score: 7.03 Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=gmail.com header.s=20210112 header.b=GyO4KAMz; dmarc=fail reason="SPF not aligned (relaxed)" header.from=gmail.com (policy=none); spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org" X-Migadu-Queue-Id: 5CA2F108EE X-Spam-Score: 7.03 X-Migadu-Scanner: scn1.migadu.com X-TUID: LU/vHA/e0x3y * gnu/packages/machine-learning.scm (real-esrgan-ncnn): New variable. --- gnu/packages/machine-learning.scm | 44 ++++ ...real-resgan-ncnn-simplify-model-path.patch | 195 ++++++++++++++++++ 2 files changed, 239 insertions(+) create mode 100644 gnu/packages/patches/real-resgan-ncnn-simplify-model-path.patch diff --git a/gnu/packages/machine-learning.scm b/gnu/packages/machine-learning.scm index e984e3004b..0566f4bd69 100644 --- a/gnu/packages/machine-learning.scm +++ b/gnu/packages/machine-learning.scm @@ -781,6 +781,50 @@ (define-public ncnn C++. It supports parallel computing as well as GPU acceleration via Vulkan.") (license license:bsd-3))) +(define-public real-esrgan-ncnn + (package + (name "real-esrgan-ncnn") + (version "0.2.0") + (source (origin + (method git-fetch) + (uri (git-reference + (url "https://github.com/xinntao/Real-ESRGAN-ncnn-vulkan") + (commit (string-append "v" version)))) + (file-name (git-file-name name version)) + (patches + (search-patches + "real-resgan-ncnn-simplify-model-path.patch")) + (sha256 + (base32 "1hlrq8b4848vgj2shcxz68d98p9wd5mf619v5d04pwg40s85zqqp")))) + (build-system cmake-build-system) + (arguments + (list #:tests? #f ; No tests + #:configure-flags + #~(list "-DUSE_SYSTEM_NCNN=TRUE" + "-DUSE_SYSTEM_WEBP=TRUE" + (string-append "-DGLSLANG_TARGET_DIR=" + #$(this-package-input "glslang") + "/lib/cmake")) + #:phases #~(modify-phases %standard-phases + (add-after 'unpack 'chdir + (lambda _ + (chdir "src"))) + (replace 'install + (lambda* (#:key outputs #:allow-other-keys) + (let ((bin (string-append (assoc-ref outputs "out") + "/bin"))) + (mkdir-p bin) + (install-file "realesrgan-ncnn-vulkan" bin))))))) + (inputs (list glslang libwebp ncnn vulkan-headers vulkan-loader)) + (home-page "https://github.com/xinntao/Real-ESRGAN") + (synopsis "Restore low-resolution images") + (description "Real-ESRGAN is a @acronym{GAN, Generative Adversarial Network} +aiming to restore low-resolution images. The techniques used are described in +the paper 'Real-ESRGAN: Training Real-World Blind Super-Resolution with Pure +Synthetic Data' by Xintao Wang, Liangbin Xie, Chao Dong, and Ying Shan. +This package provides an implementation built on top of ncnn.") + (license license:expat))) + (define-public onnx (package (name "onnx") diff --git a/gnu/packages/patches/real-resgan-ncnn-simplify-model-path.patch b/gnu/packages/patches/real-resgan-ncnn-simplify-model-path.patch new file mode 100644 index 0000000000..9a02269718 --- /dev/null +++ b/gnu/packages/patches/real-resgan-ncnn-simplify-model-path.patch @@ -0,0 +1,195 @@ +diff --git a/src/main.cpp b/src/main.cpp +index ebe0e62..ddfb742 100644 +--- a/src/main.cpp ++++ b/src/main.cpp +@@ -109,8 +109,7 @@ static void print_usage() + fprintf(stderr, " -o output-path output image path (jpg/png/webp) or directory\n"); + fprintf(stderr, " -s scale upscale ratio (can be 2, 3, 4. default=4)\n"); + fprintf(stderr, " -t tile-size tile size (>=32/0=auto, default=0) can be 0,0,0 for multi-gpu\n"); +- fprintf(stderr, " -m model-path folder path to the pre-trained models. default=models\n"); +- fprintf(stderr, " -n model-name model name (default=realesr-animevideov3, can be realesr-animevideov3 | realesrgan-x4plus | realesrgan-x4plus-anime | realesrnet-x4plus)\n"); ++ fprintf(stderr, " -m model-path model and parameter file name (sans .bin and .param extension)\n"); + fprintf(stderr, " -g gpu-id gpu device to use (default=auto) can be 0,1,2 for multi-gpu\n"); + fprintf(stderr, " -j load:proc:save thread count for load/proc/save (default=1:2:2) can be 1:2,2,2:2 for multi-gpu\n"); + fprintf(stderr, " -x enable tta mode\n"); +@@ -438,8 +437,7 @@ int main(int argc, char** argv) + path_t outputpath; + int scale = 4; + std::vector tilesize; +- path_t model = PATHSTR("models"); +- path_t modelname = PATHSTR("realesr-animevideov3"); ++ path_t model = PATHSTR(""); + std::vector gpuid; + int jobs_load = 1; + std::vector jobs_proc; +@@ -451,7 +449,7 @@ int main(int argc, char** argv) + #if _WIN32 + setlocale(LC_ALL, ""); + wchar_t opt; +- while ((opt = getopt(argc, argv, L"i:o:s:t:m:n:g:j:f:vxh")) != (wchar_t)-1) ++ while ((opt = getopt(argc, argv, L"i:o:t:m:g:j:f:vxh")) != (wchar_t)-1) + { + switch (opt) + { +@@ -461,18 +459,12 @@ int main(int argc, char** argv) + case L'o': + outputpath = optarg; + break; +- case L's': +- scale = _wtoi(optarg); +- break; + case L't': + tilesize = parse_optarg_int_array(optarg); + break; + case L'm': + model = optarg; + break; +- case L'n': +- modelname = optarg; +- break; + case L'g': + gpuid = parse_optarg_int_array(optarg); + break; +@@ -497,7 +489,7 @@ int main(int argc, char** argv) + } + #else // _WIN32 + int opt; +- while ((opt = getopt(argc, argv, "i:o:s:t:m:n:g:j:f:vxh")) != -1) ++ while ((opt = getopt(argc, argv, "i:o:t:m:g:j:f:vxh")) != -1) + { + switch (opt) + { +@@ -507,18 +499,12 @@ int main(int argc, char** argv) + case 'o': + outputpath = optarg; + break; +- case 's': +- scale = atoi(optarg); +- break; + case 't': + tilesize = parse_optarg_int_array(optarg); + break; + case 'm': + model = optarg; + break; +- case 'n': +- modelname = optarg; +- break; + case 'g': + gpuid = parse_optarg_int_array(optarg); + break; +@@ -549,6 +535,12 @@ int main(int argc, char** argv) + return -1; + } + ++ if (model.empty()) ++ { ++ fprintf(stderr, "no model given\n"); ++ return -1; ++ } ++ + if (tilesize.size() != (gpuid.empty() ? 1 : gpuid.size()) && !tilesize.empty()) + { + fprintf(stderr, "invalid tilesize argument\n"); +@@ -671,61 +663,17 @@ int main(int argc, char** argv) + } + } + +- int prepadding = 0; +- +- if (model.find(PATHSTR("models")) != path_t::npos +- || model.find(PATHSTR("models2")) != path_t::npos) +- { +- prepadding = 10; +- } +- else +- { +- fprintf(stderr, "unknown model dir type\n"); +- return -1; +- } ++ int prepadding = 10; + +- // if (modelname.find(PATHSTR("realesrgan-x4plus")) != path_t::npos +- // || modelname.find(PATHSTR("realesrnet-x4plus")) != path_t::npos +- // || modelname.find(PATHSTR("esrgan-x4")) != path_t::npos) +- // {} +- // else +- // { +- // fprintf(stderr, "unknown model name\n"); +- // return -1; +- // } + + #if _WIN32 +- wchar_t parampath[256]; +- wchar_t modelpath[256]; +- +- if (modelname == PATHSTR("realesr-animevideov3")) +- { +- swprintf(parampath, 256, L"%s/%s-x%s.param", model.c_str(), modelname.c_str(), std::to_string(scale)); +- swprintf(modelpath, 256, L"%s/%s-x%s.bin", model.c_str(), modelname.c_str(), std::to_string(scale)); +- } +- else{ +- swprintf(parampath, 256, L"%s/%s.param", model.c_str(), modelname.c_str()); +- swprintf(modelpath, 256, L"%s/%s.bin", model.c_str(), modelname.c_str()); +- } +- ++ path_t parampath = model + L".param"; ++ path_t modelpath = model + L".bin"; + #else +- char parampath[256]; +- char modelpath[256]; +- +- if (modelname == PATHSTR("realesr-animevideov3")) +- { +- sprintf(parampath, "%s/%s-x%s.param", model.c_str(), modelname.c_str(), std::to_string(scale).c_str()); +- sprintf(modelpath, "%s/%s-x%s.bin", model.c_str(), modelname.c_str(), std::to_string(scale).c_str()); +- } +- else{ +- sprintf(parampath, "%s/%s.param", model.c_str(), modelname.c_str()); +- sprintf(modelpath, "%s/%s.bin", model.c_str(), modelname.c_str()); +- } ++ path_t parampath = model + ".param"; ++ path_t modelpath = model + ".bin"; + #endif + +- path_t paramfullpath = sanitize_filepath(parampath); +- path_t modelfullpath = sanitize_filepath(modelpath); +- + #if _WIN32 + CoInitializeEx(NULL, COINIT_MULTITHREADED); + #endif +@@ -781,17 +729,14 @@ int main(int argc, char** argv) + uint32_t heap_budget = ncnn::get_gpu_device(gpuid[i])->get_heap_budget(); + + // more fine-grained tilesize policy here +- if (model.find(PATHSTR("models")) != path_t::npos) +- { +- if (heap_budget > 1900) +- tilesize[i] = 200; +- else if (heap_budget > 550) +- tilesize[i] = 100; +- else if (heap_budget > 190) +- tilesize[i] = 64; +- else +- tilesize[i] = 32; +- } ++ if (heap_budget > 1900) ++ tilesize[i] = 200; ++ else if (heap_budget > 550) ++ tilesize[i] = 100; ++ else if (heap_budget > 190) ++ tilesize[i] = 64; ++ else ++ tilesize[i] = 32; + } + + { +@@ -801,7 +746,7 @@ int main(int argc, char** argv) + { + realesrgan[i] = new RealESRGAN(gpuid[i], tta_mode); + +- realesrgan[i]->load(paramfullpath, modelfullpath); ++ realesrgan[i]->load(parampath, modelpath); + + realesrgan[i]->scale = scale; + realesrgan[i]->tilesize = tilesize[i]; -- 2.38.1