Skip to content

Commit

Permalink
Merge pull request #3 from nikhiljangra264/main
Browse files Browse the repository at this point in the history
Synching with main branch
  • Loading branch information
nikhiljangra264 authored Oct 19, 2024
2 parents f686b8c + ead0e5e commit 72e8439
Show file tree
Hide file tree
Showing 22 changed files with 623 additions and 42 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-mediaprocessor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
- name: Install Dependencies
run: |
sudo apt update
sudo apt install -y ffmpeg cmake nlohmann-json3-dev
sudo apt install -y ffmpeg cmake nlohmann-json3-dev libsndfile1-dev
- name: Compile MediaProcessor
run: |
Expand Down
5 changes: 3 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ FROM python:3.10-slim

ENV DEBIAN_FRONTEND=noninteractive

# Install dependencies (little heavy as FFmpeg devlibs are required)
# Install dependencies (including FFmpeg and libsndfile)
RUN apt-get update && \
apt-get install -y build-essential cmake ffmpeg wget pkg-config \
libavcodec-dev libavformat-dev libavfilter-dev libavdevice-dev libswscale-dev && \
libavcodec-dev libavformat-dev libavfilter-dev \
libavdevice-dev libswscale-dev libsndfile-dev && \
apt-get clean

# pkg manager doesn't find this?
Expand Down
17 changes: 16 additions & 1 deletion MediaProcessor/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,24 @@ if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release)
endif()

set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O2")

# Testing build are off by default. can be turned on using cmake -DBUILD_TESTING=ON
option(BUILD_TESTING "Build the tests" OFF)

include(CTest)
# Add subdirectories for source and tests
include_directories(${CMAKE_SOURCE_DIR}/include)

# Threads is required
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)

# SNDFILE: for read/write of sampled audio files
# https://github.com/libsndfile/libsndfile
find_package(PkgConfig REQUIRED)
pkg_check_modules(SNDFILE REQUIRED sndfile)
include_directories(${SNDFILE_INCLUDE_DIRS})

# Add subdirectories for source files and gtest
add_subdirectory(src)
add_subdirectory(tests)
111 changes: 111 additions & 0 deletions MediaProcessor/include/ThreadPool.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
// Licensed under the zlib License. See full license at the bottom of this file.

#ifndef THREAD_POOL_H
#define THREAD_POOL_H

#include <condition_variable>
#include <functional>
#include <future>
#include <memory>
#include <mutex>
#include <queue>
#include <stdexcept>
#include <thread>
#include <vector>

class ThreadPool {
public:
ThreadPool(size_t);
template <class F, class... Args>
auto enqueue(F&& f, Args&&... args) -> std::future<typename std::result_of<F(Args...)>::type>;
~ThreadPool();

private:
// need to keep track of threads so we can join them
std::vector<std::thread> workers;
// the task queue
std::queue<std::function<void()> > tasks;

// synchronization
std::mutex queue_mutex;
std::condition_variable condition;
bool stop;
};

// the constructor just launches some amount of workers
inline ThreadPool::ThreadPool(size_t threads) : stop(false) {
for (size_t i = 0; i < threads; ++i)
workers.emplace_back([this] {
for (;;) {
std::function<void()> task;

{
std::unique_lock<std::mutex> lock(this->queue_mutex);
this->condition.wait(lock,
[this] { return this->stop || !this->tasks.empty(); });
if (this->stop && this->tasks.empty()) return;
task = std::move(this->tasks.front());
this->tasks.pop();
}

task();
}
});
}

// add new work item to the pool
template <class F, class... Args>
auto ThreadPool::enqueue(F&& f,
Args&&... args) -> std::future<typename std::result_of<F(Args...)>::type> {
using return_type = typename std::result_of<F(Args...)>::type;

auto task = std::make_shared<std::packaged_task<return_type()> >(
std::bind(std::forward<F>(f), std::forward<Args>(args)...));

std::future<return_type> res = task->get_future();
{
std::unique_lock<std::mutex> lock(queue_mutex);

// don't allow enqueueing after stopping the pool
if (stop) throw std::runtime_error("enqueue on stopped ThreadPool");

tasks.emplace([task]() { (*task)(); });
}
condition.notify_one();
return res;
}

