Skip to content

Commit

Permalink
Merge pull request #55 from TNTwise/master
Browse files Browse the repository at this point in the history
Fix padding and add 4.26
  • Loading branch information
styler00dollar authored Sep 22, 2024
2 parents 98c4c09 + cafc65e commit 7084311
Show file tree
Hide file tree
Showing 8 changed files with 427 additions and 17 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,13 @@ By default models are exported with ensemble=False and Fast=True
- 66 = rife-v4.24 (ensemble=False)
- 67 = rife-v4.24 (ensemble=True)
- 68 = rife-v4.25 (ensemble=False)
- 69 = rife-v4.26 (ensemble=False)

## My experimental custom models (only works with 2x)

- 69 = sudo_rife4 (ensemble=False / fast=True)
- 70 = sudo_rife4 (ensemble=True / fast=False)
- 71 = sudo_rife4 (ensemble=True / fast=True)
- 70 = sudo_rife4 (ensemble=False / fast=True)
- 71 = sudo_rife4 (ensemble=True / fast=False)
- 72 = sudo_rife4 (ensemble=True / fast=True)

- factor_num, factor_den: Factor of target frame rate. For example `factor_num=5, factor_den=2` will multiply input clip FPS by 2.5. Only rife-v4 model supports custom frame rate.

