unofficial mirror of guix-patches@gnu.org 
 help / color / mirror / code / Atom feed
blob 9a02269718badecc4c121ae7b3c9f30e05fa1385 6798 bytes (raw)
name: gnu/packages/patches/real-resgan-ncnn-simplify-model-path.patch 	 # note: path name is non-authoritative(*)

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
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<int> tilesize;
-    path_t model = PATHSTR("models");
-    path_t modelname = PATHSTR("realesr-animevideov3");
+    path_t model = PATHSTR("");
     std::vector<int> gpuid;
     int jobs_load = 1;
     std::vector<int> 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];

debug log:

solving 9a02269718 ...
found 9a02269718 in https://yhetil.org/guix-patches/3823ee69ed8ec08192f0c2ebc26fe8b3d399b381.camel@gmail.com/

applying [1/1] https://yhetil.org/guix-patches/3823ee69ed8ec08192f0c2ebc26fe8b3d399b381.camel@gmail.com/
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

1:90: trailing whitespace.
 
1:103: trailing whitespace.
 
1:117: trailing whitespace.
 
1:127: trailing whitespace.
 
1:160: trailing whitespace.
 
Checking patch gnu/packages/patches/real-resgan-ncnn-simplify-model-path.patch...
Applied patch gnu/packages/patches/real-resgan-ncnn-simplify-model-path.patch cleanly.
warning: squelched 4 whitespace errors
warning: 9 lines add whitespace errors.

index at:
100644 9a02269718badecc4c121ae7b3c9f30e05fa1385	gnu/packages/patches/real-resgan-ncnn-simplify-model-path.patch

(*) Git path names are given by the tree(s) the blob belongs to.
    Blobs themselves have no identifier aside from the hash of its contents.^

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/guix.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).