// the destructor joins all threads
inline ThreadPool::~ThreadPool() {
{
std::unique_lock<std::mutex> lock(queue_mutex);
stop = true;
}
condition.notify_all();
for (std::thread& worker : workers) worker.join();
}

#endif

/*
Copyright (c) 2012 Jakob Progsch, Václav Zeman
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
*/
Binary file added MediaProcessor/lib/libdf.so
Binary file not shown.
Binary file added MediaProcessor/res/DeepFilterNet3_ll_onnx.tar.gz
Binary file not shown.
125 changes: 125 additions & 0 deletions MediaProcessor/res/DeepFilterNet3_ll_onnx/tmp/export/config.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
[train]
seed = 43
device =
model = deepfilternet3
jit = false
mask_only = false
df_only = false
batch_size = 64
batch_size_eval = 64
num_workers = 16
max_sample_len_s = 3.0
p_atten_lim = 0.0
overfit = false
max_epochs = 120
log_freq = 100
log_timings = False
validation_criteria = loss
validation_criteria_rule = min
early_stopping_patience = 25
global_ds_sampling_f = 1
num_prefetch_batches = 8
dataloader_snrs = -5,0,5,10,20,40
detect_anomaly = false
batch_size_scheduling = 0/8,1/16,2/24,5/32,10/64,20/128,40/9999
start_eval = false
validation_set_caching = false
cp_blacklist =
n_checkpoint_history = 10
n_best_checkpoint_history = 10

[distortion]
p_reverb = 0.15
p_bandwidth_ext = 0.0
p_clipping = 0.05
p_zeroing = 0.05
p_air_absorption = 0.0
p_interfer_sp = 0.01

[df]
sr = 48000
fft_size = 960
hop_size = 480
nb_erb = 32
nb_df = 96
norm_tau = 1
lsnr_max = 35
lsnr_min = -15
min_nb_erb_freqs = 2
pad_mode = output
df_order = 5
df_lookahead = 0

[deepfilternet]
conv_lookahead = 0
conv_ch = 64
conv_depthwise = True
emb_hidden_dim = 512
emb_num_layers = 3
enc_linear_groups = 16
linear_groups = 16
conv_dec_mode = transposed
convt_depthwise = True
mask_pf = False
df_hidden_dim = 512
df_num_layers = 3
dfop_method = df
group_shuffle = False
conv_kernel = 2,3
df_gru_skip = groupedlinear
df_pathway_kernel_size_t = 5
enc_concat = False
conv_kernel_inp = 3,3
emb_gru_skip = none
df_n_iter = 1
lsnr_dropout = False

[localsnrloss]
factor = 1e-3

[maskloss]
factor = 0.3
mask = spec
gamma = 0.3
gamma_pred = 0.3
f_under = 1.0

[spectralloss]
factor_magnitude = 0
factor_complex = 0
gamma = 0.3
factor_under = 1

[dfalphaloss]
factor = 0.0

[multiresspecloss]
factor = 700
factor_complex = 300
gamma = 0.3
fft_sizes = 1024,2048,3072

[optim]
lr = 0.001
momentum = 0
weight_decay = 1e-12
weight_decay_end = 0.01
optimizer = adamw
lr_min = 1e-06
lr_warmup = 0.0001
warmup_epochs = 3
lr_cycle_mul = 1.0
lr_cycle_decay = 0.5
lr_cycle_limit = 1
lr_update_per_epoch = False
lr_cycle_epochs = -1

[sdrloss]
factor = 0.0
segmental_ws = 0

[asrloss]
factor = 0.0
factor_lm = 0.0
loss_lm = CrossEntropy

Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading

0 comments on commit 72e8439

Please sign in to comment.