Expand Down
23 changes: 16 additions & 7 deletions RIFE/plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,8 @@ static void VS_CC rifeCreate(const VSMap* in, VSMap* out, [[maybe_unused]] void*
if (err)
d->skipThreshold = 60.0;

if (model < 0 || model > 71)
throw "model must be between 0 and 71 (inclusive)";
if (model < 0 || model > 72)
throw "model must be between 0 and 72 (inclusive)";

if (factorNum < 1)
throw "factor_num must be at least 1";
Expand Down Expand Up @@ -278,7 +278,8 @@ static void VS_CC rifeCreate(const VSMap* in, VSMap* out, [[maybe_unused]] void*
ncnn::destroy_gpu_instance();
return;
}

bool extra_padding{};
extra_padding = false;
if (modelPath.empty()) {
std::string pluginPath{ vsapi->getPluginPath(vsapi->getPluginByID("com.holywu.rife", core)) };
modelPath = pluginPath.substr(0, pluginPath.rfind('/')) + "/models";
Expand Down Expand Up @@ -493,12 +494,15 @@ static void VS_CC rifeCreate(const VSMap* in, VSMap* out, [[maybe_unused]] void*
modelPath += "/rife-v4.25_ensembleFalse";
break;
case 69:
modelPath += "/sudo_rife4_ensembleFalse_fastTrue";
modelPath += "/rife-v4.26_ensembleFalse";
break;
case 70:
modelPath += "/sudo_rife4_ensembleTrue_fastFalse";
modelPath += "/sudo_rife4_ensembleFalse_fastTrue";
break;
case 71:
modelPath += "/sudo_rife4_ensembleTrue_fastFalse";
break;
case 72:
modelPath += "/sudo_rife4_ensembleTrue_fastTrue";
break;

Expand All @@ -512,7 +516,7 @@ static void VS_CC rifeCreate(const VSMap* in, VSMap* out, [[maybe_unused]] void*

bool rife_v2{};
bool rife_v4{};

if (modelPath.find("rife-v2") != std::string::npos)
rife_v2 = true;
else if (modelPath.find("rife-v3.9") != std::string::npos)
Expand All @@ -524,6 +528,11 @@ static void VS_CC rifeCreate(const VSMap* in, VSMap* out, [[maybe_unused]] void*
rife_v4 = true;
else if (modelPath.find("rife4") != std::string::npos)
rife_v4 = true;
// rife 4.25 and 4.26 require more padding due to extra scales.
if (modelPath.find("rifev4.25") != std::string::npos)
extra_padding = true;
if (modelPath.find("rifev4.26") != std::string::npos)
extra_padding = true;
else if (modelPath.find("rife") == std::string::npos)
throw "unknown model dir type";

Expand Down Expand Up @@ -614,7 +623,7 @@ static void VS_CC rifeCreate(const VSMap* in, VSMap* out, [[maybe_unused]] void*
vsapi->freeMap(ret);
}

d->rife = std::make_unique<RIFE>(gpuId, tta, uhd, 1, rife_v2, rife_v4);
d->rife = std::make_unique<RIFE>(gpuId, tta, uhd, 1, rife_v2, rife_v4, extra_padding);

#ifdef _WIN32
auto bufferSize{ MultiByteToWideChar(CP_UTF8, 0, modelPath.c_str(), -1, nullptr, 0) };
Expand Down
15 changes: 10 additions & 5 deletions RIFE/rife.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

DEFINE_LAYER_CREATOR(Warp)

RIFE::RIFE(int gpuid, bool _tta_mode, bool _uhd_mode, int _num_threads, bool _rife_v2, bool _rife_v4)
RIFE::RIFE(int gpuid, bool _tta_mode, bool _uhd_mode, int _num_threads, bool _rife_v2, bool _rife_v4, bool _extra_padding)
{
vkdev = gpuid == -1 ? 0 : ncnn::get_gpu_device(gpuid);

Expand All @@ -41,6 +41,7 @@ RIFE::RIFE(int gpuid, bool _tta_mode, bool _uhd_mode, int _num_threads, bool _ri
num_threads = _num_threads;
rife_v2 = _rife_v2;
rife_v4 = _rife_v4;
extra_padding = _extra_padding;
}

RIFE::~RIFE()
Expand Down Expand Up @@ -1177,10 +1178,14 @@ int RIFE::process_v4(const float* src0R, const float* src0G, const float* src0B,
opt.blob_vkallocator = blob_vkallocator;
opt.workspace_vkallocator = blob_vkallocator;
opt.staging_vkallocator = staging_vkallocator;

// pad to 32n
int w_padded = (w + 31) / 32 * 32;
int h_padded = (h + 31) / 32 * 32;
int w_padded, h_padded;
if (extra_padding) {
w_padded = (w + 63) / 64 * 64;
h_padded = (h + 63) / 64 * 64;
} else {
w_padded = (w + 31) / 32 * 32;
h_padded = (h + 31) / 32 * 32;
}

const size_t in_out_tile_elemsize = opt.use_fp16_storage ? 2u : 4u;

Expand Down
3 changes: 2 additions & 1 deletion RIFE/rife.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
class RIFE
{
public:
RIFE(int gpuid, bool tta_mode = false, bool uhd_mode = false, int num_threads = 1, bool rife_v2 = false, bool rife_v4 = false);
RIFE(int gpuid, bool tta_mode = false, bool uhd_mode = false, int num_threads = 1, bool rife_v2 = false, bool rife_v4 = false, bool extra_padding = false);
~RIFE();

#if _WIN32
Expand Down Expand Up @@ -51,6 +51,7 @@ class RIFE
int num_threads;
bool rife_v2;
bool rife_v4;
bool extra_padding;
};

#endif // RIFE_H
2 changes: 2 additions & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ else
opt_var.add_cmake_defines({'NCNN_AVX512': false})
opt_var.add_cmake_defines({'NCNN_AVX512VNNI': false})
opt_var.add_cmake_defines({'NCNN_XOP': false})
opt_var.add_cmake_defines({'NCNN_DISABLE_RTTI': false})
opt_var.add_cmake_defines({'NCNN_DISABLE_EXCEPTION': false})

opt_var.add_cmake_defines({'WITH_LAYER_absval': false})
opt_var.add_cmake_defines({'WITH_LAYER_argmax': false})
Expand Down
Binary file added models/rife-v4.26_ensembleFalse/flownet.bin
Binary file not shown.
Loading

0 comments on commit 7084311

Please sign in to comment.