Skip to content

Commit

Permalink
Fix MacOS, Adjust extra padding to int, Add rife-4.25-lite (#56)
Browse files Browse the repository at this point in the history
  • Loading branch information
TNTwise authored Oct 28, 2024
1 parent 7084311 commit 895c5aa
Show file tree
Hide file tree
Showing 8 changed files with 424 additions and 30 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ jobs:
ninja -C build
macOS:
runs-on: macos-12
runs-on: macos-13

env:
CC: /usr/local/opt/llvm/bin/clang
Expand All @@ -86,7 +86,7 @@ jobs:
brew install libomp
brew install llvm
brew install llvm@15
brew install automake ninja pkg-config molten-vk vulkan-headers ncnn
- name: Setup Python
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ jobs:

macOS64:
needs: [setup, create-release]
runs-on: macos-12
runs-on: macos-13

env:
CC: /usr/local/opt/llvm/bin/clang
Expand Down
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ By default models are exported with ensemble=False and Fast=True
- 34 = rife-v4.11 (ensemble=True)
- 35 = rife-v4.12 (ensemble=False)
- 36 = rife-v4.12 (ensemble=True)
- 37 = rife-v4.12-light (ensemble=False)
- 38 = rife-v4.12-light (ensemble=True)
- 37 = rife-v4.12-lite (ensemble=False)
- 38 = rife-v4.12-lite (ensemble=True)
- 39 = rife-v4.13 (ensemble=False)
- 40 = rife-v4.13 (ensemble=True)
- 41 = rife-v4.13-lite (ensemble=False)
Expand Down Expand Up @@ -89,13 +89,14 @@ 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)
- 69 = rife-v4.25-lite (ensemble=False)
- 70 = rife-v4.26 (ensemble=False)

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

- 70 = sudo_rife4 (ensemble=False / fast=True)
- 71 = sudo_rife4 (ensemble=True / fast=False)
- 72 = sudo_rife4 (ensemble=True / fast=True)
- 71 = sudo_rife4 (ensemble=False / fast=True)
- 72 = sudo_rife4 (ensemble=True / fast=False)
- 73 = 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
25 changes: 15 additions & 10 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 > 72)
throw "model must be between 0 and 72 (inclusive)";
if (model < 0 || model > 73)
throw "model must be between 0 and 73 (inclusive)";

if (factorNum < 1)
throw "factor_num must be at least 1";
Expand Down Expand Up @@ -278,8 +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;
int padding;
padding = 32;
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 @@ -494,15 +494,18 @@ static void VS_CC rifeCreate(const VSMap* in, VSMap* out, [[maybe_unused]] void*
modelPath += "/rife-v4.25_ensembleFalse";
break;
case 69:
modelPath += "/rife-v4.26_ensembleFalse";
modelPath += "/rife-v4.25-lite_ensembleFalse";
break;
case 70:
modelPath += "/sudo_rife4_ensembleFalse_fastTrue";
modelPath += "/rife-v4.26_ensembleFalse";
break;
case 71:
modelPath += "/sudo_rife4_ensembleTrue_fastFalse";
modelPath += "/sudo_rife4_ensembleFalse_fastTrue";
break;
case 72:
modelPath += "/sudo_rife4_ensembleTrue_fastFalse";
break;
case 73:
modelPath += "/sudo_rife4_ensembleTrue_fastTrue";
break;

Expand Down Expand Up @@ -530,9 +533,11 @@ static void VS_CC rifeCreate(const VSMap* in, VSMap* out, [[maybe_unused]] void*
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;
padding = 64;
if (modelPath.find("rifev4.25-lite") != std::string::npos)
padding = 128;
if (modelPath.find("rifev4.26") != std::string::npos)
extra_padding = true;
padding = 64;
else if (modelPath.find("rife") == std::string::npos)
throw "unknown model dir type";

Expand Down Expand Up @@ -623,7 +628,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, extra_padding);
d->rife = std::make_unique<RIFE>(gpuId, tta, uhd, 1, rife_v2, rife_v4, padding);

#ifdef _WIN32
auto bufferSize{ MultiByteToWideChar(CP_UTF8, 0, modelPath.c_str(), -1, nullptr, 0) };
Expand Down
15 changes: 6 additions & 9 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, bool _extra_padding)
RIFE::RIFE(int gpuid, bool _tta_mode, bool _uhd_mode, int _num_threads, bool _rife_v2, bool _rife_v4, int _padding)
{
vkdev = gpuid == -1 ? 0 : ncnn::get_gpu_device(gpuid);

Expand All @@ -41,7 +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;
padding = _padding;
}

RIFE::~RIFE()
Expand Down Expand Up @@ -1178,14 +1178,11 @@ 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;
// padding, the default is 32, but newer rife models require 64
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;
}
w_padded = (w + padding - 1) / padding * padding;
h_padded = (h + padding - 1) / padding * padding;


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

Expand Down
4 changes: 2 additions & 2 deletions 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, bool extra_padding = false);
RIFE(int gpuid, bool tta_mode = false, bool uhd_mode = false, int num_threads = 1, bool rife_v2 = false, bool rife_v4 = false, int padding = 32);
~RIFE();

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

#endif // RIFE_H
Binary file added models/rife-v4.25-lite_ensembleFalse/flownet.bin
Binary file not shown.
Loading

0 comments on commit 895c5aa

Please sign in to comment.