Skip to content
This repository has been archived by the owner on Jul 20, 2022. It is now read-only.

Commit

Permalink
Merge pull request #2 from ArchieMeng/upstream
Browse files Browse the repository at this point in the history
update to waifu2x-ncnn-vulkan 20210210 version
  • Loading branch information
ArchieMeng authored Feb 10, 2021
2 parents 27854e2 + c6d4834 commit 5f0aa53
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 8 deletions.
49 changes: 42 additions & 7 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ static void print_usage()
fprintf(stdout, " -i input-path input image path (jpg/png/webp) or directory\n");
fprintf(stdout, " -o output-path output image path (jpg/png/webp) or directory\n");
fprintf(stdout, " -n noise-level denoise level (-1/0/1/2/3, default=0)\n");
fprintf(stdout, " -s scale upscale ratio (1/2, default=2)\n");
fprintf(stdout, " -s scale upscale ratio (1/2/4/8/16/32, default=2)\n");
fprintf(stdout, " -t tile-size tile size (>=32/0=auto, default=0) can be 0,0,0 for multi-gpu\n");
fprintf(stdout, " -m model-path waifu2x model path (default=models-cunet)\n");
fprintf(stdout, " -g gpu-id gpu device to use (-1=cpu, default=auto) can be 0,1,2 for multi-gpu\n");
Expand Down Expand Up @@ -324,7 +324,42 @@ void* proc(void* args)
if (v.id == -233)
break;

waifu2x->process(v.inimage, v.outimage);
const int scale = v.outimage.w / v.inimage.w;
int scale_run_count = 0;
if (scale == 1 || scale == 2)
{
scale_run_count = 1;
}
if (scale == 4)
{
scale_run_count = 2;
}
if (scale == 8)
{
scale_run_count = 3;
}
if (scale == 16)
{
scale_run_count = 4;
}
if (scale == 32)
{
scale_run_count = 5;
}

for (int i = 0; i < scale_run_count; i++)
{
if (i == scale_run_count - 1)
{
waifu2x->process(v.inimage, v.outimage);
}
else
{
ncnn::Mat tmpimage(v.inimage.w * 2, v.inimage.h * 2, (size_t)v.inimage.elemsize, (int)v.inimage.elemsize);
waifu2x->process(v.inimage, tmpimage);
v.inimage = tmpimage;
}
}

tosave.put(v);
}
Expand Down Expand Up @@ -545,7 +580,7 @@ int main(int argc, char** argv)
return -1;
}

if (scale < 1 || scale > 2)
if (!(scale == 1 || scale == 2 || scale == 4 || scale == 8 || scale == 16 || scale == 32))
{
fprintf(stderr, "invalid scale argument\n");
return -1;
Expand Down Expand Up @@ -685,7 +720,7 @@ int main(int argc, char** argv)
{
prepadding = 28;
}
else if (scale == 2)
else if (scale == 2 || scale == 4 || scale == 8 || scale == 16 || scale == 32)
{
prepadding = 18;
}
Expand Down Expand Up @@ -717,7 +752,7 @@ int main(int argc, char** argv)
swprintf(parampath, 256, L"%s/noise%d_model.param", model.c_str(), noise);
swprintf(modelpath, 256, L"%s/noise%d_model.bin", model.c_str(), noise);
}
else if (scale == 2)
else if (scale == 2 || scale == 4 || scale == 8 || scale == 16 || scale == 32)
{
swprintf(parampath, 256, L"%s/noise%d_scale2.0x_model.param", model.c_str(), noise);
swprintf(modelpath, 256, L"%s/noise%d_scale2.0x_model.bin", model.c_str(), noise);
Expand All @@ -735,7 +770,7 @@ int main(int argc, char** argv)
sprintf(parampath, "%s/noise%d_model.param", model.c_str(), noise);
sprintf(modelpath, "%s/noise%d_model.bin", model.c_str(), noise);
}
else if (scale == 2)
else if (scale == 2 || scale == 4 || scale == 8 || scale == 16 || scale == 32)
{
sprintf(parampath, "%s/noise%d_scale2.0x_model.param", model.c_str(), noise);
sprintf(modelpath, "%s/noise%d_scale2.0x_model.bin", model.c_str(), noise);
Expand Down Expand Up @@ -852,7 +887,7 @@ int main(int argc, char** argv)
waifu2x[i]->load(paramfullpath, modelfullpath);

waifu2x[i]->noise = noise;
waifu2x[i]->scale = scale;
waifu2x[i]->scale = (scale >= 2) ? 2 : scale;
waifu2x[i]->tilesize = tilesize[i];
waifu2x[i]->prepadding = prepadding;
}
Expand Down
2 changes: 1 addition & 1 deletion src/ncnn
Submodule ncnn updated 198 files

0 comments on commit 5f0aa53

Please sign in to comment.