From a5ffa496793dc7c96ea3b1f9852381837e98e3bf Mon Sep 17 00:00:00 2001 From: Oli Larkin Date: Wed, 27 Dec 2023 11:45:08 +0100 Subject: [PATCH 001/133] Pass in const reference to weights And const_iterator rather than iterator --- NAM/convnet.cpp | 8 ++++---- NAM/convnet.h | 6 +++--- NAM/dsp.cpp | 6 +++--- NAM/dsp.h | 6 +++--- NAM/lstm.cpp | 6 +++--- NAM/lstm.h | 4 ++-- NAM/wavenet.cpp | 12 ++++++------ NAM/wavenet.h | 10 +++++----- 8 files changed, 29 insertions(+), 29 deletions(-) diff --git a/NAM/convnet.cpp b/NAM/convnet.cpp index 1d4e3ba..bc0a392 100644 --- a/NAM/convnet.cpp +++ b/NAM/convnet.cpp @@ -10,7 +10,7 @@ #include "dsp.h" #include "convnet.h" -nam::convnet::BatchNorm::BatchNorm(const int dim, std::vector::iterator& weights) +nam::convnet::BatchNorm::BatchNorm(const int dim, std::vector::const_iterator& weights) { // Extract from param buffer Eigen::VectorXf running_mean(dim); @@ -48,7 +48,7 @@ void nam::convnet::BatchNorm::process_(Eigen::MatrixXf& x, const long i_start, c void nam::convnet::ConvNetBlock::set_weights_(const int in_channels, const int out_channels, const int _dilation, const bool batchnorm, const std::string activation, - std::vector::iterator& weights) + std::vector::const_iterator& weights) { this->_batchnorm = batchnorm; // HACK 2 kernel @@ -74,7 +74,7 @@ long nam::convnet::ConvNetBlock::get_out_channels() const return this->conv.get_out_channels(); } -nam::convnet::_Head::_Head(const int channels, std::vector::iterator& weights) +nam::convnet::_Head::_Head(const int channels, std::vector::const_iterator& weights) { this->_weight.resize(channels); for (int i = 0; i < channels; i++) @@ -98,7 +98,7 @@ nam::convnet::ConvNet::ConvNet(const int channels, const std::vector& dilat { this->_verify_weights(channels, dilations, batchnorm, weights.size()); this->_blocks.resize(dilations.size()); - std::vector::iterator it = weights.begin(); + std::vector::const_iterator it = weights.begin(); for (size_t i = 0; i < dilations.size(); i++) this->_blocks[i].set_weights_(i == 0 ? 1 : channels, channels, dilations[i], batchnorm, activation, it); this->_block_vals.resize(this->_blocks.size() + 1); diff --git a/NAM/convnet.h b/NAM/convnet.h index 310a1e5..a410506 100644 --- a/NAM/convnet.h +++ b/NAM/convnet.h @@ -23,7 +23,7 @@ class BatchNorm { public: BatchNorm(){}; - BatchNorm(const int dim, std::vector::iterator& weights); + BatchNorm(const int dim, std::vector::const_iterator& weights); void process_(Eigen::MatrixXf& input, const long i_start, const long i_end) const; private: @@ -41,7 +41,7 @@ class ConvNetBlock public: ConvNetBlock(){}; void set_weights_(const int in_channels, const int out_channels, const int _dilation, const bool batchnorm, - const std::string activation, std::vector::iterator& weights); + const std::string activation, std::vector::const_iterator& weights); void process_(const Eigen::MatrixXf& input, Eigen::MatrixXf& output, const long i_start, const long i_end) const; long get_out_channels() const; Conv1D conv; @@ -56,7 +56,7 @@ class _Head { public: _Head(){}; - _Head(const int channels, std::vector::iterator& weights); + _Head(const int channels, std::vector::const_iterator& weights); void process_(const Eigen::MatrixXf& input, Eigen::VectorXf& output, const long i_start, const long i_end) const; private: diff --git a/NAM/dsp.cpp b/NAM/dsp.cpp index d068eed..68f5f37 100644 --- a/NAM/dsp.cpp +++ b/NAM/dsp.cpp @@ -167,7 +167,7 @@ void nam::Linear::process(NAM_SAMPLE* input, NAM_SAMPLE* output, const int num_f // NN modules ================================================================= -void nam::Conv1D::set_weights_(std::vector::iterator& weights) +void nam::Conv1D::set_weights_(std::vector::const_iterator& weights) { if (this->_weight.size() > 0) { @@ -198,7 +198,7 @@ void nam::Conv1D::set_size_(const int in_channels, const int out_channels, const } void nam::Conv1D::set_size_and_weights_(const int in_channels, const int out_channels, const int kernel_size, - const int _dilation, const bool do_bias, std::vector::iterator& weights) + const int _dilation, const bool do_bias, std::vector::const_iterator& weights) { this->set_size_(in_channels, out_channels, kernel_size, do_bias, _dilation); this->set_weights_(weights); @@ -236,7 +236,7 @@ nam::Conv1x1::Conv1x1(const int in_channels, const int out_channels, const bool this->_bias.resize(out_channels); } -void nam::Conv1x1::set_weights_(std::vector::iterator& weights) +void nam::Conv1x1::set_weights_(std::vector::const_iterator& weights) { for (int i = 0; i < this->_weight.rows(); i++) for (int j = 0; j < this->_weight.cols(); j++) diff --git a/NAM/dsp.h b/NAM/dsp.h index c3e8ec9..737d6c3 100644 --- a/NAM/dsp.h +++ b/NAM/dsp.h @@ -124,11 +124,11 @@ class Conv1D { public: Conv1D() { this->_dilation = 1; }; - void set_weights_(std::vector::iterator& weights); + void set_weights_(std::vector::const_iterator& weights); void set_size_(const int in_channels, const int out_channels, const int kernel_size, const bool do_bias, const int _dilation); void set_size_and_weights_(const int in_channels, const int out_channels, const int kernel_size, const int _dilation, - const bool do_bias, std::vector::iterator& weights); + const bool do_bias, std::vector::const_iterator& weights); // Process from input to output // Rightmost indices of input go from i_start to i_end, // Indices on output for from j_start (to j_start + i_end - i_start) @@ -153,7 +153,7 @@ class Conv1x1 { public: Conv1x1(const int in_channels, const int out_channels, const bool _bias); - void set_weights_(std::vector::iterator& weights); + void set_weights_(std::vector::const_iterator& weights); // :param input: (N,Cin) or (Cin,) // :return: (N,Cout) or (Cout,), respectively Eigen::MatrixXf process(const Eigen::MatrixXf& input) const; diff --git a/NAM/lstm.cpp b/NAM/lstm.cpp index 38ff494..bde249f 100644 --- a/NAM/lstm.cpp +++ b/NAM/lstm.cpp @@ -4,7 +4,7 @@ #include "lstm.h" -nam::lstm::LSTMCell::LSTMCell(const int input_size, const int hidden_size, std::vector::iterator& weights) +nam::lstm::LSTMCell::LSTMCell(const int input_size, const int hidden_size, std::vector::const_iterator& weights) { // Resize arrays this->_w.resize(4 * hidden_size, input_size + hidden_size); @@ -63,12 +63,12 @@ void nam::lstm::LSTMCell::process_(const Eigen::VectorXf& x) } } -nam::lstm::LSTM::LSTM(const int num_layers, const int input_size, const int hidden_size, std::vector& weights, +nam::lstm::LSTM::LSTM(const int num_layers, const int input_size, const int hidden_size, const std::vector& weights, const double expected_sample_rate) : DSP(expected_sample_rate) { this->_input.resize(1); - std::vector::iterator it = weights.begin(); + std::vector::const_iterator it = weights.begin(); for (int i = 0; i < num_layers; i++) this->_layers.push_back(LSTMCell(i == 0 ? input_size : hidden_size, hidden_size, it)); this->_head_weight.resize(hidden_size); diff --git a/NAM/lstm.h b/NAM/lstm.h index 6b02b18..cdfada0 100644 --- a/NAM/lstm.h +++ b/NAM/lstm.h @@ -22,7 +22,7 @@ namespace lstm class LSTMCell { public: - LSTMCell(const int input_size, const int hidden_size, std::vector::iterator& weights); + LSTMCell(const int input_size, const int hidden_size, std::vector::const_iterator& weights); Eigen::VectorXf get_hidden_state() const { return this->_xh(Eigen::placeholders::lastN(this->_get_hidden_size())); }; void process_(const Eigen::VectorXf& x); @@ -50,7 +50,7 @@ class LSTMCell class LSTM : public DSP { public: - LSTM(const int num_layers, const int input_size, const int hidden_size, std::vector& weights, + LSTM(const int num_layers, const int input_size, const int hidden_size, const std::vector& weights, const double expected_sample_rate = -1.0); ~LSTM() = default; diff --git a/NAM/wavenet.cpp b/NAM/wavenet.cpp index fc96fa6..111dae0 100644 --- a/NAM/wavenet.cpp +++ b/NAM/wavenet.cpp @@ -12,7 +12,7 @@ nam::wavenet::_DilatedConv::_DilatedConv(const int in_channels, const int out_ch this->set_size_(in_channels, out_channels, kernel_size, bias, dilation); } -void nam::wavenet::_Layer::set_weights_(std::vector::iterator& weights) +void nam::wavenet::_Layer::set_weights_(std::vector::const_iterator& weights) { this->_conv.set_weights_(weights); this->_input_mixin.set_weights_(weights); @@ -133,7 +133,7 @@ void nam::wavenet::_LayerArray::set_num_frames_(const long num_frames) this->_layers[i].set_num_frames_(num_frames); } -void nam::wavenet::_LayerArray::set_weights_(std::vector::iterator& weights) +void nam::wavenet::_LayerArray::set_weights_(std::vector::const_iterator& weights) { this->_rechannel.set_weights_(weights); for (size_t i = 0; i < this->_layers.size(); i++) @@ -186,7 +186,7 @@ nam::wavenet::_Head::_Head(const int input_size, const int num_layers, const int } } -void nam::wavenet::_Head::set_weights_(std::vector::iterator& weights) +void nam::wavenet::_Head::set_weights_(std::vector::const_iterator& weights) { for (size_t i = 0; i < this->_layers.size(); i++) this->_layers[i].set_weights_(weights); @@ -231,7 +231,7 @@ void nam::wavenet::_Head::_apply_activation_(Eigen::MatrixXf& x) // WaveNet ==================================================================== nam::wavenet::WaveNet::WaveNet(const std::vector& layer_array_params, - const float head_scale, const bool with_head, std::vector weights, + const float head_scale, const bool with_head, const std::vector& weights, const double expected_sample_rate) : DSP(expected_sample_rate) , _num_frames(0) @@ -272,9 +272,9 @@ void nam::wavenet::WaveNet::finalize_(const int num_frames) this->_advance_buffers_(num_frames); } -void nam::wavenet::WaveNet::set_weights_(std::vector& weights) +void nam::wavenet::WaveNet::set_weights_(const std::vector& weights) { - std::vector::iterator it = weights.begin(); + std::vector::const_iterator it = weights.begin(); for (size_t i = 0; i < this->_layer_arrays.size(); i++) this->_layer_arrays[i].set_weights_(it); // this->_head.set_params_(it); diff --git a/NAM/wavenet.h b/NAM/wavenet.h index 7ea94f1..b4ab962 100644 --- a/NAM/wavenet.h +++ b/NAM/wavenet.h @@ -30,7 +30,7 @@ class _Layer , _1x1(channels, channels, true) , _activation(activations::Activation::get_activation(activation)) , _gated(gated){}; - void set_weights_(std::vector::iterator& weights); + void set_weights_(std::vector::const_iterator& weights); // :param `input`: from previous layer // :param `output`: to next layer void process_(const Eigen::MatrixXf& input, const Eigen::MatrixXf& condition, Eigen::MatrixXf& head_input, @@ -108,7 +108,7 @@ class _LayerArray Eigen::MatrixXf& head_outputs // post head-rechannel ); void set_num_frames_(const long num_frames); - void set_weights_(std::vector::iterator& it); + void set_weights_(std::vector::const_iterator& it); // "Zero-indexed" receptive field. // E.g. a 1x1 convolution has a z.i.r.f. of zero. @@ -144,7 +144,7 @@ class _Head { public: _Head(const int input_size, const int num_layers, const int channels, const std::string activation); - void set_weights_(std::vector::iterator& weights); + void set_weights_(std::vector::const_iterator& weights); // NOTE: the head transforms the provided input by applying a nonlinearity // to it in-place! void process_(Eigen::MatrixXf& inputs, Eigen::MatrixXf& outputs); @@ -169,11 +169,11 @@ class WaveNet : public DSP { public: WaveNet(const std::vector& layer_array_params, const float head_scale, const bool with_head, - std::vector weights, const double expected_sample_rate = -1.0); + const std::vector& weights, const double expected_sample_rate = -1.0); ~WaveNet() = default; void finalize_(const int num_frames) override; - void set_weights_(std::vector& weights); + void set_weights_(const std::vector& weights); private: long _num_frames; From 0833ea6760c70c9fde8f48c47d370d6222c8269a Mon Sep 17 00:00:00 2001 From: Oli Larkin Date: Sat, 30 Dec 2023 21:11:29 +0100 Subject: [PATCH 002/133] Introduce weights_it alias --- NAM/convnet.cpp | 8 ++++---- NAM/convnet.h | 6 +++--- NAM/dsp.cpp | 6 +++--- NAM/dsp.h | 8 +++++--- NAM/lstm.cpp | 5 +++-- NAM/lstm.h | 2 +- NAM/wavenet.cpp | 8 ++++---- NAM/wavenet.h | 6 +++--- 8 files changed, 26 insertions(+), 23 deletions(-) diff --git a/NAM/convnet.cpp b/NAM/convnet.cpp index bc0a392..937bf0b 100644 --- a/NAM/convnet.cpp +++ b/NAM/convnet.cpp @@ -10,7 +10,7 @@ #include "dsp.h" #include "convnet.h" -nam::convnet::BatchNorm::BatchNorm(const int dim, std::vector::const_iterator& weights) +nam::convnet::BatchNorm::BatchNorm(const int dim, weights_it& weights) { // Extract from param buffer Eigen::VectorXf running_mean(dim); @@ -48,7 +48,7 @@ void nam::convnet::BatchNorm::process_(Eigen::MatrixXf& x, const long i_start, c void nam::convnet::ConvNetBlock::set_weights_(const int in_channels, const int out_channels, const int _dilation, const bool batchnorm, const std::string activation, - std::vector::const_iterator& weights) + weights_it& weights) { this->_batchnorm = batchnorm; // HACK 2 kernel @@ -74,7 +74,7 @@ long nam::convnet::ConvNetBlock::get_out_channels() const return this->conv.get_out_channels(); } -nam::convnet::_Head::_Head(const int channels, std::vector::const_iterator& weights) +nam::convnet::_Head::_Head(const int channels, weights_it& weights) { this->_weight.resize(channels); for (int i = 0; i < channels; i++) @@ -98,7 +98,7 @@ nam::convnet::ConvNet::ConvNet(const int channels, const std::vector& dilat { this->_verify_weights(channels, dilations, batchnorm, weights.size()); this->_blocks.resize(dilations.size()); - std::vector::const_iterator it = weights.begin(); + weights_it it = weights.begin(); for (size_t i = 0; i < dilations.size(); i++) this->_blocks[i].set_weights_(i == 0 ? 1 : channels, channels, dilations[i], batchnorm, activation, it); this->_block_vals.resize(this->_blocks.size() + 1); diff --git a/NAM/convnet.h b/NAM/convnet.h index a410506..02af4c8 100644 --- a/NAM/convnet.h +++ b/NAM/convnet.h @@ -23,7 +23,7 @@ class BatchNorm { public: BatchNorm(){}; - BatchNorm(const int dim, std::vector::const_iterator& weights); + BatchNorm(const int dim, weights_it& weights); void process_(Eigen::MatrixXf& input, const long i_start, const long i_end) const; private: @@ -41,7 +41,7 @@ class ConvNetBlock public: ConvNetBlock(){}; void set_weights_(const int in_channels, const int out_channels, const int _dilation, const bool batchnorm, - const std::string activation, std::vector::const_iterator& weights); + const std::string activation, weights_it& weights); void process_(const Eigen::MatrixXf& input, Eigen::MatrixXf& output, const long i_start, const long i_end) const; long get_out_channels() const; Conv1D conv; @@ -56,7 +56,7 @@ class _Head { public: _Head(){}; - _Head(const int channels, std::vector::const_iterator& weights); + _Head(const int channels, weights_it& weights); void process_(const Eigen::MatrixXf& input, Eigen::VectorXf& output, const long i_start, const long i_end) const; private: diff --git a/NAM/dsp.cpp b/NAM/dsp.cpp index 68f5f37..db0730b 100644 --- a/NAM/dsp.cpp +++ b/NAM/dsp.cpp @@ -167,7 +167,7 @@ void nam::Linear::process(NAM_SAMPLE* input, NAM_SAMPLE* output, const int num_f // NN modules ================================================================= -void nam::Conv1D::set_weights_(std::vector::const_iterator& weights) +void nam::Conv1D::set_weights_(weights_it& weights) { if (this->_weight.size() > 0) { @@ -198,7 +198,7 @@ void nam::Conv1D::set_size_(const int in_channels, const int out_channels, const } void nam::Conv1D::set_size_and_weights_(const int in_channels, const int out_channels, const int kernel_size, - const int _dilation, const bool do_bias, std::vector::const_iterator& weights) + const int _dilation, const bool do_bias, weights_it& weights) { this->set_size_(in_channels, out_channels, kernel_size, do_bias, _dilation); this->set_weights_(weights); @@ -236,7 +236,7 @@ nam::Conv1x1::Conv1x1(const int in_channels, const int out_channels, const bool this->_bias.resize(out_channels); } -void nam::Conv1x1::set_weights_(std::vector::const_iterator& weights) +void nam::Conv1x1::set_weights_(weights_it& weights) { for (int i = 0; i < this->_weight.rows(); i++) for (int j = 0; j < this->_weight.cols(); j++) diff --git a/NAM/dsp.h b/NAM/dsp.h index 737d6c3..e74a153 100644 --- a/NAM/dsp.h +++ b/NAM/dsp.h @@ -23,6 +23,8 @@ namespace nam { +using weights_it = std::vector::const_iterator; + enum EArchitectures { kLinear = 0, @@ -124,11 +126,11 @@ class Conv1D { public: Conv1D() { this->_dilation = 1; }; - void set_weights_(std::vector::const_iterator& weights); + void set_weights_(weights_it& weights); void set_size_(const int in_channels, const int out_channels, const int kernel_size, const bool do_bias, const int _dilation); void set_size_and_weights_(const int in_channels, const int out_channels, const int kernel_size, const int _dilation, - const bool do_bias, std::vector::const_iterator& weights); + const bool do_bias, weights_it& weights); // Process from input to output // Rightmost indices of input go from i_start to i_end, // Indices on output for from j_start (to j_start + i_end - i_start) @@ -153,7 +155,7 @@ class Conv1x1 { public: Conv1x1(const int in_channels, const int out_channels, const bool _bias); - void set_weights_(std::vector::const_iterator& weights); + void set_weights_(weights_it& weights); // :param input: (N,Cin) or (Cin,) // :return: (N,Cout) or (Cout,), respectively Eigen::MatrixXf process(const Eigen::MatrixXf& input) const; diff --git a/NAM/lstm.cpp b/NAM/lstm.cpp index bde249f..3b55575 100644 --- a/NAM/lstm.cpp +++ b/NAM/lstm.cpp @@ -2,9 +2,10 @@ #include #include +#include "dsp.h" #include "lstm.h" -nam::lstm::LSTMCell::LSTMCell(const int input_size, const int hidden_size, std::vector::const_iterator& weights) +nam::lstm::LSTMCell::LSTMCell(const int input_size, const int hidden_size, weights_it& weights) { // Resize arrays this->_w.resize(4 * hidden_size, input_size + hidden_size); @@ -68,7 +69,7 @@ nam::lstm::LSTM::LSTM(const int num_layers, const int input_size, const int hidd : DSP(expected_sample_rate) { this->_input.resize(1); - std::vector::const_iterator it = weights.begin(); + auto it = weights.begin(); for (int i = 0; i < num_layers; i++) this->_layers.push_back(LSTMCell(i == 0 ? input_size : hidden_size, hidden_size, it)); this->_head_weight.resize(hidden_size); diff --git a/NAM/lstm.h b/NAM/lstm.h index cdfada0..a432169 100644 --- a/NAM/lstm.h +++ b/NAM/lstm.h @@ -22,7 +22,7 @@ namespace lstm class LSTMCell { public: - LSTMCell(const int input_size, const int hidden_size, std::vector::const_iterator& weights); + LSTMCell(const int input_size, const int hidden_size, weights_it& weights); Eigen::VectorXf get_hidden_state() const { return this->_xh(Eigen::placeholders::lastN(this->_get_hidden_size())); }; void process_(const Eigen::VectorXf& x); diff --git a/NAM/wavenet.cpp b/NAM/wavenet.cpp index 111dae0..42dd299 100644 --- a/NAM/wavenet.cpp +++ b/NAM/wavenet.cpp @@ -12,7 +12,7 @@ nam::wavenet::_DilatedConv::_DilatedConv(const int in_channels, const int out_ch this->set_size_(in_channels, out_channels, kernel_size, bias, dilation); } -void nam::wavenet::_Layer::set_weights_(std::vector::const_iterator& weights) +void nam::wavenet::_Layer::set_weights_(weights_it& weights) { this->_conv.set_weights_(weights); this->_input_mixin.set_weights_(weights); @@ -133,7 +133,7 @@ void nam::wavenet::_LayerArray::set_num_frames_(const long num_frames) this->_layers[i].set_num_frames_(num_frames); } -void nam::wavenet::_LayerArray::set_weights_(std::vector::const_iterator& weights) +void nam::wavenet::_LayerArray::set_weights_(weights_it& weights) { this->_rechannel.set_weights_(weights); for (size_t i = 0; i < this->_layers.size(); i++) @@ -186,7 +186,7 @@ nam::wavenet::_Head::_Head(const int input_size, const int num_layers, const int } } -void nam::wavenet::_Head::set_weights_(std::vector::const_iterator& weights) +void nam::wavenet::_Head::set_weights_(weights_it& weights) { for (size_t i = 0; i < this->_layers.size(); i++) this->_layers[i].set_weights_(weights); @@ -274,7 +274,7 @@ void nam::wavenet::WaveNet::finalize_(const int num_frames) void nam::wavenet::WaveNet::set_weights_(const std::vector& weights) { - std::vector::const_iterator it = weights.begin(); + weights_it it = weights.begin(); for (size_t i = 0; i < this->_layer_arrays.size(); i++) this->_layer_arrays[i].set_weights_(it); // this->_head.set_params_(it); diff --git a/NAM/wavenet.h b/NAM/wavenet.h index b4ab962..bd30f03 100644 --- a/NAM/wavenet.h +++ b/NAM/wavenet.h @@ -30,7 +30,7 @@ class _Layer , _1x1(channels, channels, true) , _activation(activations::Activation::get_activation(activation)) , _gated(gated){}; - void set_weights_(std::vector::const_iterator& weights); + void set_weights_(weights_it& weights); // :param `input`: from previous layer // :param `output`: to next layer void process_(const Eigen::MatrixXf& input, const Eigen::MatrixXf& condition, Eigen::MatrixXf& head_input, @@ -108,7 +108,7 @@ class _LayerArray Eigen::MatrixXf& head_outputs // post head-rechannel ); void set_num_frames_(const long num_frames); - void set_weights_(std::vector::const_iterator& it); + void set_weights_(weights_it& it); // "Zero-indexed" receptive field. // E.g. a 1x1 convolution has a z.i.r.f. of zero. @@ -144,7 +144,7 @@ class _Head { public: _Head(const int input_size, const int num_layers, const int channels, const std::string activation); - void set_weights_(std::vector::const_iterator& weights); + void set_weights_(weights_it& weights); // NOTE: the head transforms the provided input by applying a nonlinearity // to it in-place! void process_(Eigen::MatrixXf& inputs, Eigen::MatrixXf& outputs); From 78f42d048aaa9757616792427ba8cdeb712584e7 Mon Sep 17 00:00:00 2001 From: Oli Larkin Date: Sat, 30 Dec 2023 21:55:33 +0100 Subject: [PATCH 003/133] Use Eigen::Ref<> rather than normal references https://eigen.tuxfamily.org/dox/TopicFunctionTakingEigenTypes.html#TopicUsingRefClass --- NAM/activations.h | 2 +- NAM/convnet.cpp | 10 +++++----- NAM/convnet.h | 6 +++--- NAM/dsp.cpp | 8 ++++---- NAM/dsp.h | 4 ++-- NAM/lstm.cpp | 2 +- NAM/wavenet.cpp | 30 ++++++++++++++++++++---------- NAM/wavenet.h | 18 +++++++++--------- 8 files changed, 45 insertions(+), 35 deletions(-) diff --git a/NAM/activations.h b/NAM/activations.h index e9afc33..51b03d9 100644 --- a/NAM/activations.h +++ b/NAM/activations.h @@ -45,7 +45,7 @@ class Activation public: Activation() = default; virtual ~Activation() = default; - virtual void apply(Eigen::MatrixXf& matrix) { apply(matrix.data(), matrix.rows() * matrix.cols()); } + virtual void apply(Eigen::Ref matrix) { apply(matrix.data(), matrix.rows() * matrix.cols()); } virtual void apply(Eigen::Block block) { apply(block.data(), block.rows() * block.cols()); } virtual void apply(Eigen::Block block) { diff --git a/NAM/convnet.cpp b/NAM/convnet.cpp index 937bf0b..1122871 100644 --- a/NAM/convnet.cpp +++ b/NAM/convnet.cpp @@ -35,7 +35,7 @@ nam::convnet::BatchNorm::BatchNorm(const int dim, weights_it& weights) this->loc = _bias - this->scale.cwiseProduct(running_mean); } -void nam::convnet::BatchNorm::process_(Eigen::MatrixXf& x, const long i_start, const long i_end) const +void nam::convnet::BatchNorm::process_(Eigen::Ref x, const long i_start, const long i_end) const { // todo using colwise? // #speed but conv probably dominates @@ -58,7 +58,7 @@ void nam::convnet::ConvNetBlock::set_weights_(const int in_channels, const int o this->activation = activations::Activation::get_activation(activation); } -void nam::convnet::ConvNetBlock::process_(const Eigen::MatrixXf& input, Eigen::MatrixXf& output, const long i_start, +void nam::convnet::ConvNetBlock::process_(const Eigen::Ref input, Eigen::Ref output, const long i_start, const long i_end) const { const long ncols = i_end - i_start; @@ -82,7 +82,7 @@ nam::convnet::_Head::_Head(const int channels, weights_it& weights) this->_bias = *(weights++); } -void nam::convnet::_Head::process_(const Eigen::MatrixXf& input, Eigen::VectorXf& output, const long i_start, +void nam::convnet::_Head::process_(const Eigen::Ref input, Eigen::VectorXf& output, const long i_start, const long i_end) const { const long length = i_end - i_start; @@ -146,7 +146,7 @@ void nam::convnet::ConvNet::_update_buffers_(NAM_SAMPLE* input, const int num_fr const size_t buffer_size = this->_input_buffer.size(); - if (this->_block_vals[0].rows() != 1 || this->_block_vals[0].cols() != buffer_size) + if (this->_block_vals[0].rows() != Eigen::Index(1) || this->_block_vals[0].cols() != Eigen::Index(buffer_size)) { this->_block_vals[0].resize(1, buffer_size); this->_block_vals[0].setZero(); @@ -155,7 +155,7 @@ void nam::convnet::ConvNet::_update_buffers_(NAM_SAMPLE* input, const int num_fr for (size_t i = 1; i < this->_block_vals.size(); i++) { if (this->_block_vals[i].rows() == this->_blocks[i - 1].get_out_channels() - && this->_block_vals[i].cols() == buffer_size) + && this->_block_vals[i].cols() == Eigen::Index(buffer_size)) continue; // Already has correct size this->_block_vals[i].resize(this->_blocks[i - 1].get_out_channels(), buffer_size); this->_block_vals[i].setZero(); diff --git a/NAM/convnet.h b/NAM/convnet.h index 02af4c8..a117b43 100644 --- a/NAM/convnet.h +++ b/NAM/convnet.h @@ -24,7 +24,7 @@ class BatchNorm public: BatchNorm(){}; BatchNorm(const int dim, weights_it& weights); - void process_(Eigen::MatrixXf& input, const long i_start, const long i_end) const; + void process_(Eigen::Ref input, const long i_start, const long i_end) const; private: // TODO simplify to just ax+b @@ -42,7 +42,7 @@ class ConvNetBlock ConvNetBlock(){}; void set_weights_(const int in_channels, const int out_channels, const int _dilation, const bool batchnorm, const std::string activation, weights_it& weights); - void process_(const Eigen::MatrixXf& input, Eigen::MatrixXf& output, const long i_start, const long i_end) const; + void process_(const Eigen::Ref input, Eigen::Ref output, const long i_start, const long i_end) const; long get_out_channels() const; Conv1D conv; @@ -57,7 +57,7 @@ class _Head public: _Head(){}; _Head(const int channels, weights_it& weights); - void process_(const Eigen::MatrixXf& input, Eigen::VectorXf& output, const long i_start, const long i_end) const; + void process_(const Eigen::Ref input, Eigen::VectorXf& output, const long i_start, const long i_end) const; private: Eigen::VectorXf _weight; diff --git a/NAM/dsp.cpp b/NAM/dsp.cpp index db0730b..9b27ec9 100644 --- a/NAM/dsp.cpp +++ b/NAM/dsp.cpp @@ -39,7 +39,7 @@ void nam::DSP::prewarm() void nam::DSP::process(NAM_SAMPLE* input, NAM_SAMPLE* output, const int num_frames) { // Default implementation is the null operation - for (size_t i = 0; i < num_frames; i++) + for (auto i = 0; i < num_frames; i++) output[i] = input[i]; } @@ -157,7 +157,7 @@ void nam::Linear::process(NAM_SAMPLE* input, NAM_SAMPLE* output, const int num_f this->nam::Buffer::_update_buffers_(input, num_frames); // Main computation! - for (size_t i = 0; i < num_frames; i++) + for (auto i = 0; i < num_frames; i++) { const size_t offset = this->_input_buffer_offset - this->_weight.size() + i + 1; auto input = Eigen::Map(&this->_input_buffer[offset], this->_receptive_field); @@ -204,7 +204,7 @@ void nam::Conv1D::set_size_and_weights_(const int in_channels, const int out_cha this->set_weights_(weights); } -void nam::Conv1D::process_(const Eigen::MatrixXf& input, Eigen::MatrixXf& output, const long i_start, const long ncols, +void nam::Conv1D::process_(const Eigen::Ref input, Eigen::Ref output, const long i_start, const long ncols, const long j_start) const { // This is the clever part ;) @@ -246,7 +246,7 @@ void nam::Conv1x1::set_weights_(weights_it& weights) this->_bias(i) = *(weights++); } -Eigen::MatrixXf nam::Conv1x1::process(const Eigen::MatrixXf& input) const +Eigen::MatrixXf nam::Conv1x1::process(const Eigen::Ref input) const { if (this->_do_bias) return (this->_weight * input).colwise() + this->_bias; diff --git a/NAM/dsp.h b/NAM/dsp.h index e74a153..118e782 100644 --- a/NAM/dsp.h +++ b/NAM/dsp.h @@ -134,7 +134,7 @@ class Conv1D // Process from input to output // Rightmost indices of input go from i_start to i_end, // Indices on output for from j_start (to j_start + i_end - i_start) - void process_(const Eigen::MatrixXf& input, Eigen::MatrixXf& output, const long i_start, const long i_end, + void process_(const Eigen::Ref input, Eigen::Ref output, const long i_start, const long i_end, const long j_start) const; long get_in_channels() const { return this->_weight.size() > 0 ? this->_weight[0].cols() : 0; }; long get_kernel_size() const { return this->_weight.size(); }; @@ -158,7 +158,7 @@ class Conv1x1 void set_weights_(weights_it& weights); // :param input: (N,Cin) or (Cin,) // :return: (N,Cout) or (Cout,), respectively - Eigen::MatrixXf process(const Eigen::MatrixXf& input) const; + Eigen::MatrixXf process(const Eigen::Ref input) const; long get_out_channels() const { return this->_weight.rows(); }; diff --git a/NAM/lstm.cpp b/NAM/lstm.cpp index 3b55575..aa0f6ad 100644 --- a/NAM/lstm.cpp +++ b/NAM/lstm.cpp @@ -81,7 +81,7 @@ nam::lstm::LSTM::LSTM(const int num_layers, const int input_size, const int hidd void nam::lstm::LSTM::process(NAM_SAMPLE* input, NAM_SAMPLE* output, const int num_frames) { - for (size_t i = 0; i < num_frames; i++) + for (auto i = 0; i < num_frames; i++) output[i] = this->_process_sample(input[i]); } diff --git a/NAM/wavenet.cpp b/NAM/wavenet.cpp index 42dd299..7899c3b 100644 --- a/NAM/wavenet.cpp +++ b/NAM/wavenet.cpp @@ -19,8 +19,8 @@ void nam::wavenet::_Layer::set_weights_(weights_it& weights) this->_1x1.set_weights_(weights); } -void nam::wavenet::_Layer::process_(const Eigen::MatrixXf& input, const Eigen::MatrixXf& condition, - Eigen::MatrixXf& head_input, Eigen::MatrixXf& output, const long i_start, +void nam::wavenet::_Layer::process_(const Eigen::Ref input, const Eigen::Ref condition, + Eigen::Ref head_input, Eigen::Ref output, const long i_start, const long j_start) { const long ncols = condition.cols(); @@ -102,17 +102,27 @@ void nam::wavenet::_LayerArray::prepare_for_frames_(const long num_frames) this->_rewind_buffers_(); } -void nam::wavenet::_LayerArray::process_(const Eigen::MatrixXf& layer_inputs, const Eigen::MatrixXf& condition, - Eigen::MatrixXf& head_inputs, Eigen::MatrixXf& layer_outputs, - Eigen::MatrixXf& head_outputs) +void nam::wavenet::_LayerArray::process_(const Eigen::Ref layer_inputs, const Eigen::Ref condition, + Eigen::Ref head_inputs, Eigen::Ref layer_outputs, + Eigen::Ref head_outputs) { this->_layer_buffers[0].middleCols(this->_buffer_start, layer_inputs.cols()) = this->_rechannel.process(layer_inputs); const size_t last_layer = this->_layers.size() - 1; for (size_t i = 0; i < this->_layers.size(); i++) { - this->_layers[i].process_(this->_layer_buffers[i], condition, head_inputs, - i == last_layer ? layer_outputs : this->_layer_buffers[i + 1], this->_buffer_start, - i == last_layer ? 0 : this->_buffer_start); + if (i == last_layer) + { + this->_layers[i].process_(this->_layer_buffers[i], condition, head_inputs, + layer_outputs, this->_buffer_start, + 0); + } + else + { + this->_layers[i].process_(this->_layer_buffers[i], condition, head_inputs, + this->_layer_buffers[i + 1], this->_buffer_start, + this->_buffer_start); + } + } head_outputs = this->_head_rechannel.process(head_inputs); } @@ -192,7 +202,7 @@ void nam::wavenet::_Head::set_weights_(weights_it& weights) this->_layers[i].set_weights_(weights); } -void nam::wavenet::_Head::process_(Eigen::MatrixXf& inputs, Eigen::MatrixXf& outputs) +void nam::wavenet::_Head::process_(Eigen::Ref inputs, Eigen::Ref outputs) { const size_t num_layers = this->_layers.size(); this->_apply_activation_(inputs); @@ -223,7 +233,7 @@ void nam::wavenet::_Head::set_num_frames_(const long num_frames) } } -void nam::wavenet::_Head::_apply_activation_(Eigen::MatrixXf& x) +void nam::wavenet::_Head::_apply_activation_(Eigen::Ref x) { this->_activation->apply(x); } diff --git a/NAM/wavenet.h b/NAM/wavenet.h index bd30f03..fbaab54 100644 --- a/NAM/wavenet.h +++ b/NAM/wavenet.h @@ -33,8 +33,8 @@ class _Layer void set_weights_(weights_it& weights); // :param `input`: from previous layer // :param `output`: to next layer - void process_(const Eigen::MatrixXf& input, const Eigen::MatrixXf& condition, Eigen::MatrixXf& head_input, - Eigen::MatrixXf& output, const long i_start, const long j_start); + void process_(const Eigen::Ref input, const Eigen::Ref condition, Eigen::Ref head_input, + Eigen::Ref output, const long i_start, const long j_start); void set_num_frames_(const long num_frames); long get_channels() const { return this->_conv.get_in_channels(); }; int get_dilation() const { return this->_conv.get_dilation(); }; @@ -101,11 +101,11 @@ class _LayerArray void prepare_for_frames_(const long num_frames); // All arrays are "short". - void process_(const Eigen::MatrixXf& layer_inputs, // Short - const Eigen::MatrixXf& condition, // Short - Eigen::MatrixXf& layer_outputs, // Short - Eigen::MatrixXf& head_inputs, // Sum up on this. - Eigen::MatrixXf& head_outputs // post head-rechannel + void process_(const Eigen::Ref layer_inputs, // Short + const Eigen::Ref condition, // Short + Eigen::Ref layer_outputs, // Short + Eigen::Ref head_inputs, // Sum up on this. + Eigen::Ref head_outputs // post head-rechannel ); void set_num_frames_(const long num_frames); void set_weights_(weights_it& it); @@ -147,7 +147,7 @@ class _Head void set_weights_(weights_it& weights); // NOTE: the head transforms the provided input by applying a nonlinearity // to it in-place! - void process_(Eigen::MatrixXf& inputs, Eigen::MatrixXf& outputs); + void process_(Eigen::Ref inputs, Eigen::Ref outputs); void set_num_frames_(const long num_frames); private: @@ -161,7 +161,7 @@ class _Head std::vector _buffers; // Apply the activation to the provided array, in-place - void _apply_activation_(Eigen::MatrixXf& x); + void _apply_activation_(Eigen::Ref x); }; // The main WaveNet model From d60bcc1c2a87e16b4bca6a1b259be4fc4e307115 Mon Sep 17 00:00:00 2001 From: Oli Larkin Date: Fri, 19 Jan 2024 23:17:49 +0100 Subject: [PATCH 004/133] Remove NAM_SAMPLE --- NAM/convnet.cpp | 4 ++-- NAM/convnet.h | 4 ++-- NAM/dsp.cpp | 10 +++++----- NAM/dsp.h | 11 +++-------- NAM/lstm.cpp | 2 +- NAM/lstm.h | 2 +- NAM/wavenet.cpp | 4 ++-- NAM/wavenet.h | 4 ++-- tools/benchmodel.cpp | 2 +- 9 files changed, 19 insertions(+), 24 deletions(-) diff --git a/NAM/convnet.cpp b/NAM/convnet.cpp index 1122871..55721dc 100644 --- a/NAM/convnet.cpp +++ b/NAM/convnet.cpp @@ -115,7 +115,7 @@ nam::convnet::ConvNet::ConvNet(const int channels, const std::vector& dilat } -void nam::convnet::ConvNet::process(NAM_SAMPLE* input, NAM_SAMPLE* output, const int num_frames) +void nam::convnet::ConvNet::process(float* input, float* output, const int num_frames) { this->_update_buffers_(input, num_frames); @@ -140,7 +140,7 @@ void nam::convnet::ConvNet::_verify_weights(const int channels, const std::vecto // TODO } -void nam::convnet::ConvNet::_update_buffers_(NAM_SAMPLE* input, const int num_frames) +void nam::convnet::ConvNet::_update_buffers_(float* input, const int num_frames) { this->Buffer::_update_buffers_(input, num_frames); diff --git a/NAM/convnet.h b/NAM/convnet.h index a117b43..1c33661 100644 --- a/NAM/convnet.h +++ b/NAM/convnet.h @@ -78,10 +78,10 @@ class ConvNet : public Buffer _Head _head; void _verify_weights(const int channels, const std::vector& dilations, const bool batchnorm, const size_t actual_weights); - void _update_buffers_(NAM_SAMPLE* input, const int num_frames) override; + void _update_buffers_(float* input, const int num_frames) override; void _rewind_buffers_() override; - void process(NAM_SAMPLE* input, NAM_SAMPLE* output, const int num_frames) override; + void process(float* input, float* output, const int num_frames) override; }; }; // namespace convnet }; // namespace nam diff --git a/NAM/dsp.cpp b/NAM/dsp.cpp index 9b27ec9..1ae7199 100644 --- a/NAM/dsp.cpp +++ b/NAM/dsp.cpp @@ -24,8 +24,8 @@ void nam::DSP::prewarm() if (_prewarm_samples == 0) return; - NAM_SAMPLE sample = 0; - NAM_SAMPLE* sample_ptr = &sample; + float sample = 0; + float* sample_ptr = &sample; // pre-warm the model for a model-specific number of samples for (long i = 0; i < _prewarm_samples; i++) @@ -36,7 +36,7 @@ void nam::DSP::prewarm() } } -void nam::DSP::process(NAM_SAMPLE* input, NAM_SAMPLE* output, const int num_frames) +void nam::DSP::process(float* input, float* output, const int num_frames) { // Default implementation is the null operation for (auto i = 0; i < num_frames; i++) @@ -81,7 +81,7 @@ void nam::Buffer::_set_receptive_field(const int new_receptive_field, const int this->_reset_input_buffer(); } -void nam::Buffer::_update_buffers_(NAM_SAMPLE* input, const int num_frames) +void nam::Buffer::_update_buffers_(float* input, const int num_frames) { // Make sure that the buffer is big enough for the receptive field and the // frames needed! @@ -152,7 +152,7 @@ nam::Linear::Linear(const int receptive_field, const bool _bias, const std::vect this->_bias = _bias ? weights[receptive_field] : (float)0.0; } -void nam::Linear::process(NAM_SAMPLE* input, NAM_SAMPLE* output, const int num_frames) +void nam::Linear::process(float* input, float* output, const int num_frames) { this->nam::Buffer::_update_buffers_(input, num_frames); diff --git a/NAM/dsp.h b/NAM/dsp.h index 118e782..950db9b 100644 --- a/NAM/dsp.h +++ b/NAM/dsp.h @@ -12,11 +12,6 @@ #include "activations.h" #include "json.hpp" -#ifdef NAM_SAMPLE_FLOAT - #define NAM_SAMPLE float -#else - #define NAM_SAMPLE double -#endif // Use a sample rate of -1 if we don't know what the model expects to be run at. // TODO clean this up and track a bool for whether it knows. #define NAM_UNKNOWN_EXPECTED_SAMPLE_RATE -1.0 @@ -53,7 +48,7 @@ class DSP // 1. The core DSP algorithm is run (This is what should probably be // overridden in subclasses). // 2. The output level is applied and the result stored to `output`. - virtual void process(NAM_SAMPLE* input, NAM_SAMPLE* output, const int num_frames); + virtual void process(float* input, float* output, const int num_frames); // Anything to take care of before next buffer comes in. // For example: // * Move the buffer index forward @@ -103,7 +98,7 @@ class Buffer : public DSP void _set_receptive_field(const int new_receptive_field); void _reset_input_buffer(); // Use this->_input_post_gain - virtual void _update_buffers_(NAM_SAMPLE* input, int num_frames); + virtual void _update_buffers_(float* input, int num_frames); virtual void _rewind_buffers_(); }; @@ -113,7 +108,7 @@ class Linear : public Buffer public: Linear(const int receptive_field, const bool _bias, const std::vector& weights, const double expected_sample_rate = -1.0); - void process(NAM_SAMPLE* input, NAM_SAMPLE* output, const int num_frames) override; + void process(float* input, float* output, const int num_frames) override; protected: Eigen::VectorXf _weight; diff --git a/NAM/lstm.cpp b/NAM/lstm.cpp index aa0f6ad..4c1c74b 100644 --- a/NAM/lstm.cpp +++ b/NAM/lstm.cpp @@ -79,7 +79,7 @@ nam::lstm::LSTM::LSTM(const int num_layers, const int input_size, const int hidd assert(it == weights.end()); } -void nam::lstm::LSTM::process(NAM_SAMPLE* input, NAM_SAMPLE* output, const int num_frames) +void nam::lstm::LSTM::process(float* input, float* output, const int num_frames) { for (auto i = 0; i < num_frames; i++) output[i] = this->_process_sample(input[i]); diff --git a/NAM/lstm.h b/NAM/lstm.h index a432169..cd03901 100644 --- a/NAM/lstm.h +++ b/NAM/lstm.h @@ -57,7 +57,7 @@ class LSTM : public DSP protected: Eigen::VectorXf _head_weight; float _head_bias; - void process(NAM_SAMPLE* input, NAM_SAMPLE* output, const int num_frames) override; + void process(float* input, float* output, const int num_frames) override; std::vector _layers; float _process_sample(const float x); diff --git a/NAM/wavenet.cpp b/NAM/wavenet.cpp index 7899c3b..6398760 100644 --- a/NAM/wavenet.cpp +++ b/NAM/wavenet.cpp @@ -315,7 +315,7 @@ void nam::wavenet::WaveNet::_prepare_for_frames_(const long num_frames) this->_layer_arrays[i].prepare_for_frames_(num_frames); } -void nam::wavenet::WaveNet::_set_condition_array(NAM_SAMPLE* input, const int num_frames) +void nam::wavenet::WaveNet::_set_condition_array(float* input, const int num_frames) { for (int j = 0; j < num_frames; j++) { @@ -323,7 +323,7 @@ void nam::wavenet::WaveNet::_set_condition_array(NAM_SAMPLE* input, const int nu } } -void nam::wavenet::WaveNet::process(NAM_SAMPLE* input, NAM_SAMPLE* output, const int num_frames) +void nam::wavenet::WaveNet::process(float* input, float* output, const int num_frames) { this->_set_num_frames_(num_frames); this->_prepare_for_frames_(num_frames); diff --git a/NAM/wavenet.h b/NAM/wavenet.h index fbaab54..33d2ffd 100644 --- a/NAM/wavenet.h +++ b/NAM/wavenet.h @@ -191,11 +191,11 @@ class WaveNet : public DSP void _advance_buffers_(const int num_frames); void _prepare_for_frames_(const long num_frames); - void process(NAM_SAMPLE* input, NAM_SAMPLE* output, const int num_frames) override; + void process(float* input, float* output, const int num_frames) override; virtual int _get_condition_dim() const { return 1; }; // Fill in the "condition" array that's fed into the various parts of the net. - virtual void _set_condition_array(NAM_SAMPLE* input, const int num_frames); + virtual void _set_condition_array(float* input, const int num_frames); // Ensure that all buffer arrays are the right size for this num_frames void _set_num_frames_(const long num_frames); }; diff --git a/tools/benchmodel.cpp b/tools/benchmodel.cpp index 46178d2..a91f420 100644 --- a/tools/benchmodel.cpp +++ b/tools/benchmodel.cpp @@ -11,7 +11,7 @@ using std::chrono::milliseconds; #define AUDIO_BUFFER_SIZE 64 -double buffer[AUDIO_BUFFER_SIZE]; +float buffer[AUDIO_BUFFER_SIZE]; int main(int argc, char* argv[]) { From 913e5b34e73c0c6fbd301b2ac9f6d6ce91d0df13 Mon Sep 17 00:00:00 2001 From: Oli Larkin Date: Fri, 19 Jan 2024 23:35:01 +0100 Subject: [PATCH 005/133] finalize_ -> Finalize --- NAM/dsp.cpp | 8 ++++---- NAM/dsp.h | 4 ++-- NAM/wavenet.cpp | 4 ++-- NAM/wavenet.h | 2 +- tools/benchmodel.cpp | 2 +- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/NAM/dsp.cpp b/NAM/dsp.cpp index 1ae7199..8759883 100644 --- a/NAM/dsp.cpp +++ b/NAM/dsp.cpp @@ -31,7 +31,7 @@ void nam::DSP::prewarm() for (long i = 0; i < _prewarm_samples; i++) { this->process(sample_ptr, sample_ptr, 1); - this->finalize_(1); + this->Finalize(1); sample = 0; } } @@ -58,7 +58,7 @@ void nam::DSP::SetLoudness(const double loudness) mHasLoudness = true; } -void nam::DSP::finalize_(const int num_frames) {} +void nam::DSP::Finalize(const int num_frames) {} // Buffer ===================================================================== @@ -128,9 +128,9 @@ void nam::Buffer::_reset_input_buffer() this->_input_buffer_offset = this->_receptive_field; } -void nam::Buffer::finalize_(const int num_frames) +void nam::Buffer::Finalize(const int num_frames) { - this->nam::DSP::finalize_(num_frames); + this->nam::DSP::Finalize(num_frames); this->_input_buffer_offset += num_frames; } diff --git a/NAM/dsp.h b/NAM/dsp.h index 950db9b..3b6cb81 100644 --- a/NAM/dsp.h +++ b/NAM/dsp.h @@ -52,7 +52,7 @@ class DSP // Anything to take care of before next buffer comes in. // For example: // * Move the buffer index forward - virtual void finalize_(const int num_frames); + virtual void Finalize(const int num_frames); // Expected sample rate, in Hz. // TODO throw if it doesn't know. double GetExpectedSampleRate() const { return mExpectedSampleRate; }; @@ -83,7 +83,7 @@ class Buffer : public DSP { public: Buffer(const int receptive_field, const double expected_sample_rate = -1.0); - void finalize_(const int num_frames); + void Finalize(const int num_frames); protected: // Input buffer diff --git a/NAM/wavenet.cpp b/NAM/wavenet.cpp index 6398760..f71a51a 100644 --- a/NAM/wavenet.cpp +++ b/NAM/wavenet.cpp @@ -276,9 +276,9 @@ nam::wavenet::WaveNet::WaveNet(const std::vector _prewarm_samples += this->_layer_arrays[i].get_receptive_field(); } -void nam::wavenet::WaveNet::finalize_(const int num_frames) +void nam::wavenet::WaveNet::Finalize(const int num_frames) { - this->DSP::finalize_(num_frames); + this->DSP::Finalize(num_frames); this->_advance_buffers_(num_frames); } diff --git a/NAM/wavenet.h b/NAM/wavenet.h index 33d2ffd..dec445a 100644 --- a/NAM/wavenet.h +++ b/NAM/wavenet.h @@ -172,7 +172,7 @@ class WaveNet : public DSP const std::vector& weights, const double expected_sample_rate = -1.0); ~WaveNet() = default; - void finalize_(const int num_frames) override; + void Finalize(const int num_frames) override; void set_weights_(const std::vector& weights); private: diff --git a/tools/benchmodel.cpp b/tools/benchmodel.cpp index a91f420..382df68 100644 --- a/tools/benchmodel.cpp +++ b/tools/benchmodel.cpp @@ -46,7 +46,7 @@ int main(int argc, char* argv[]) for (size_t i = 0; i < numBuffers; i++) { model->process(buffer, buffer, AUDIO_BUFFER_SIZE); - model->finalize_(AUDIO_BUFFER_SIZE); + model->Finalize(AUDIO_BUFFER_SIZE); } std::cout << "Finished\n"; From b3ef0e2d1d883fe9215c9fceb7bb43cdab8d12e3 Mon Sep 17 00:00:00 2001 From: Oli Larkin Date: Fri, 19 Jan 2024 23:37:04 +0100 Subject: [PATCH 006/133] _prewarm_samples -> mPrewarmSamples --- NAM/convnet.cpp | 4 ++-- NAM/dsp.cpp | 4 ++-- NAM/dsp.h | 2 +- NAM/wavenet.cpp | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/NAM/convnet.cpp b/NAM/convnet.cpp index 55721dc..512a8e8 100644 --- a/NAM/convnet.cpp +++ b/NAM/convnet.cpp @@ -109,9 +109,9 @@ nam::convnet::ConvNet::ConvNet(const int channels, const std::vector& dilat if (it != weights.end()) throw std::runtime_error("Didn't touch all the weights when initializing ConvNet"); - _prewarm_samples = 1; + mPrewarmSamples = 1; for (size_t i = 0; i < dilations.size(); i++) - _prewarm_samples += dilations[i]; + mPrewarmSamples += dilations[i]; } diff --git a/NAM/dsp.cpp b/NAM/dsp.cpp index 8759883..217d251 100644 --- a/NAM/dsp.cpp +++ b/NAM/dsp.cpp @@ -21,14 +21,14 @@ nam::DSP::DSP(const double expected_sample_rate) void nam::DSP::prewarm() { - if (_prewarm_samples == 0) + if (mPrewarmSamples == 0) return; float sample = 0; float* sample_ptr = &sample; // pre-warm the model for a model-specific number of samples - for (long i = 0; i < _prewarm_samples; i++) + for (long i = 0; i < mPrewarmSamples; i++) { this->process(sample_ptr, sample_ptr, 1); this->Finalize(1); diff --git a/NAM/dsp.h b/NAM/dsp.h index 3b6cb81..f9678e2 100644 --- a/NAM/dsp.h +++ b/NAM/dsp.h @@ -73,7 +73,7 @@ class DSP // What sample rate does the model expect? double mExpectedSampleRate; // How many samples should be processed during "pre-warming" - int _prewarm_samples = 0; + int mPrewarmSamples = 0; }; // Class where an input buffer is kept so that long-time effects can be diff --git a/NAM/wavenet.cpp b/NAM/wavenet.cpp index f71a51a..4994f5c 100644 --- a/NAM/wavenet.cpp +++ b/NAM/wavenet.cpp @@ -271,9 +271,9 @@ nam::wavenet::WaveNet::WaveNet(const std::vector this->_head_output.resize(1, 0); // Mono output! this->set_weights_(weights); - _prewarm_samples = 1; + mPrewarmSamples = 1; for (size_t i = 0; i < this->_layer_arrays.size(); i++) - _prewarm_samples += this->_layer_arrays[i].get_receptive_field(); + mPrewarmSamples += this->_layer_arrays[i].get_receptive_field(); } void nam::wavenet::WaveNet::Finalize(const int num_frames) From 9298e8b993143c23aee0a71e9df048fe50ba5491 Mon Sep 17 00:00:00 2001 From: Oli Larkin Date: Fri, 19 Jan 2024 23:39:54 +0100 Subject: [PATCH 007/133] num_frames -> numFrames --- NAM/convnet.cpp | 12 ++++---- NAM/convnet.h | 4 +-- NAM/dsp.cpp | 28 +++++++++--------- NAM/dsp.h | 10 +++---- NAM/lstm.cpp | 4 +-- NAM/lstm.h | 2 +- NAM/wavenet.cpp | 78 ++++++++++++++++++++++++------------------------- NAM/wavenet.h | 24 +++++++-------- 8 files changed, 81 insertions(+), 81 deletions(-) diff --git a/NAM/convnet.cpp b/NAM/convnet.cpp index 512a8e8..45f3a88 100644 --- a/NAM/convnet.cpp +++ b/NAM/convnet.cpp @@ -115,13 +115,13 @@ nam::convnet::ConvNet::ConvNet(const int channels, const std::vector& dilat } -void nam::convnet::ConvNet::process(float* input, float* output, const int num_frames) +void nam::convnet::ConvNet::process(float* input, float* output, const int numFrames) { - this->_update_buffers_(input, num_frames); + this->_update_buffers_(input, numFrames); // Main computation! const long i_start = this->_input_buffer_offset; - const long i_end = i_start + num_frames; + const long i_end = i_start + numFrames; // TODO one unnecessary copy :/ #speed for (auto i = i_start; i < i_end; i++) this->_block_vals[0](0, i) = this->_input_buffer[i]; @@ -130,7 +130,7 @@ void nam::convnet::ConvNet::process(float* input, float* output, const int num_f // TODO clean up this allocation this->_head.process_(this->_block_vals[this->_blocks.size()], this->_head_output, i_start, i_end); // Copy to required output array (TODO tighten this up) - for (int s = 0; s < num_frames; s++) + for (int s = 0; s < numFrames; s++) output[s] = this->_head_output(s); } @@ -140,9 +140,9 @@ void nam::convnet::ConvNet::_verify_weights(const int channels, const std::vecto // TODO } -void nam::convnet::ConvNet::_update_buffers_(float* input, const int num_frames) +void nam::convnet::ConvNet::_update_buffers_(float* input, const int numFrames) { - this->Buffer::_update_buffers_(input, num_frames); + this->Buffer::_update_buffers_(input, numFrames); const size_t buffer_size = this->_input_buffer.size(); diff --git a/NAM/convnet.h b/NAM/convnet.h index 1c33661..b90b8bf 100644 --- a/NAM/convnet.h +++ b/NAM/convnet.h @@ -78,10 +78,10 @@ class ConvNet : public Buffer _Head _head; void _verify_weights(const int channels, const std::vector& dilations, const bool batchnorm, const size_t actual_weights); - void _update_buffers_(float* input, const int num_frames) override; + void _update_buffers_(float* input, const int numFrames) override; void _rewind_buffers_() override; - void process(float* input, float* output, const int num_frames) override; + void process(float* input, float* output, const int numFrames) override; }; }; // namespace convnet }; // namespace nam diff --git a/NAM/dsp.cpp b/NAM/dsp.cpp index 217d251..22c8c3a 100644 --- a/NAM/dsp.cpp +++ b/NAM/dsp.cpp @@ -36,10 +36,10 @@ void nam::DSP::prewarm() } } -void nam::DSP::process(float* input, float* output, const int num_frames) +void nam::DSP::process(float* input, float* output, const int numFrames) { // Default implementation is the null operation - for (auto i = 0; i < num_frames; i++) + for (auto i = 0; i < numFrames; i++) output[i] = input[i]; } @@ -58,7 +58,7 @@ void nam::DSP::SetLoudness(const double loudness) mHasLoudness = true; } -void nam::DSP::Finalize(const int num_frames) {} +void nam::DSP::Finalize(const int numFrames) {} // Buffer ===================================================================== @@ -81,12 +81,12 @@ void nam::Buffer::_set_receptive_field(const int new_receptive_field, const int this->_reset_input_buffer(); } -void nam::Buffer::_update_buffers_(float* input, const int num_frames) +void nam::Buffer::_update_buffers_(float* input, const int numFrames) { // Make sure that the buffer is big enough for the receptive field and the // frames needed! { - const long minimum_input_buffer_size = (long)this->_receptive_field + _INPUT_BUFFER_SAFETY_FACTOR * num_frames; + const long minimum_input_buffer_size = (long)this->_receptive_field + _INPUT_BUFFER_SAFETY_FACTOR * numFrames; if ((long)this->_input_buffer.size() < minimum_input_buffer_size) { long new_buffer_size = 2; @@ -99,13 +99,13 @@ void nam::Buffer::_update_buffers_(float* input, const int num_frames) // If we'd run off the end of the input buffer, then we need to move the data // back to the start of the buffer and start again. - if (this->_input_buffer_offset + num_frames > (long)this->_input_buffer.size()) + if (this->_input_buffer_offset + numFrames > (long)this->_input_buffer.size()) this->_rewind_buffers_(); // Put the new samples into the input buffer - for (long i = this->_input_buffer_offset, j = 0; j < num_frames; i++, j++) + for (long i = this->_input_buffer_offset, j = 0; j < numFrames; i++, j++) this->_input_buffer[i] = input[j]; // And resize the output buffer: - this->_output_buffer.resize(num_frames); + this->_output_buffer.resize(numFrames); std::fill(this->_output_buffer.begin(), this->_output_buffer.end(), 0.0f); } @@ -128,10 +128,10 @@ void nam::Buffer::_reset_input_buffer() this->_input_buffer_offset = this->_receptive_field; } -void nam::Buffer::Finalize(const int num_frames) +void nam::Buffer::Finalize(const int numFrames) { - this->nam::DSP::Finalize(num_frames); - this->_input_buffer_offset += num_frames; + this->nam::DSP::Finalize(numFrames); + this->_input_buffer_offset += numFrames; } // Linear ===================================================================== @@ -152,12 +152,12 @@ nam::Linear::Linear(const int receptive_field, const bool _bias, const std::vect this->_bias = _bias ? weights[receptive_field] : (float)0.0; } -void nam::Linear::process(float* input, float* output, const int num_frames) +void nam::Linear::process(float* input, float* output, const int numFrames) { - this->nam::Buffer::_update_buffers_(input, num_frames); + this->nam::Buffer::_update_buffers_(input, numFrames); // Main computation! - for (auto i = 0; i < num_frames; i++) + for (auto i = 0; i < numFrames; i++) { const size_t offset = this->_input_buffer_offset - this->_weight.size() + i + 1; auto input = Eigen::Map(&this->_input_buffer[offset], this->_receptive_field); diff --git a/NAM/dsp.h b/NAM/dsp.h index f9678e2..c44862c 100644 --- a/NAM/dsp.h +++ b/NAM/dsp.h @@ -48,11 +48,11 @@ class DSP // 1. The core DSP algorithm is run (This is what should probably be // overridden in subclasses). // 2. The output level is applied and the result stored to `output`. - virtual void process(float* input, float* output, const int num_frames); + virtual void process(float* input, float* output, const int numFrames); // Anything to take care of before next buffer comes in. // For example: // * Move the buffer index forward - virtual void Finalize(const int num_frames); + virtual void Finalize(const int numFrames); // Expected sample rate, in Hz. // TODO throw if it doesn't know. double GetExpectedSampleRate() const { return mExpectedSampleRate; }; @@ -83,7 +83,7 @@ class Buffer : public DSP { public: Buffer(const int receptive_field, const double expected_sample_rate = -1.0); - void Finalize(const int num_frames); + void Finalize(const int numFrames); protected: // Input buffer @@ -98,7 +98,7 @@ class Buffer : public DSP void _set_receptive_field(const int new_receptive_field); void _reset_input_buffer(); // Use this->_input_post_gain - virtual void _update_buffers_(float* input, int num_frames); + virtual void _update_buffers_(float* input, int numFrames); virtual void _rewind_buffers_(); }; @@ -108,7 +108,7 @@ class Linear : public Buffer public: Linear(const int receptive_field, const bool _bias, const std::vector& weights, const double expected_sample_rate = -1.0); - void process(float* input, float* output, const int num_frames) override; + void process(float* input, float* output, const int numFrames) override; protected: Eigen::VectorXf _weight; diff --git a/NAM/lstm.cpp b/NAM/lstm.cpp index 4c1c74b..99726e4 100644 --- a/NAM/lstm.cpp +++ b/NAM/lstm.cpp @@ -79,9 +79,9 @@ nam::lstm::LSTM::LSTM(const int num_layers, const int input_size, const int hidd assert(it == weights.end()); } -void nam::lstm::LSTM::process(float* input, float* output, const int num_frames) +void nam::lstm::LSTM::process(float* input, float* output, const int numFrames) { - for (auto i = 0; i < num_frames; i++) + for (auto i = 0; i < numFrames; i++) output[i] = this->_process_sample(input[i]); } diff --git a/NAM/lstm.h b/NAM/lstm.h index cd03901..7173eb8 100644 --- a/NAM/lstm.h +++ b/NAM/lstm.h @@ -57,7 +57,7 @@ class LSTM : public DSP protected: Eigen::VectorXf _head_weight; float _head_bias; - void process(float* input, float* output, const int num_frames) override; + void process(float* input, float* output, const int numFrames) override; std::vector _layers; float _process_sample(const float x); diff --git a/NAM/wavenet.cpp b/NAM/wavenet.cpp index 4994f5c..3bc3584 100644 --- a/NAM/wavenet.cpp +++ b/NAM/wavenet.cpp @@ -46,12 +46,12 @@ void nam::wavenet::_Layer::process_(const Eigen::Ref inpu output.middleCols(j_start, ncols) = input.middleCols(i_start, ncols) + this->_1x1.process(this->_z.topRows(channels)); } -void nam::wavenet::_Layer::set_num_frames_(const long num_frames) +void nam::wavenet::_Layer::set_num_frames_(const long numFrames) { - if (this->_z.rows() == this->_conv.get_out_channels() && this->_z.cols() == num_frames) + if (this->_z.rows() == this->_conv.get_out_channels() && this->_z.cols() == numFrames) return; // Already has correct size - this->_z.resize(this->_conv.get_out_channels(), num_frames); + this->_z.resize(this->_conv.get_out_channels(), numFrames); this->_z.setZero(); } @@ -76,9 +76,9 @@ nam::wavenet::_LayerArray::_LayerArray(const int input_size, const int condition this->_buffer_start = this->_get_receptive_field() - 1; } -void nam::wavenet::_LayerArray::advance_buffers_(const int num_frames) +void nam::wavenet::_LayerArray::advance_buffers_(const int numFrames) { - this->_buffer_start += num_frames; + this->_buffer_start += numFrames; } long nam::wavenet::_LayerArray::get_receptive_field() const @@ -89,16 +89,16 @@ long nam::wavenet::_LayerArray::get_receptive_field() const return result; } -void nam::wavenet::_LayerArray::prepare_for_frames_(const long num_frames) +void nam::wavenet::_LayerArray::prepare_for_frames_(const long numFrames) { // Example: // _buffer_start = 0 - // num_frames = 64 + // numFrames = 64 // buffer_size = 64 // -> this will write on indices 0 through 63, inclusive. // -> No illegal writes. // -> no rewind needed. - if (this->_buffer_start + num_frames > this->_get_buffer_size()) + if (this->_buffer_start + numFrames > this->_get_buffer_size()) this->_rewind_buffers_(); } @@ -127,20 +127,20 @@ void nam::wavenet::_LayerArray::process_(const Eigen::Ref head_outputs = this->_head_rechannel.process(head_inputs); } -void nam::wavenet::_LayerArray::set_num_frames_(const long num_frames) +void nam::wavenet::_LayerArray::set_num_frames_(const long numFrames) { - // Wavenet checks for unchanged num_frames; if we made it here, there's + // Wavenet checks for unchanged numFrames; if we made it here, there's // something to do. - if (LAYER_ARRAY_BUFFER_SIZE - num_frames < this->_get_receptive_field()) + if (LAYER_ARRAY_BUFFER_SIZE - numFrames < this->_get_receptive_field()) { std::stringstream ss; - ss << "Asked to accept a buffer of " << num_frames << " samples, but the buffer is too short (" + ss << "Asked to accept a buffer of " << numFrames << " samples, but the buffer is too short (" << LAYER_ARRAY_BUFFER_SIZE << ") to get out of the recptive field (" << this->_get_receptive_field() << "); copy errors could occur!\n"; throw std::runtime_error(ss.str().c_str()); } for (size_t i = 0; i < this->_layers.size(); i++) - this->_layers[i].set_num_frames_(num_frames); + this->_layers[i].set_num_frames_(numFrames); } void nam::wavenet::_LayerArray::set_weights_(weights_it& weights) @@ -222,13 +222,13 @@ void nam::wavenet::_Head::process_(Eigen::Ref inputs, Eigen::Re } } -void nam::wavenet::_Head::set_num_frames_(const long num_frames) +void nam::wavenet::_Head::set_num_frames_(const long numFrames) { for (size_t i = 0; i < this->_buffers.size(); i++) { - if (this->_buffers[i].rows() == this->_channels && this->_buffers[i].cols() == num_frames) + if (this->_buffers[i].rows() == this->_channels && this->_buffers[i].cols() == numFrames) continue; // Already has correct size - this->_buffers[i].resize(this->_channels, num_frames); + this->_buffers[i].resize(this->_channels, numFrames); this->_buffers[i].setZero(); } } @@ -276,10 +276,10 @@ nam::wavenet::WaveNet::WaveNet(const std::vector mPrewarmSamples += this->_layer_arrays[i].get_receptive_field(); } -void nam::wavenet::WaveNet::Finalize(const int num_frames) +void nam::wavenet::WaveNet::Finalize(const int numFrames) { - this->DSP::Finalize(num_frames); - this->_advance_buffers_(num_frames); + this->DSP::Finalize(numFrames); + this->_advance_buffers_(numFrames); } void nam::wavenet::WaveNet::set_weights_(const std::vector& weights) @@ -303,31 +303,31 @@ void nam::wavenet::WaveNet::set_weights_(const std::vector& weights) } } -void nam::wavenet::WaveNet::_advance_buffers_(const int num_frames) +void nam::wavenet::WaveNet::_advance_buffers_(const int numFrames) { for (size_t i = 0; i < this->_layer_arrays.size(); i++) - this->_layer_arrays[i].advance_buffers_(num_frames); + this->_layer_arrays[i].advance_buffers_(numFrames); } -void nam::wavenet::WaveNet::_prepare_for_frames_(const long num_frames) +void nam::wavenet::WaveNet::_prepare_for_frames_(const long numFrames) { for (size_t i = 0; i < this->_layer_arrays.size(); i++) - this->_layer_arrays[i].prepare_for_frames_(num_frames); + this->_layer_arrays[i].prepare_for_frames_(numFrames); } -void nam::wavenet::WaveNet::_set_condition_array(float* input, const int num_frames) +void nam::wavenet::WaveNet::_set_condition_array(float* input, const int numFrames) { - for (int j = 0; j < num_frames; j++) + for (int j = 0; j < numFrames; j++) { this->_condition(0, j) = input[j]; } } -void nam::wavenet::WaveNet::process(float* input, float* output, const int num_frames) +void nam::wavenet::WaveNet::process(float* input, float* output, const int numFrames) { - this->_set_num_frames_(num_frames); - this->_prepare_for_frames_(num_frames); - this->_set_condition_array(input, num_frames); + this->_set_num_frames_(numFrames); + this->_prepare_for_frames_(numFrames); + this->_set_condition_array(input, numFrames); // Main layer arrays: // Layer-to-layer @@ -346,28 +346,28 @@ void nam::wavenet::WaveNet::process(float* input, float* output, const int num_f const long final_head_array = this->_head_arrays.size() - 1; assert(this->_head_arrays[final_head_array].rows() == 1); - for (int s = 0; s < num_frames; s++) + for (int s = 0; s < numFrames; s++) { float out = this->_head_scale * this->_head_arrays[final_head_array](0, s); output[s] = out; } } -void nam::wavenet::WaveNet::_set_num_frames_(const long num_frames) +void nam::wavenet::WaveNet::_set_num_frames_(const long numFrames) { - if (num_frames == this->_num_frames) + if (numFrames == this->_num_frames) return; - this->_condition.resize(this->_get_condition_dim(), num_frames); + this->_condition.resize(this->_get_condition_dim(), numFrames); for (size_t i = 0; i < this->_head_arrays.size(); i++) - this->_head_arrays[i].resize(this->_head_arrays[i].rows(), num_frames); + this->_head_arrays[i].resize(this->_head_arrays[i].rows(), numFrames); for (size_t i = 0; i < this->_layer_array_outputs.size(); i++) - this->_layer_array_outputs[i].resize(this->_layer_array_outputs[i].rows(), num_frames); - this->_head_output.resize(this->_head_output.rows(), num_frames); + this->_layer_array_outputs[i].resize(this->_layer_array_outputs[i].rows(), numFrames); + this->_head_output.resize(this->_head_output.rows(), numFrames); this->_head_output.setZero(); for (size_t i = 0; i < this->_layer_arrays.size(); i++) - this->_layer_arrays[i].set_num_frames_(num_frames); - // this->_head.set_num_frames_(num_frames); - this->_num_frames = num_frames; + this->_layer_arrays[i].set_num_frames_(numFrames); + // this->_head.set_num_frames_(numFrames); + this->_num_frames = numFrames; } diff --git a/NAM/wavenet.h b/NAM/wavenet.h index dec445a..955358e 100644 --- a/NAM/wavenet.h +++ b/NAM/wavenet.h @@ -35,7 +35,7 @@ class _Layer // :param `output`: to next layer void process_(const Eigen::Ref input, const Eigen::Ref condition, Eigen::Ref head_input, Eigen::Ref output, const long i_start, const long j_start); - void set_num_frames_(const long num_frames); + void set_num_frames_(const long numFrames); long get_channels() const { return this->_conv.get_in_channels(); }; int get_dilation() const { return this->_conv.get_dilation(); }; long get_kernel_size() const { return this->_conv.get_kernel_size(); }; @@ -92,13 +92,13 @@ class _LayerArray const int kernel_size, const std::vector& dilations, const std::string activation, const bool gated, const bool head_bias); - void advance_buffers_(const int num_frames); + void advance_buffers_(const int numFrames); // Preparing for frames: // Rewind buffers if needed // Shift index to prepare // - void prepare_for_frames_(const long num_frames); + void prepare_for_frames_(const long numFrames); // All arrays are "short". void process_(const Eigen::Ref layer_inputs, // Short @@ -107,7 +107,7 @@ class _LayerArray Eigen::Ref head_inputs, // Sum up on this. Eigen::Ref head_outputs // post head-rechannel ); - void set_num_frames_(const long num_frames); + void set_num_frames_(const long numFrames); void set_weights_(weights_it& it); // "Zero-indexed" receptive field. @@ -148,7 +148,7 @@ class _Head // NOTE: the head transforms the provided input by applying a nonlinearity // to it in-place! void process_(Eigen::Ref inputs, Eigen::Ref outputs); - void set_num_frames_(const long num_frames); + void set_num_frames_(const long numFrames); private: int _channels; @@ -172,7 +172,7 @@ class WaveNet : public DSP const std::vector& weights, const double expected_sample_rate = -1.0); ~WaveNet() = default; - void Finalize(const int num_frames) override; + void Finalize(const int numFrames) override; void set_weights_(const std::vector& weights); private: @@ -189,15 +189,15 @@ class WaveNet : public DSP float _head_scale; Eigen::MatrixXf _head_output; - void _advance_buffers_(const int num_frames); - void _prepare_for_frames_(const long num_frames); - void process(float* input, float* output, const int num_frames) override; + void _advance_buffers_(const int numFrames); + void _prepare_for_frames_(const long numFrames); + void process(float* input, float* output, const int numFrames) override; virtual int _get_condition_dim() const { return 1; }; // Fill in the "condition" array that's fed into the various parts of the net. - virtual void _set_condition_array(float* input, const int num_frames); - // Ensure that all buffer arrays are the right size for this num_frames - void _set_num_frames_(const long num_frames); + virtual void _set_condition_array(float* input, const int numFrames); + // Ensure that all buffer arrays are the right size for this numFrames + void _set_num_frames_(const long numFrames); }; }; // namespace wavenet }; // namespace nam From 9378f8f25137a28cb43f388a1d89629799792ddf Mon Sep 17 00:00:00 2001 From: Oli Larkin Date: Fri, 19 Jan 2024 23:43:17 +0100 Subject: [PATCH 008/133] process -> Process --- NAM/convnet.cpp | 2 +- NAM/convnet.h | 2 +- NAM/dsp.cpp | 8 ++++---- NAM/dsp.h | 8 ++++---- NAM/lstm.cpp | 2 +- NAM/lstm.h | 2 +- NAM/wavenet.cpp | 18 +++++++++--------- NAM/wavenet.h | 2 +- tools/benchmodel.cpp | 2 +- 9 files changed, 23 insertions(+), 23 deletions(-) diff --git a/NAM/convnet.cpp b/NAM/convnet.cpp index 45f3a88..8dde0fb 100644 --- a/NAM/convnet.cpp +++ b/NAM/convnet.cpp @@ -115,7 +115,7 @@ nam::convnet::ConvNet::ConvNet(const int channels, const std::vector& dilat } -void nam::convnet::ConvNet::process(float* input, float* output, const int numFrames) +void nam::convnet::ConvNet::Process(float* input, float* output, const int numFrames) { this->_update_buffers_(input, numFrames); diff --git a/NAM/convnet.h b/NAM/convnet.h index b90b8bf..070496c 100644 --- a/NAM/convnet.h +++ b/NAM/convnet.h @@ -81,7 +81,7 @@ class ConvNet : public Buffer void _update_buffers_(float* input, const int numFrames) override; void _rewind_buffers_() override; - void process(float* input, float* output, const int numFrames) override; + void Process(float* input, float* output, const int numFrames) override; }; }; // namespace convnet }; // namespace nam diff --git a/NAM/dsp.cpp b/NAM/dsp.cpp index 22c8c3a..a34bec7 100644 --- a/NAM/dsp.cpp +++ b/NAM/dsp.cpp @@ -30,13 +30,13 @@ void nam::DSP::prewarm() // pre-warm the model for a model-specific number of samples for (long i = 0; i < mPrewarmSamples; i++) { - this->process(sample_ptr, sample_ptr, 1); + this->Process(sample_ptr, sample_ptr, 1); this->Finalize(1); sample = 0; } } -void nam::DSP::process(float* input, float* output, const int numFrames) +void nam::DSP::Process(float* input, float* output, const int numFrames) { // Default implementation is the null operation for (auto i = 0; i < numFrames; i++) @@ -152,7 +152,7 @@ nam::Linear::Linear(const int receptive_field, const bool _bias, const std::vect this->_bias = _bias ? weights[receptive_field] : (float)0.0; } -void nam::Linear::process(float* input, float* output, const int numFrames) +void nam::Linear::Process(float* input, float* output, const int numFrames) { this->nam::Buffer::_update_buffers_(input, numFrames); @@ -246,7 +246,7 @@ void nam::Conv1x1::set_weights_(weights_it& weights) this->_bias(i) = *(weights++); } -Eigen::MatrixXf nam::Conv1x1::process(const Eigen::Ref input) const +Eigen::MatrixXf nam::Conv1x1::Process(const Eigen::Ref input) const { if (this->_do_bias) return (this->_weight * input).colwise() + this->_bias; diff --git a/NAM/dsp.h b/NAM/dsp.h index c44862c..3397c60 100644 --- a/NAM/dsp.h +++ b/NAM/dsp.h @@ -42,13 +42,13 @@ class DSP // prewarm() does any required intial work required to "settle" model initial conditions // it can be somewhat expensive, so should not be called during realtime audio processing virtual void prewarm(); - // process() does all of the processing requried to take `input` array and + // Process() does all of the processing requried to take `input` array and // fill in the required values on `output`. // To do this: // 1. The core DSP algorithm is run (This is what should probably be // overridden in subclasses). // 2. The output level is applied and the result stored to `output`. - virtual void process(float* input, float* output, const int numFrames); + virtual void Process(float* input, float* output, const int numFrames); // Anything to take care of before next buffer comes in. // For example: // * Move the buffer index forward @@ -108,7 +108,7 @@ class Linear : public Buffer public: Linear(const int receptive_field, const bool _bias, const std::vector& weights, const double expected_sample_rate = -1.0); - void process(float* input, float* output, const int numFrames) override; + void Process(float* input, float* output, const int numFrames) override; protected: Eigen::VectorXf _weight; @@ -153,7 +153,7 @@ class Conv1x1 void set_weights_(weights_it& weights); // :param input: (N,Cin) or (Cin,) // :return: (N,Cout) or (Cout,), respectively - Eigen::MatrixXf process(const Eigen::Ref input) const; + Eigen::MatrixXf Process(const Eigen::Ref input) const; long get_out_channels() const { return this->_weight.rows(); }; diff --git a/NAM/lstm.cpp b/NAM/lstm.cpp index 99726e4..61dc786 100644 --- a/NAM/lstm.cpp +++ b/NAM/lstm.cpp @@ -79,7 +79,7 @@ nam::lstm::LSTM::LSTM(const int num_layers, const int input_size, const int hidd assert(it == weights.end()); } -void nam::lstm::LSTM::process(float* input, float* output, const int numFrames) +void nam::lstm::LSTM::Process(float* input, float* output, const int numFrames) { for (auto i = 0; i < numFrames; i++) output[i] = this->_process_sample(input[i]); diff --git a/NAM/lstm.h b/NAM/lstm.h index 7173eb8..670f252 100644 --- a/NAM/lstm.h +++ b/NAM/lstm.h @@ -57,7 +57,7 @@ class LSTM : public DSP protected: Eigen::VectorXf _head_weight; float _head_bias; - void process(float* input, float* output, const int numFrames) override; + void Process(float* input, float* output, const int numFrames) override; std::vector _layers; float _process_sample(const float x); diff --git a/NAM/wavenet.cpp b/NAM/wavenet.cpp index 3bc3584..650a024 100644 --- a/NAM/wavenet.cpp +++ b/NAM/wavenet.cpp @@ -28,7 +28,7 @@ void nam::wavenet::_Layer::process_(const Eigen::Ref inpu // Input dilated conv this->_conv.process_(input, this->_z, i_start, ncols, 0); // Mix-in condition - this->_z += this->_input_mixin.process(condition); + this->_z += this->_input_mixin.Process(condition); this->_activation->apply(this->_z); @@ -43,7 +43,7 @@ void nam::wavenet::_Layer::process_(const Eigen::Ref inpu } head_input += this->_z.topRows(channels); - output.middleCols(j_start, ncols) = input.middleCols(i_start, ncols) + this->_1x1.process(this->_z.topRows(channels)); + output.middleCols(j_start, ncols) = input.middleCols(i_start, ncols) + this->_1x1.Process(this->_z.topRows(channels)); } void nam::wavenet::_Layer::set_num_frames_(const long numFrames) @@ -106,7 +106,7 @@ void nam::wavenet::_LayerArray::process_(const Eigen::Ref Eigen::Ref head_inputs, Eigen::Ref layer_outputs, Eigen::Ref head_outputs) { - this->_layer_buffers[0].middleCols(this->_buffer_start, layer_inputs.cols()) = this->_rechannel.process(layer_inputs); + this->_layer_buffers[0].middleCols(this->_buffer_start, layer_inputs.cols()) = this->_rechannel.Process(layer_inputs); const size_t last_layer = this->_layers.size() - 1; for (size_t i = 0; i < this->_layers.size(); i++) { @@ -124,7 +124,7 @@ void nam::wavenet::_LayerArray::process_(const Eigen::Ref } } - head_outputs = this->_head_rechannel.process(head_inputs); + head_outputs = this->_head_rechannel.Process(head_inputs); } void nam::wavenet::_LayerArray::set_num_frames_(const long numFrames) @@ -207,17 +207,17 @@ void nam::wavenet::_Head::process_(Eigen::Ref inputs, Eigen::Re const size_t num_layers = this->_layers.size(); this->_apply_activation_(inputs); if (num_layers == 1) - outputs = this->_layers[0].process(inputs); + outputs = this->_layers[0].Process(inputs); else { - this->_buffers[0] = this->_layers[0].process(inputs); + this->_buffers[0] = this->_layers[0].Process(inputs); for (size_t i = 1; i < num_layers; i++) { // Asserted > 0 layers this->_apply_activation_(this->_buffers[i - 1]); if (i < num_layers - 1) - this->_buffers[i] = this->_layers[i].process(this->_buffers[i - 1]); + this->_buffers[i] = this->_layers[i].Process(this->_buffers[i - 1]); else - outputs = this->_layers[i].process(this->_buffers[i - 1]); + outputs = this->_layers[i].Process(this->_buffers[i - 1]); } } } @@ -323,7 +323,7 @@ void nam::wavenet::WaveNet::_set_condition_array(float* input, const int numFram } } -void nam::wavenet::WaveNet::process(float* input, float* output, const int numFrames) +void nam::wavenet::WaveNet::Process(float* input, float* output, const int numFrames) { this->_set_num_frames_(numFrames); this->_prepare_for_frames_(numFrames); diff --git a/NAM/wavenet.h b/NAM/wavenet.h index 955358e..8fee59a 100644 --- a/NAM/wavenet.h +++ b/NAM/wavenet.h @@ -191,7 +191,7 @@ class WaveNet : public DSP void _advance_buffers_(const int numFrames); void _prepare_for_frames_(const long numFrames); - void process(float* input, float* output, const int numFrames) override; + void Process(float* input, float* output, const int numFrames) override; virtual int _get_condition_dim() const { return 1; }; // Fill in the "condition" array that's fed into the various parts of the net. diff --git a/tools/benchmodel.cpp b/tools/benchmodel.cpp index 382df68..986093a 100644 --- a/tools/benchmodel.cpp +++ b/tools/benchmodel.cpp @@ -45,7 +45,7 @@ int main(int argc, char* argv[]) for (size_t i = 0; i < numBuffers; i++) { - model->process(buffer, buffer, AUDIO_BUFFER_SIZE); + model->Process(buffer, buffer, AUDIO_BUFFER_SIZE); model->Finalize(AUDIO_BUFFER_SIZE); } From af31d4e37d48586c9c494e59c73e2f0a4373941f Mon Sep 17 00:00:00 2001 From: Oli Larkin Date: Fri, 19 Jan 2024 23:44:03 +0100 Subject: [PATCH 009/133] prewarm -> Prewarm --- NAM/dsp.cpp | 2 +- NAM/dsp.h | 4 ++-- NAM/get_dsp.cpp | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/NAM/dsp.cpp b/NAM/dsp.cpp index a34bec7..aaa1efe 100644 --- a/NAM/dsp.cpp +++ b/NAM/dsp.cpp @@ -19,7 +19,7 @@ nam::DSP::DSP(const double expected_sample_rate) { } -void nam::DSP::prewarm() +void nam::DSP::Prewarm() { if (mPrewarmSamples == 0) return; diff --git a/NAM/dsp.h b/NAM/dsp.h index 3397c60..f4a917f 100644 --- a/NAM/dsp.h +++ b/NAM/dsp.h @@ -39,9 +39,9 @@ class DSP // We may choose to have the models figure out for themselves how loud they are in here in the future. DSP(const double expected_sample_rate); virtual ~DSP() = default; - // prewarm() does any required intial work required to "settle" model initial conditions + // Prewarm() does any required intial work required to "settle" model initial conditions // it can be somewhat expensive, so should not be called during realtime audio processing - virtual void prewarm(); + virtual void Prewarm(); // Process() does all of the processing requried to take `input` array and // fill in the required values on `output`. // To do this: diff --git a/NAM/get_dsp.cpp b/NAM/get_dsp.cpp index 47aba97..d848046 100644 --- a/NAM/get_dsp.cpp +++ b/NAM/get_dsp.cpp @@ -194,7 +194,7 @@ std::unique_ptr get_dsp(dspData& conf) } // "pre-warm" the model to settle initial conditions - out->prewarm(); + out->Prewarm(); return out; } From 76984203e10ac772e5d8a7fbe370df90e4f503aa Mon Sep 17 00:00:00 2001 From: Oli Larkin Date: Fri, 19 Jan 2024 23:45:05 +0100 Subject: [PATCH 010/133] _set_receptive_field -> SetReceptiveField --- NAM/dsp.cpp | 8 ++++---- NAM/dsp.h | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/NAM/dsp.cpp b/NAM/dsp.cpp index aaa1efe..f7b6d49 100644 --- a/NAM/dsp.cpp +++ b/NAM/dsp.cpp @@ -65,15 +65,15 @@ void nam::DSP::Finalize(const int numFrames) {} nam::Buffer::Buffer(const int receptive_field, const double expected_sample_rate) : nam::DSP(expected_sample_rate) { - this->_set_receptive_field(receptive_field); + this->SetReceptiveField(receptive_field); } -void nam::Buffer::_set_receptive_field(const int new_receptive_field) +void nam::Buffer::SetReceptiveField(const int new_receptive_field) { - this->_set_receptive_field(new_receptive_field, _INPUT_BUFFER_SAFETY_FACTOR * new_receptive_field); + this->SetReceptiveField(new_receptive_field, _INPUT_BUFFER_SAFETY_FACTOR * new_receptive_field); }; -void nam::Buffer::_set_receptive_field(const int new_receptive_field, const int input_buffer_size) +void nam::Buffer::SetReceptiveField(const int new_receptive_field, const int input_buffer_size) { this->_receptive_field = new_receptive_field; this->_input_buffer.resize(input_buffer_size); diff --git a/NAM/dsp.h b/NAM/dsp.h index f4a917f..bb4ba1e 100644 --- a/NAM/dsp.h +++ b/NAM/dsp.h @@ -94,8 +94,8 @@ class Buffer : public DSP std::vector _input_buffer; std::vector _output_buffer; - void _set_receptive_field(const int new_receptive_field, const int input_buffer_size); - void _set_receptive_field(const int new_receptive_field); + void SetReceptiveField(const int new_receptive_field, const int input_buffer_size); + void SetReceptiveField(const int new_receptive_field); void _reset_input_buffer(); // Use this->_input_post_gain virtual void _update_buffers_(float* input, int numFrames); From 693bf13022491bc590c874891c0629145c1777e2 Mon Sep 17 00:00:00 2001 From: Oli Larkin Date: Fri, 19 Jan 2024 23:45:30 +0100 Subject: [PATCH 011/133] _reset_input_buffer ResetInputBuffer --- NAM/dsp.cpp | 4 ++-- NAM/dsp.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/NAM/dsp.cpp b/NAM/dsp.cpp index f7b6d49..dfede9f 100644 --- a/NAM/dsp.cpp +++ b/NAM/dsp.cpp @@ -78,7 +78,7 @@ void nam::Buffer::SetReceptiveField(const int new_receptive_field, const int inp this->_receptive_field = new_receptive_field; this->_input_buffer.resize(input_buffer_size); std::fill(this->_input_buffer.begin(), this->_input_buffer.end(), 0.0f); - this->_reset_input_buffer(); + this->ResetInputBuffer(); } void nam::Buffer::_update_buffers_(float* input, const int numFrames) @@ -123,7 +123,7 @@ void nam::Buffer::_rewind_buffers_() this->_input_buffer_offset = this->_receptive_field; } -void nam::Buffer::_reset_input_buffer() +void nam::Buffer::ResetInputBuffer() { this->_input_buffer_offset = this->_receptive_field; } diff --git a/NAM/dsp.h b/NAM/dsp.h index bb4ba1e..61d9073 100644 --- a/NAM/dsp.h +++ b/NAM/dsp.h @@ -96,7 +96,7 @@ class Buffer : public DSP void SetReceptiveField(const int new_receptive_field, const int input_buffer_size); void SetReceptiveField(const int new_receptive_field); - void _reset_input_buffer(); + void ResetInputBuffer(); // Use this->_input_post_gain virtual void _update_buffers_(float* input, int numFrames); virtual void _rewind_buffers_(); From 6e55afa7ce290eee963206bc50716f78639f841a Mon Sep 17 00:00:00 2001 From: Oli Larkin Date: Fri, 19 Jan 2024 23:45:57 +0100 Subject: [PATCH 012/133] _update_buffers_ UpdateBuffers --- NAM/convnet.cpp | 6 +++--- NAM/convnet.h | 2 +- NAM/dsp.cpp | 4 ++-- NAM/dsp.h | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/NAM/convnet.cpp b/NAM/convnet.cpp index 8dde0fb..b95fee3 100644 --- a/NAM/convnet.cpp +++ b/NAM/convnet.cpp @@ -118,7 +118,7 @@ nam::convnet::ConvNet::ConvNet(const int channels, const std::vector& dilat void nam::convnet::ConvNet::Process(float* input, float* output, const int numFrames) { - this->_update_buffers_(input, numFrames); + this->UpdateBuffers(input, numFrames); // Main computation! const long i_start = this->_input_buffer_offset; const long i_end = i_start + numFrames; @@ -140,9 +140,9 @@ void nam::convnet::ConvNet::_verify_weights(const int channels, const std::vecto // TODO } -void nam::convnet::ConvNet::_update_buffers_(float* input, const int numFrames) +void nam::convnet::ConvNet::UpdateBuffers(float* input, const int numFrames) { - this->Buffer::_update_buffers_(input, numFrames); + this->Buffer::UpdateBuffers(input, numFrames); const size_t buffer_size = this->_input_buffer.size(); diff --git a/NAM/convnet.h b/NAM/convnet.h index 070496c..799c55c 100644 --- a/NAM/convnet.h +++ b/NAM/convnet.h @@ -78,7 +78,7 @@ class ConvNet : public Buffer _Head _head; void _verify_weights(const int channels, const std::vector& dilations, const bool batchnorm, const size_t actual_weights); - void _update_buffers_(float* input, const int numFrames) override; + void UpdateBuffers(float* input, const int numFrames) override; void _rewind_buffers_() override; void Process(float* input, float* output, const int numFrames) override; diff --git a/NAM/dsp.cpp b/NAM/dsp.cpp index dfede9f..09b88fb 100644 --- a/NAM/dsp.cpp +++ b/NAM/dsp.cpp @@ -81,7 +81,7 @@ void nam::Buffer::SetReceptiveField(const int new_receptive_field, const int inp this->ResetInputBuffer(); } -void nam::Buffer::_update_buffers_(float* input, const int numFrames) +void nam::Buffer::UpdateBuffers(float* input, const int numFrames) { // Make sure that the buffer is big enough for the receptive field and the // frames needed! @@ -154,7 +154,7 @@ nam::Linear::Linear(const int receptive_field, const bool _bias, const std::vect void nam::Linear::Process(float* input, float* output, const int numFrames) { - this->nam::Buffer::_update_buffers_(input, numFrames); + this->nam::Buffer::UpdateBuffers(input, numFrames); // Main computation! for (auto i = 0; i < numFrames; i++) diff --git a/NAM/dsp.h b/NAM/dsp.h index 61d9073..be3e21c 100644 --- a/NAM/dsp.h +++ b/NAM/dsp.h @@ -98,7 +98,7 @@ class Buffer : public DSP void SetReceptiveField(const int new_receptive_field); void ResetInputBuffer(); // Use this->_input_post_gain - virtual void _update_buffers_(float* input, int numFrames); + virtual void UpdateBuffers(float* input, int numFrames); virtual void _rewind_buffers_(); }; From 0f4e7cb57a677ee83f9fa141eb31250fbd0064fb Mon Sep 17 00:00:00 2001 From: Oli Larkin Date: Fri, 19 Jan 2024 23:46:19 +0100 Subject: [PATCH 013/133] _rewind_buffers_ RewindBuffers --- NAM/convnet.cpp | 4 ++-- NAM/convnet.h | 2 +- NAM/dsp.cpp | 4 ++-- NAM/dsp.h | 2 +- NAM/wavenet.cpp | 4 ++-- NAM/wavenet.h | 2 +- 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/NAM/convnet.cpp b/NAM/convnet.cpp index b95fee3..2c63bfe 100644 --- a/NAM/convnet.cpp +++ b/NAM/convnet.cpp @@ -162,7 +162,7 @@ void nam::convnet::ConvNet::UpdateBuffers(float* input, const int numFrames) } } -void nam::convnet::ConvNet::_rewind_buffers_() +void nam::convnet::ConvNet::RewindBuffers() { // Need to rewind the block vals first because Buffer::rewind_buffers() // resets the offset index @@ -179,5 +179,5 @@ void nam::convnet::ConvNet::_rewind_buffers_() this->_block_vals[k](r, i) = this->_block_vals[k](r, j); } // Now we can do the rest of the rewind - this->Buffer::_rewind_buffers_(); + this->Buffer::RewindBuffers(); } diff --git a/NAM/convnet.h b/NAM/convnet.h index 799c55c..273b201 100644 --- a/NAM/convnet.h +++ b/NAM/convnet.h @@ -79,7 +79,7 @@ class ConvNet : public Buffer void _verify_weights(const int channels, const std::vector& dilations, const bool batchnorm, const size_t actual_weights); void UpdateBuffers(float* input, const int numFrames) override; - void _rewind_buffers_() override; + void RewindBuffers() override; void Process(float* input, float* output, const int numFrames) override; }; diff --git a/NAM/dsp.cpp b/NAM/dsp.cpp index 09b88fb..5e9f0af 100644 --- a/NAM/dsp.cpp +++ b/NAM/dsp.cpp @@ -100,7 +100,7 @@ void nam::Buffer::UpdateBuffers(float* input, const int numFrames) // If we'd run off the end of the input buffer, then we need to move the data // back to the start of the buffer and start again. if (this->_input_buffer_offset + numFrames > (long)this->_input_buffer.size()) - this->_rewind_buffers_(); + this->RewindBuffers(); // Put the new samples into the input buffer for (long i = this->_input_buffer_offset, j = 0; j < numFrames; i++, j++) this->_input_buffer[i] = input[j]; @@ -109,7 +109,7 @@ void nam::Buffer::UpdateBuffers(float* input, const int numFrames) std::fill(this->_output_buffer.begin(), this->_output_buffer.end(), 0.0f); } -void nam::Buffer::_rewind_buffers_() +void nam::Buffer::RewindBuffers() { // Copy the input buffer back // RF-1 samples because we've got at least one new one inbound. diff --git a/NAM/dsp.h b/NAM/dsp.h index be3e21c..fc6644a 100644 --- a/NAM/dsp.h +++ b/NAM/dsp.h @@ -99,7 +99,7 @@ class Buffer : public DSP void ResetInputBuffer(); // Use this->_input_post_gain virtual void UpdateBuffers(float* input, int numFrames); - virtual void _rewind_buffers_(); + virtual void RewindBuffers(); }; // Basic linear model (an IR!) diff --git a/NAM/wavenet.cpp b/NAM/wavenet.cpp index 650a024..f806a54 100644 --- a/NAM/wavenet.cpp +++ b/NAM/wavenet.cpp @@ -99,7 +99,7 @@ void nam::wavenet::_LayerArray::prepare_for_frames_(const long numFrames) // -> No illegal writes. // -> no rewind needed. if (this->_buffer_start + numFrames > this->_get_buffer_size()) - this->_rewind_buffers_(); + this->RewindBuffers(); } void nam::wavenet::_LayerArray::process_(const Eigen::Ref layer_inputs, const Eigen::Ref condition, @@ -165,7 +165,7 @@ long nam::wavenet::_LayerArray::_get_receptive_field() const return res; } -void nam::wavenet::_LayerArray::_rewind_buffers_() +void nam::wavenet::_LayerArray::RewindBuffers() // Consider wrapping instead... // Can make this smaller--largest dilation, not receptive field! { diff --git a/NAM/wavenet.h b/NAM/wavenet.h index 8fee59a..d769c7c 100644 --- a/NAM/wavenet.h +++ b/NAM/wavenet.h @@ -135,7 +135,7 @@ class _LayerArray // TODO remove! // E.g. a 1x1 convolution has a o.i.r.f. of one. long _get_receptive_field() const; - void _rewind_buffers_(); + void RewindBuffers(); }; // The head module From 3955a2256f3d8d65e297d5b93dd62c78c8a8aa48 Mon Sep 17 00:00:00 2001 From: Oli Larkin Date: Fri, 19 Jan 2024 23:47:10 +0100 Subject: [PATCH 014/133] _input_buffer -> mInputBuffer --- NAM/convnet.cpp | 6 +++--- NAM/dsp.cpp | 18 +++++++++--------- NAM/dsp.h | 2 +- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/NAM/convnet.cpp b/NAM/convnet.cpp index 2c63bfe..7cd757b 100644 --- a/NAM/convnet.cpp +++ b/NAM/convnet.cpp @@ -104,7 +104,7 @@ nam::convnet::ConvNet::ConvNet(const int channels, const std::vector& dilat this->_block_vals.resize(this->_blocks.size() + 1); for (auto& matrix : this->_block_vals) matrix.setZero(); - std::fill(this->_input_buffer.begin(), this->_input_buffer.end(), 0.0f); + std::fill(this->mInputBuffer.begin(), this->mInputBuffer.end(), 0.0f); this->_head = _Head(channels, it); if (it != weights.end()) throw std::runtime_error("Didn't touch all the weights when initializing ConvNet"); @@ -124,7 +124,7 @@ void nam::convnet::ConvNet::Process(float* input, float* output, const int numFr const long i_end = i_start + numFrames; // TODO one unnecessary copy :/ #speed for (auto i = i_start; i < i_end; i++) - this->_block_vals[0](0, i) = this->_input_buffer[i]; + this->_block_vals[0](0, i) = this->mInputBuffer[i]; for (size_t i = 0; i < this->_blocks.size(); i++) this->_blocks[i].process_(this->_block_vals[i], this->_block_vals[i + 1], i_start, i_end); // TODO clean up this allocation @@ -144,7 +144,7 @@ void nam::convnet::ConvNet::UpdateBuffers(float* input, const int numFrames) { this->Buffer::UpdateBuffers(input, numFrames); - const size_t buffer_size = this->_input_buffer.size(); + const size_t buffer_size = this->mInputBuffer.size(); if (this->_block_vals[0].rows() != Eigen::Index(1) || this->_block_vals[0].cols() != Eigen::Index(buffer_size)) { diff --git a/NAM/dsp.cpp b/NAM/dsp.cpp index 5e9f0af..1e23e8e 100644 --- a/NAM/dsp.cpp +++ b/NAM/dsp.cpp @@ -76,8 +76,8 @@ void nam::Buffer::SetReceptiveField(const int new_receptive_field) void nam::Buffer::SetReceptiveField(const int new_receptive_field, const int input_buffer_size) { this->_receptive_field = new_receptive_field; - this->_input_buffer.resize(input_buffer_size); - std::fill(this->_input_buffer.begin(), this->_input_buffer.end(), 0.0f); + this->mInputBuffer.resize(input_buffer_size); + std::fill(this->mInputBuffer.begin(), this->mInputBuffer.end(), 0.0f); this->ResetInputBuffer(); } @@ -87,23 +87,23 @@ void nam::Buffer::UpdateBuffers(float* input, const int numFrames) // frames needed! { const long minimum_input_buffer_size = (long)this->_receptive_field + _INPUT_BUFFER_SAFETY_FACTOR * numFrames; - if ((long)this->_input_buffer.size() < minimum_input_buffer_size) + if ((long)this->mInputBuffer.size() < minimum_input_buffer_size) { long new_buffer_size = 2; while (new_buffer_size < minimum_input_buffer_size) new_buffer_size *= 2; - this->_input_buffer.resize(new_buffer_size); - std::fill(this->_input_buffer.begin(), this->_input_buffer.end(), 0.0f); + this->mInputBuffer.resize(new_buffer_size); + std::fill(this->mInputBuffer.begin(), this->mInputBuffer.end(), 0.0f); } } // If we'd run off the end of the input buffer, then we need to move the data // back to the start of the buffer and start again. - if (this->_input_buffer_offset + numFrames > (long)this->_input_buffer.size()) + if (this->_input_buffer_offset + numFrames > (long)this->mInputBuffer.size()) this->RewindBuffers(); // Put the new samples into the input buffer for (long i = this->_input_buffer_offset, j = 0; j < numFrames; i++, j++) - this->_input_buffer[i] = input[j]; + this->mInputBuffer[i] = input[j]; // And resize the output buffer: this->_output_buffer.resize(numFrames); std::fill(this->_output_buffer.begin(), this->_output_buffer.end(), 0.0f); @@ -114,7 +114,7 @@ void nam::Buffer::RewindBuffers() // Copy the input buffer back // RF-1 samples because we've got at least one new one inbound. for (long i = 0, j = this->_input_buffer_offset - this->_receptive_field; i < this->_receptive_field; i++, j++) - this->_input_buffer[i] = this->_input_buffer[j]; + this->mInputBuffer[i] = this->mInputBuffer[j]; // And reset the offset. // Even though we could be stingy about that one sample that we won't be using // (because a new set is incoming) it's probably not worth the @@ -160,7 +160,7 @@ void nam::Linear::Process(float* input, float* output, const int numFrames) for (auto i = 0; i < numFrames; i++) { const size_t offset = this->_input_buffer_offset - this->_weight.size() + i + 1; - auto input = Eigen::Map(&this->_input_buffer[offset], this->_receptive_field); + auto input = Eigen::Map(&this->mInputBuffer[offset], this->_receptive_field); output[i] = this->_bias + this->_weight.dot(input); } } diff --git a/NAM/dsp.h b/NAM/dsp.h index fc6644a..2ba58a5 100644 --- a/NAM/dsp.h +++ b/NAM/dsp.h @@ -91,7 +91,7 @@ class Buffer : public DSP int _receptive_field; // First location where we add new samples from the input long _input_buffer_offset; - std::vector _input_buffer; + std::vector mInputBuffer; std::vector _output_buffer; void SetReceptiveField(const int new_receptive_field, const int input_buffer_size); From d3068c874eb313fe86538076e62ee146063b697b Mon Sep 17 00:00:00 2001 From: Oli Larkin Date: Fri, 19 Jan 2024 23:47:44 +0100 Subject: [PATCH 015/133] _output_buffer -> mOutputBuffer --- NAM/dsp.cpp | 4 ++-- NAM/dsp.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/NAM/dsp.cpp b/NAM/dsp.cpp index 1e23e8e..b30857f 100644 --- a/NAM/dsp.cpp +++ b/NAM/dsp.cpp @@ -105,8 +105,8 @@ void nam::Buffer::UpdateBuffers(float* input, const int numFrames) for (long i = this->_input_buffer_offset, j = 0; j < numFrames; i++, j++) this->mInputBuffer[i] = input[j]; // And resize the output buffer: - this->_output_buffer.resize(numFrames); - std::fill(this->_output_buffer.begin(), this->_output_buffer.end(), 0.0f); + this->mOutputBuffer.resize(numFrames); + std::fill(this->mOutputBuffer.begin(), this->mOutputBuffer.end(), 0.0f); } void nam::Buffer::RewindBuffers() diff --git a/NAM/dsp.h b/NAM/dsp.h index 2ba58a5..a632b46 100644 --- a/NAM/dsp.h +++ b/NAM/dsp.h @@ -92,7 +92,7 @@ class Buffer : public DSP // First location where we add new samples from the input long _input_buffer_offset; std::vector mInputBuffer; - std::vector _output_buffer; + std::vector mOutputBuffer; void SetReceptiveField(const int new_receptive_field, const int input_buffer_size); void SetReceptiveField(const int new_receptive_field); From 8544e1ada2b12da1245d85f20da9ebeb28ba3c74 Mon Sep 17 00:00:00 2001 From: Oli Larkin Date: Fri, 19 Jan 2024 23:48:29 +0100 Subject: [PATCH 016/133] _input_buffer_offset --- NAM/convnet.cpp | 6 +++--- NAM/dsp.cpp | 14 +++++++------- NAM/dsp.h | 2 +- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/NAM/convnet.cpp b/NAM/convnet.cpp index 7cd757b..8ef4fff 100644 --- a/NAM/convnet.cpp +++ b/NAM/convnet.cpp @@ -120,7 +120,7 @@ void nam::convnet::ConvNet::Process(float* input, float* output, const int numFr { this->UpdateBuffers(input, numFrames); // Main computation! - const long i_start = this->_input_buffer_offset; + const long i_start = this->mInputBufferOffset; const long i_end = i_start + numFrames; // TODO one unnecessary copy :/ #speed for (auto i = i_start; i < i_end; i++) @@ -173,8 +173,8 @@ void nam::convnet::ConvNet::RewindBuffers() // We actually don't need to pull back a lot...just as far as the first // input sample would grab from dilation const long _dilation = this->_blocks[k].conv.get_dilation(); - for (long i = this->_receptive_field - _dilation, j = this->_input_buffer_offset - _dilation; - j < this->_input_buffer_offset; i++, j++) + for (long i = this->_receptive_field - _dilation, j = this->mInputBufferOffset - _dilation; + j < this->mInputBufferOffset; i++, j++) for (long r = 0; r < this->_block_vals[k].rows(); r++) this->_block_vals[k](r, i) = this->_block_vals[k](r, j); } diff --git a/NAM/dsp.cpp b/NAM/dsp.cpp index b30857f..003ea26 100644 --- a/NAM/dsp.cpp +++ b/NAM/dsp.cpp @@ -99,10 +99,10 @@ void nam::Buffer::UpdateBuffers(float* input, const int numFrames) // If we'd run off the end of the input buffer, then we need to move the data // back to the start of the buffer and start again. - if (this->_input_buffer_offset + numFrames > (long)this->mInputBuffer.size()) + if (this->mInputBufferOffset + numFrames > (long)this->mInputBuffer.size()) this->RewindBuffers(); // Put the new samples into the input buffer - for (long i = this->_input_buffer_offset, j = 0; j < numFrames; i++, j++) + for (long i = this->mInputBufferOffset, j = 0; j < numFrames; i++, j++) this->mInputBuffer[i] = input[j]; // And resize the output buffer: this->mOutputBuffer.resize(numFrames); @@ -113,25 +113,25 @@ void nam::Buffer::RewindBuffers() { // Copy the input buffer back // RF-1 samples because we've got at least one new one inbound. - for (long i = 0, j = this->_input_buffer_offset - this->_receptive_field; i < this->_receptive_field; i++, j++) + for (long i = 0, j = this->mInputBufferOffset - this->_receptive_field; i < this->_receptive_field; i++, j++) this->mInputBuffer[i] = this->mInputBuffer[j]; // And reset the offset. // Even though we could be stingy about that one sample that we won't be using // (because a new set is incoming) it's probably not worth the // hyper-optimization and liable for bugs. And the code looks way tidier this // way. - this->_input_buffer_offset = this->_receptive_field; + this->mInputBufferOffset = this->_receptive_field; } void nam::Buffer::ResetInputBuffer() { - this->_input_buffer_offset = this->_receptive_field; + this->mInputBufferOffset = this->_receptive_field; } void nam::Buffer::Finalize(const int numFrames) { this->nam::DSP::Finalize(numFrames); - this->_input_buffer_offset += numFrames; + this->mInputBufferOffset += numFrames; } // Linear ===================================================================== @@ -159,7 +159,7 @@ void nam::Linear::Process(float* input, float* output, const int numFrames) // Main computation! for (auto i = 0; i < numFrames; i++) { - const size_t offset = this->_input_buffer_offset - this->_weight.size() + i + 1; + const size_t offset = this->mInputBufferOffset - this->_weight.size() + i + 1; auto input = Eigen::Map(&this->mInputBuffer[offset], this->_receptive_field); output[i] = this->_bias + this->_weight.dot(input); } diff --git a/NAM/dsp.h b/NAM/dsp.h index a632b46..26821e6 100644 --- a/NAM/dsp.h +++ b/NAM/dsp.h @@ -90,7 +90,7 @@ class Buffer : public DSP const int _input_buffer_channels = 1; // Mono int _receptive_field; // First location where we add new samples from the input - long _input_buffer_offset; + long mInputBufferOffset; std::vector mInputBuffer; std::vector mOutputBuffer; From dadb1a774c21d0ffe4f475b3f90379317b0f4174 Mon Sep 17 00:00:00 2001 From: Oli Larkin Date: Fri, 19 Jan 2024 23:48:52 +0100 Subject: [PATCH 017/133] mReceptiveField --- NAM/convnet.cpp | 2 +- NAM/dsp.cpp | 16 ++++++++-------- NAM/dsp.h | 2 +- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/NAM/convnet.cpp b/NAM/convnet.cpp index 8ef4fff..ace0b23 100644 --- a/NAM/convnet.cpp +++ b/NAM/convnet.cpp @@ -173,7 +173,7 @@ void nam::convnet::ConvNet::RewindBuffers() // We actually don't need to pull back a lot...just as far as the first // input sample would grab from dilation const long _dilation = this->_blocks[k].conv.get_dilation(); - for (long i = this->_receptive_field - _dilation, j = this->mInputBufferOffset - _dilation; + for (long i = this->mReceptiveField - _dilation, j = this->mInputBufferOffset - _dilation; j < this->mInputBufferOffset; i++, j++) for (long r = 0; r < this->_block_vals[k].rows(); r++) this->_block_vals[k](r, i) = this->_block_vals[k](r, j); diff --git a/NAM/dsp.cpp b/NAM/dsp.cpp index 003ea26..3e47bfd 100644 --- a/NAM/dsp.cpp +++ b/NAM/dsp.cpp @@ -75,7 +75,7 @@ void nam::Buffer::SetReceptiveField(const int new_receptive_field) void nam::Buffer::SetReceptiveField(const int new_receptive_field, const int input_buffer_size) { - this->_receptive_field = new_receptive_field; + this->mReceptiveField = new_receptive_field; this->mInputBuffer.resize(input_buffer_size); std::fill(this->mInputBuffer.begin(), this->mInputBuffer.end(), 0.0f); this->ResetInputBuffer(); @@ -86,7 +86,7 @@ void nam::Buffer::UpdateBuffers(float* input, const int numFrames) // Make sure that the buffer is big enough for the receptive field and the // frames needed! { - const long minimum_input_buffer_size = (long)this->_receptive_field + _INPUT_BUFFER_SAFETY_FACTOR * numFrames; + const long minimum_input_buffer_size = (long)this->mReceptiveField + _INPUT_BUFFER_SAFETY_FACTOR * numFrames; if ((long)this->mInputBuffer.size() < minimum_input_buffer_size) { long new_buffer_size = 2; @@ -113,19 +113,19 @@ void nam::Buffer::RewindBuffers() { // Copy the input buffer back // RF-1 samples because we've got at least one new one inbound. - for (long i = 0, j = this->mInputBufferOffset - this->_receptive_field; i < this->_receptive_field; i++, j++) + for (long i = 0, j = this->mInputBufferOffset - this->mReceptiveField; i < this->mReceptiveField; i++, j++) this->mInputBuffer[i] = this->mInputBuffer[j]; // And reset the offset. // Even though we could be stingy about that one sample that we won't be using // (because a new set is incoming) it's probably not worth the // hyper-optimization and liable for bugs. And the code looks way tidier this // way. - this->mInputBufferOffset = this->_receptive_field; + this->mInputBufferOffset = this->mReceptiveField; } void nam::Buffer::ResetInputBuffer() { - this->mInputBufferOffset = this->_receptive_field; + this->mInputBufferOffset = this->mReceptiveField; } void nam::Buffer::Finalize(const int numFrames) @@ -145,9 +145,9 @@ nam::Linear::Linear(const int receptive_field, const bool _bias, const std::vect "Params vector does not match expected size based " "on architecture parameters"); - this->_weight.resize(this->_receptive_field); + this->_weight.resize(this->mReceptiveField); // Pass in in reverse order so that dot products work out of the box. - for (int i = 0; i < this->_receptive_field; i++) + for (int i = 0; i < this->mReceptiveField; i++) this->_weight(i) = weights[receptive_field - 1 - i]; this->_bias = _bias ? weights[receptive_field] : (float)0.0; } @@ -160,7 +160,7 @@ void nam::Linear::Process(float* input, float* output, const int numFrames) for (auto i = 0; i < numFrames; i++) { const size_t offset = this->mInputBufferOffset - this->_weight.size() + i + 1; - auto input = Eigen::Map(&this->mInputBuffer[offset], this->_receptive_field); + auto input = Eigen::Map(&this->mInputBuffer[offset], this->mReceptiveField); output[i] = this->_bias + this->_weight.dot(input); } } diff --git a/NAM/dsp.h b/NAM/dsp.h index 26821e6..4c35b7e 100644 --- a/NAM/dsp.h +++ b/NAM/dsp.h @@ -88,7 +88,7 @@ class Buffer : public DSP protected: // Input buffer const int _input_buffer_channels = 1; // Mono - int _receptive_field; + int mReceptiveField; // First location where we add new samples from the input long mInputBufferOffset; std::vector mInputBuffer; From 056777a4740eb5d0cc485ed640d0240fe5bff7e6 Mon Sep 17 00:00:00 2001 From: Oli Larkin Date: Fri, 19 Jan 2024 23:49:26 +0100 Subject: [PATCH 018/133] Remove unused _input_buffer_channels --- NAM/dsp.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/NAM/dsp.h b/NAM/dsp.h index 4c35b7e..c416599 100644 --- a/NAM/dsp.h +++ b/NAM/dsp.h @@ -86,8 +86,6 @@ class Buffer : public DSP void Finalize(const int numFrames); protected: - // Input buffer - const int _input_buffer_channels = 1; // Mono int mReceptiveField; // First location where we add new samples from the input long mInputBufferOffset; From 53b2915bfbf6658a238bb98e9d87567e2319502d Mon Sep 17 00:00:00 2001 From: Oli Larkin Date: Fri, 19 Jan 2024 23:50:25 +0100 Subject: [PATCH 019/133] newReceptiveField --- NAM/dsp.cpp | 8 ++++---- NAM/dsp.h | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/NAM/dsp.cpp b/NAM/dsp.cpp index 3e47bfd..e7ad686 100644 --- a/NAM/dsp.cpp +++ b/NAM/dsp.cpp @@ -68,14 +68,14 @@ nam::Buffer::Buffer(const int receptive_field, const double expected_sample_rate this->SetReceptiveField(receptive_field); } -void nam::Buffer::SetReceptiveField(const int new_receptive_field) +void nam::Buffer::SetReceptiveField(const int newReceptiveField) { - this->SetReceptiveField(new_receptive_field, _INPUT_BUFFER_SAFETY_FACTOR * new_receptive_field); + this->SetReceptiveField(newReceptiveField, _INPUT_BUFFER_SAFETY_FACTOR * newReceptiveField); }; -void nam::Buffer::SetReceptiveField(const int new_receptive_field, const int input_buffer_size) +void nam::Buffer::SetReceptiveField(const int newReceptiveField, const int input_buffer_size) { - this->mReceptiveField = new_receptive_field; + this->mReceptiveField = newReceptiveField; this->mInputBuffer.resize(input_buffer_size); std::fill(this->mInputBuffer.begin(), this->mInputBuffer.end(), 0.0f); this->ResetInputBuffer(); diff --git a/NAM/dsp.h b/NAM/dsp.h index c416599..b36deae 100644 --- a/NAM/dsp.h +++ b/NAM/dsp.h @@ -92,8 +92,8 @@ class Buffer : public DSP std::vector mInputBuffer; std::vector mOutputBuffer; - void SetReceptiveField(const int new_receptive_field, const int input_buffer_size); - void SetReceptiveField(const int new_receptive_field); + void SetReceptiveField(const int newReceptiveField, const int input_buffer_size); + void SetReceptiveField(const int newReceptiveField); void ResetInputBuffer(); // Use this->_input_post_gain virtual void UpdateBuffers(float* input, int numFrames); From df723f754d204c96dce45b77ee05e1b2d2f3ad7e Mon Sep 17 00:00:00 2001 From: Oli Larkin Date: Fri, 19 Jan 2024 23:50:45 +0100 Subject: [PATCH 020/133] input_buffer_size --- NAM/dsp.cpp | 4 ++-- NAM/dsp.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/NAM/dsp.cpp b/NAM/dsp.cpp index e7ad686..906aa9f 100644 --- a/NAM/dsp.cpp +++ b/NAM/dsp.cpp @@ -73,10 +73,10 @@ void nam::Buffer::SetReceptiveField(const int newReceptiveField) this->SetReceptiveField(newReceptiveField, _INPUT_BUFFER_SAFETY_FACTOR * newReceptiveField); }; -void nam::Buffer::SetReceptiveField(const int newReceptiveField, const int input_buffer_size) +void nam::Buffer::SetReceptiveField(const int newReceptiveField, const int inputBufferSize) { this->mReceptiveField = newReceptiveField; - this->mInputBuffer.resize(input_buffer_size); + this->mInputBuffer.resize(inputBufferSize); std::fill(this->mInputBuffer.begin(), this->mInputBuffer.end(), 0.0f); this->ResetInputBuffer(); } diff --git a/NAM/dsp.h b/NAM/dsp.h index b36deae..197930d 100644 --- a/NAM/dsp.h +++ b/NAM/dsp.h @@ -92,7 +92,7 @@ class Buffer : public DSP std::vector mInputBuffer; std::vector mOutputBuffer; - void SetReceptiveField(const int newReceptiveField, const int input_buffer_size); + void SetReceptiveField(const int newReceptiveField, const int inputBufferSize); void SetReceptiveField(const int newReceptiveField); void ResetInputBuffer(); // Use this->_input_post_gain From 86a9ca43f8af6a7d0b9dbc4fd6c3bc5fff50b01d Mon Sep 17 00:00:00 2001 From: Oli Larkin Date: Fri, 19 Jan 2024 23:51:14 +0100 Subject: [PATCH 021/133] receptive_field --- NAM/dsp.cpp | 14 +++++++------- NAM/dsp.h | 4 ++-- NAM/get_dsp.cpp | 4 ++-- NAM/wavenet.cpp | 4 ++-- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/NAM/dsp.cpp b/NAM/dsp.cpp index 906aa9f..8b3b871 100644 --- a/NAM/dsp.cpp +++ b/NAM/dsp.cpp @@ -62,10 +62,10 @@ void nam::DSP::Finalize(const int numFrames) {} // Buffer ===================================================================== -nam::Buffer::Buffer(const int receptive_field, const double expected_sample_rate) +nam::Buffer::Buffer(const int receptiveField, const double expected_sample_rate) : nam::DSP(expected_sample_rate) { - this->SetReceptiveField(receptive_field); + this->SetReceptiveField(receptiveField); } void nam::Buffer::SetReceptiveField(const int newReceptiveField) @@ -136,11 +136,11 @@ void nam::Buffer::Finalize(const int numFrames) // Linear ===================================================================== -nam::Linear::Linear(const int receptive_field, const bool _bias, const std::vector& weights, +nam::Linear::Linear(const int receptiveField, const bool _bias, const std::vector& weights, const double expected_sample_rate) -: nam::Buffer(receptive_field, expected_sample_rate) +: nam::Buffer(receptiveField, expected_sample_rate) { - if ((int)weights.size() != (receptive_field + (_bias ? 1 : 0))) + if ((int)weights.size() != (receptiveField + (_bias ? 1 : 0))) throw std::runtime_error( "Params vector does not match expected size based " "on architecture parameters"); @@ -148,8 +148,8 @@ nam::Linear::Linear(const int receptive_field, const bool _bias, const std::vect this->_weight.resize(this->mReceptiveField); // Pass in in reverse order so that dot products work out of the box. for (int i = 0; i < this->mReceptiveField; i++) - this->_weight(i) = weights[receptive_field - 1 - i]; - this->_bias = _bias ? weights[receptive_field] : (float)0.0; + this->_weight(i) = weights[receptiveField - 1 - i]; + this->_bias = _bias ? weights[receptiveField] : (float)0.0; } void nam::Linear::Process(float* input, float* output, const int numFrames) diff --git a/NAM/dsp.h b/NAM/dsp.h index 197930d..3ad4213 100644 --- a/NAM/dsp.h +++ b/NAM/dsp.h @@ -82,7 +82,7 @@ class DSP class Buffer : public DSP { public: - Buffer(const int receptive_field, const double expected_sample_rate = -1.0); + Buffer(const int receptiveField, const double expected_sample_rate = -1.0); void Finalize(const int numFrames); protected: @@ -104,7 +104,7 @@ class Buffer : public DSP class Linear : public Buffer { public: - Linear(const int receptive_field, const bool _bias, const std::vector& weights, + Linear(const int receptiveField, const bool _bias, const std::vector& weights, const double expected_sample_rate = -1.0); void Process(float* input, float* output, const int numFrames) override; diff --git a/NAM/get_dsp.cpp b/NAM/get_dsp.cpp index d848046..08acec4 100644 --- a/NAM/get_dsp.cpp +++ b/NAM/get_dsp.cpp @@ -145,9 +145,9 @@ std::unique_ptr get_dsp(dspData& conf) std::unique_ptr out = nullptr; if (architecture == "Linear") { - const int receptive_field = config["receptive_field"]; + const int receptiveField = config["receptiveField"]; const bool _bias = config["bias"]; - out = std::make_unique(receptive_field, _bias, weights, expectedSampleRate); + out = std::make_unique(receptiveField, _bias, weights, expectedSampleRate); } else if (architecture == "ConvNet") { diff --git a/NAM/wavenet.cpp b/NAM/wavenet.cpp index f806a54..1ce5ecc 100644 --- a/NAM/wavenet.cpp +++ b/NAM/wavenet.cpp @@ -67,10 +67,10 @@ nam::wavenet::_LayerArray::_LayerArray(const int input_size, const int condition { for (size_t i = 0; i < dilations.size(); i++) this->_layers.push_back(_Layer(condition_size, channels, kernel_size, dilations[i], activation, gated)); - const long receptive_field = this->_get_receptive_field(); + const long receptiveField = this->_get_receptive_field(); for (size_t i = 0; i < dilations.size(); i++) { - this->_layer_buffers.push_back(Eigen::MatrixXf(channels, LAYER_ARRAY_BUFFER_SIZE + receptive_field - 1)); + this->_layer_buffers.push_back(Eigen::MatrixXf(channels, LAYER_ARRAY_BUFFER_SIZE + receptiveField - 1)); this->_layer_buffers[i].setZero(); } this->_buffer_start = this->_get_receptive_field() - 1; From 5c515d8153527d95ba2a3181a503c418b5992158 Mon Sep 17 00:00:00 2001 From: Oli Larkin Date: Fri, 19 Jan 2024 23:51:37 +0100 Subject: [PATCH 022/133] expectedSampleRate --- NAM/convnet.cpp | 4 ++-- NAM/convnet.h | 2 +- NAM/dsp.cpp | 12 ++++++------ NAM/dsp.h | 10 +++++----- NAM/get_dsp.cpp | 6 +++--- NAM/lstm.cpp | 4 ++-- NAM/lstm.h | 2 +- NAM/wavenet.cpp | 4 ++-- NAM/wavenet.h | 2 +- 9 files changed, 23 insertions(+), 23 deletions(-) diff --git a/NAM/convnet.cpp b/NAM/convnet.cpp index ace0b23..8640718 100644 --- a/NAM/convnet.cpp +++ b/NAM/convnet.cpp @@ -93,8 +93,8 @@ void nam::convnet::_Head::process_(const Eigen::Ref input nam::convnet::ConvNet::ConvNet(const int channels, const std::vector& dilations, const bool batchnorm, const std::string activation, std::vector& weights, - const double expected_sample_rate) -: Buffer(*std::max_element(dilations.begin(), dilations.end()), expected_sample_rate) + const double expectedSampleRate) +: Buffer(*std::max_element(dilations.begin(), dilations.end()), expectedSampleRate) { this->_verify_weights(channels, dilations, batchnorm, weights.size()); this->_blocks.resize(dilations.size()); diff --git a/NAM/convnet.h b/NAM/convnet.h index 273b201..eaeb282 100644 --- a/NAM/convnet.h +++ b/NAM/convnet.h @@ -68,7 +68,7 @@ class ConvNet : public Buffer { public: ConvNet(const int channels, const std::vector& dilations, const bool batchnorm, const std::string activation, - std::vector& weights, const double expected_sample_rate = -1.0); + std::vector& weights, const double expectedSampleRate = -1.0); ~ConvNet() = default; protected: diff --git a/NAM/dsp.cpp b/NAM/dsp.cpp index 8b3b871..116d423 100644 --- a/NAM/dsp.cpp +++ b/NAM/dsp.cpp @@ -14,8 +14,8 @@ constexpr const long _INPUT_BUFFER_SAFETY_FACTOR = 32; -nam::DSP::DSP(const double expected_sample_rate) -: mExpectedSampleRate(expected_sample_rate) +nam::DSP::DSP(const double expectedSampleRate) +: mExpectedSampleRate(expectedSampleRate) { } @@ -62,8 +62,8 @@ void nam::DSP::Finalize(const int numFrames) {} // Buffer ===================================================================== -nam::Buffer::Buffer(const int receptiveField, const double expected_sample_rate) -: nam::DSP(expected_sample_rate) +nam::Buffer::Buffer(const int receptiveField, const double expectedSampleRate) +: nam::DSP(expectedSampleRate) { this->SetReceptiveField(receptiveField); } @@ -137,8 +137,8 @@ void nam::Buffer::Finalize(const int numFrames) // Linear ===================================================================== nam::Linear::Linear(const int receptiveField, const bool _bias, const std::vector& weights, - const double expected_sample_rate) -: nam::Buffer(receptiveField, expected_sample_rate) + const double expectedSampleRate) +: nam::Buffer(receptiveField, expectedSampleRate) { if ((int)weights.size() != (receptiveField + (_bias ? 1 : 0))) throw std::runtime_error( diff --git a/NAM/dsp.h b/NAM/dsp.h index 3ad4213..e7a8d45 100644 --- a/NAM/dsp.h +++ b/NAM/dsp.h @@ -37,7 +37,7 @@ class DSP // Older models won't know, but newer ones will come with a loudness from the training based on their response to a // standardized input. // We may choose to have the models figure out for themselves how loud they are in here in the future. - DSP(const double expected_sample_rate); + DSP(const double expectedSampleRate); virtual ~DSP() = default; // Prewarm() does any required intial work required to "settle" model initial conditions // it can be somewhat expensive, so should not be called during realtime audio processing @@ -82,7 +82,7 @@ class DSP class Buffer : public DSP { public: - Buffer(const int receptiveField, const double expected_sample_rate = -1.0); + Buffer(const int receptiveField, const double expectedSampleRate = -1.0); void Finalize(const int numFrames); protected: @@ -105,7 +105,7 @@ class Linear : public Buffer { public: Linear(const int receptiveField, const bool _bias, const std::vector& weights, - const double expected_sample_rate = -1.0); + const double expectedSampleRate = -1.0); void Process(float* input, float* output, const int numFrames) override; protected: @@ -176,7 +176,7 @@ class Conv1x1 // :param config: // :param metadata: // :param weights: The model weights -// :param expected_sample_rate: Most NAM models implicitly assume that data will be provided to them at some sample +// :param expectedSampleRate: Most NAM models implicitly assume that data will be provided to them at some sample // rate. This captures it for other components interfacing with the model to understand its needs. Use -1.0 for "I // don't know". struct dspData @@ -186,7 +186,7 @@ struct dspData nlohmann::json config; nlohmann::json metadata; std::vector weights; - double expected_sample_rate; + double expectedSampleRate; }; // Verify that the config that we are building our model from is supported by diff --git a/NAM/get_dsp.cpp b/NAM/get_dsp.cpp index 08acec4..46a5c5d 100644 --- a/NAM/get_dsp.cpp +++ b/NAM/get_dsp.cpp @@ -106,10 +106,10 @@ std::unique_ptr get_dsp(const std::filesystem::path config_filename, dspDat returnedConfig.metadata = j["metadata"]; returnedConfig.weights = weights; if (j.find("sample_rate") != j.end()) - returnedConfig.expected_sample_rate = j["sample_rate"]; + returnedConfig.expectedSampleRate = j["sample_rate"]; else { - returnedConfig.expected_sample_rate = -1.0; + returnedConfig.expectedSampleRate = -1.0; } @@ -140,7 +140,7 @@ std::unique_ptr get_dsp(dspData& conf) haveLoudness = true; } } - const double expectedSampleRate = conf.expected_sample_rate; + const double expectedSampleRate = conf.expectedSampleRate; std::unique_ptr out = nullptr; if (architecture == "Linear") diff --git a/NAM/lstm.cpp b/NAM/lstm.cpp index 61dc786..8aad57f 100644 --- a/NAM/lstm.cpp +++ b/NAM/lstm.cpp @@ -65,8 +65,8 @@ void nam::lstm::LSTMCell::process_(const Eigen::VectorXf& x) } nam::lstm::LSTM::LSTM(const int num_layers, const int input_size, const int hidden_size, const std::vector& weights, - const double expected_sample_rate) -: DSP(expected_sample_rate) + const double expectedSampleRate) +: DSP(expectedSampleRate) { this->_input.resize(1); auto it = weights.begin(); diff --git a/NAM/lstm.h b/NAM/lstm.h index 670f252..7bb9806 100644 --- a/NAM/lstm.h +++ b/NAM/lstm.h @@ -51,7 +51,7 @@ class LSTM : public DSP { public: LSTM(const int num_layers, const int input_size, const int hidden_size, const std::vector& weights, - const double expected_sample_rate = -1.0); + const double expectedSampleRate = -1.0); ~LSTM() = default; protected: diff --git a/NAM/wavenet.cpp b/NAM/wavenet.cpp index 1ce5ecc..bb58044 100644 --- a/NAM/wavenet.cpp +++ b/NAM/wavenet.cpp @@ -242,8 +242,8 @@ void nam::wavenet::_Head::_apply_activation_(Eigen::Ref x) nam::wavenet::WaveNet::WaveNet(const std::vector& layer_array_params, const float head_scale, const bool with_head, const std::vector& weights, - const double expected_sample_rate) -: DSP(expected_sample_rate) + const double expectedSampleRate) +: DSP(expectedSampleRate) , _num_frames(0) , _head_scale(head_scale) { diff --git a/NAM/wavenet.h b/NAM/wavenet.h index d769c7c..e2e57d1 100644 --- a/NAM/wavenet.h +++ b/NAM/wavenet.h @@ -169,7 +169,7 @@ class WaveNet : public DSP { public: WaveNet(const std::vector& layer_array_params, const float head_scale, const bool with_head, - const std::vector& weights, const double expected_sample_rate = -1.0); + const std::vector& weights, const double expectedSampleRate = -1.0); ~WaveNet() = default; void Finalize(const int numFrames) override; From 1fc8ec1de3b8951bb001bc798b1ea0eabb401f73 Mon Sep 17 00:00:00 2001 From: Oli Larkin Date: Fri, 19 Jan 2024 23:52:45 +0100 Subject: [PATCH 023/133] mBias --- NAM/convnet.cpp | 4 ++-- NAM/convnet.h | 2 +- NAM/dsp.cpp | 26 +++++++++++++------------- NAM/dsp.h | 6 +++--- 4 files changed, 19 insertions(+), 19 deletions(-) diff --git a/NAM/convnet.cpp b/NAM/convnet.cpp index 8640718..b29423a 100644 --- a/NAM/convnet.cpp +++ b/NAM/convnet.cpp @@ -79,7 +79,7 @@ nam::convnet::_Head::_Head(const int channels, weights_it& weights) this->_weight.resize(channels); for (int i = 0; i < channels; i++) this->_weight[i] = *(weights++); - this->_bias = *(weights++); + this->mBias = *(weights++); } void nam::convnet::_Head::process_(const Eigen::Ref input, Eigen::VectorXf& output, const long i_start, @@ -88,7 +88,7 @@ void nam::convnet::_Head::process_(const Eigen::Ref input const long length = i_end - i_start; output.resize(length); for (long i = 0, j = i_start; i < length; i++, j++) - output(i) = this->_bias + input.col(j).dot(this->_weight); + output(i) = this->mBias + input.col(j).dot(this->_weight); } nam::convnet::ConvNet::ConvNet(const int channels, const std::vector& dilations, const bool batchnorm, diff --git a/NAM/convnet.h b/NAM/convnet.h index eaeb282..5ebb577 100644 --- a/NAM/convnet.h +++ b/NAM/convnet.h @@ -61,7 +61,7 @@ class _Head private: Eigen::VectorXf _weight; - float _bias = 0.0f; + float mBias = 0.0f; }; class ConvNet : public Buffer diff --git a/NAM/dsp.cpp b/NAM/dsp.cpp index 116d423..9ae2552 100644 --- a/NAM/dsp.cpp +++ b/NAM/dsp.cpp @@ -149,7 +149,7 @@ nam::Linear::Linear(const int receptiveField, const bool _bias, const std::vecto // Pass in in reverse order so that dot products work out of the box. for (int i = 0; i < this->mReceptiveField; i++) this->_weight(i) = weights[receptiveField - 1 - i]; - this->_bias = _bias ? weights[receptiveField] : (float)0.0; + this->mBias = _bias ? weights[receptiveField] : (float)0.0; } void nam::Linear::Process(float* input, float* output, const int numFrames) @@ -161,7 +161,7 @@ void nam::Linear::Process(float* input, float* output, const int numFrames) { const size_t offset = this->mInputBufferOffset - this->_weight.size() + i + 1; auto input = Eigen::Map(&this->mInputBuffer[offset], this->mReceptiveField); - output[i] = this->_bias + this->_weight.dot(input); + output[i] = this->mBias + this->_weight.dot(input); } } @@ -179,8 +179,8 @@ void nam::Conv1D::set_weights_(weights_it& weights) for (size_t k = 0; k < this->_weight.size(); k++) this->_weight[k](i, j) = *(weights++); } - for (long i = 0; i < this->_bias.size(); i++) - this->_bias(i) = *(weights++); + for (long i = 0; i < this->mBias.size(); i++) + this->mBias(i) = *(weights++); } void nam::Conv1D::set_size_(const int in_channels, const int out_channels, const int kernel_size, const bool do_bias, @@ -191,9 +191,9 @@ void nam::Conv1D::set_size_(const int in_channels, const int out_channels, const this->_weight[i].resize(out_channels, in_channels); // y = Ax, input array (C,L) if (do_bias) - this->_bias.resize(out_channels); + this->mBias.resize(out_channels); else - this->_bias.resize(0); + this->mBias.resize(0); this->_dilation = _dilation; } @@ -216,13 +216,13 @@ void nam::Conv1D::process_(const Eigen::Ref input, Eigen: else output.middleCols(j_start, ncols) += this->_weight[k] * input.middleCols(i_start + offset, ncols); } - if (this->_bias.size() > 0) - output.middleCols(j_start, ncols).colwise() += this->_bias; + if (this->mBias.size() > 0) + output.middleCols(j_start, ncols).colwise() += this->mBias; } long nam::Conv1D::get_num_weights() const { - long num_weights = this->_bias.size(); + long num_weights = this->mBias.size(); for (size_t i = 0; i < this->_weight.size(); i++) num_weights += this->_weight[i].size(); return num_weights; @@ -233,7 +233,7 @@ nam::Conv1x1::Conv1x1(const int in_channels, const int out_channels, const bool this->_weight.resize(out_channels, in_channels); this->_do_bias = _bias; if (_bias) - this->_bias.resize(out_channels); + this->mBias.resize(out_channels); } void nam::Conv1x1::set_weights_(weights_it& weights) @@ -242,14 +242,14 @@ void nam::Conv1x1::set_weights_(weights_it& weights) for (int j = 0; j < this->_weight.cols(); j++) this->_weight(i, j) = *(weights++); if (this->_do_bias) - for (int i = 0; i < this->_bias.size(); i++) - this->_bias(i) = *(weights++); + for (int i = 0; i < this->mBias.size(); i++) + this->mBias(i) = *(weights++); } Eigen::MatrixXf nam::Conv1x1::Process(const Eigen::Ref input) const { if (this->_do_bias) - return (this->_weight * input).colwise() + this->_bias; + return (this->_weight * input).colwise() + this->mBias; else return this->_weight * input; } diff --git a/NAM/dsp.h b/NAM/dsp.h index e7a8d45..2393993 100644 --- a/NAM/dsp.h +++ b/NAM/dsp.h @@ -110,7 +110,7 @@ class Linear : public Buffer protected: Eigen::VectorXf _weight; - float _bias; + float mBias; }; // NN modules ================================================================= @@ -139,7 +139,7 @@ class Conv1D // Gonna wing this... // conv[kernel](cout, cin) std::vector _weight; - Eigen::VectorXf _bias; + Eigen::VectorXf mBias; int _dilation; }; @@ -157,7 +157,7 @@ class Conv1x1 private: Eigen::MatrixXf _weight; - Eigen::VectorXf _bias; + Eigen::VectorXf mBias; bool _do_bias; }; From b997c70139d9ea32fdb6a2c31127ad32d6d3d611 Mon Sep 17 00:00:00 2001 From: Oli Larkin Date: Fri, 19 Jan 2024 23:59:30 +0100 Subject: [PATCH 024/133] mWeight --- NAM/convnet.cpp | 6 +++--- NAM/convnet.h | 2 +- NAM/dsp.cpp | 48 ++++++++++++++++++++++++------------------------ NAM/dsp.h | 14 +++++++------- 4 files changed, 35 insertions(+), 35 deletions(-) diff --git a/NAM/convnet.cpp b/NAM/convnet.cpp index b29423a..f4e535a 100644 --- a/NAM/convnet.cpp +++ b/NAM/convnet.cpp @@ -76,9 +76,9 @@ long nam::convnet::ConvNetBlock::get_out_channels() const nam::convnet::_Head::_Head(const int channels, weights_it& weights) { - this->_weight.resize(channels); + this->mWeight.resize(channels); for (int i = 0; i < channels; i++) - this->_weight[i] = *(weights++); + this->mWeight[i] = *(weights++); this->mBias = *(weights++); } @@ -88,7 +88,7 @@ void nam::convnet::_Head::process_(const Eigen::Ref input const long length = i_end - i_start; output.resize(length); for (long i = 0, j = i_start; i < length; i++, j++) - output(i) = this->mBias + input.col(j).dot(this->_weight); + output(i) = this->mBias + input.col(j).dot(this->mWeight); } nam::convnet::ConvNet::ConvNet(const int channels, const std::vector& dilations, const bool batchnorm, diff --git a/NAM/convnet.h b/NAM/convnet.h index 5ebb577..0d3f93a 100644 --- a/NAM/convnet.h +++ b/NAM/convnet.h @@ -60,7 +60,7 @@ class _Head void process_(const Eigen::Ref input, Eigen::VectorXf& output, const long i_start, const long i_end) const; private: - Eigen::VectorXf _weight; + Eigen::VectorXf mWeight; float mBias = 0.0f; }; diff --git a/NAM/dsp.cpp b/NAM/dsp.cpp index 9ae2552..b4c7d0e 100644 --- a/NAM/dsp.cpp +++ b/NAM/dsp.cpp @@ -145,10 +145,10 @@ nam::Linear::Linear(const int receptiveField, const bool _bias, const std::vecto "Params vector does not match expected size based " "on architecture parameters"); - this->_weight.resize(this->mReceptiveField); + this->mWeight.resize(this->mReceptiveField); // Pass in in reverse order so that dot products work out of the box. for (int i = 0; i < this->mReceptiveField; i++) - this->_weight(i) = weights[receptiveField - 1 - i]; + this->mWeight(i) = weights[receptiveField - 1 - i]; this->mBias = _bias ? weights[receptiveField] : (float)0.0; } @@ -159,9 +159,9 @@ void nam::Linear::Process(float* input, float* output, const int numFrames) // Main computation! for (auto i = 0; i < numFrames; i++) { - const size_t offset = this->mInputBufferOffset - this->_weight.size() + i + 1; + const size_t offset = this->mInputBufferOffset - this->mWeight.size() + i + 1; auto input = Eigen::Map(&this->mInputBuffer[offset], this->mReceptiveField); - output[i] = this->mBias + this->_weight.dot(input); + output[i] = this->mBias + this->mWeight.dot(input); } } @@ -169,15 +169,15 @@ void nam::Linear::Process(float* input, float* output, const int numFrames) void nam::Conv1D::set_weights_(weights_it& weights) { - if (this->_weight.size() > 0) + if (this->mWeight.size() > 0) { - const long out_channels = this->_weight[0].rows(); - const long in_channels = this->_weight[0].cols(); + const long out_channels = this->mWeight[0].rows(); + const long in_channels = this->mWeight[0].cols(); // Crazy ordering because that's how it gets flattened. for (auto i = 0; i < out_channels; i++) for (auto j = 0; j < in_channels; j++) - for (size_t k = 0; k < this->_weight.size(); k++) - this->_weight[k](i, j) = *(weights++); + for (size_t k = 0; k < this->mWeight.size(); k++) + this->mWeight[k](i, j) = *(weights++); } for (long i = 0; i < this->mBias.size(); i++) this->mBias(i) = *(weights++); @@ -186,9 +186,9 @@ void nam::Conv1D::set_weights_(weights_it& weights) void nam::Conv1D::set_size_(const int in_channels, const int out_channels, const int kernel_size, const bool do_bias, const int _dilation) { - this->_weight.resize(kernel_size); - for (size_t i = 0; i < this->_weight.size(); i++) - this->_weight[i].resize(out_channels, + this->mWeight.resize(kernel_size); + for (size_t i = 0; i < this->mWeight.size(); i++) + this->mWeight[i].resize(out_channels, in_channels); // y = Ax, input array (C,L) if (do_bias) this->mBias.resize(out_channels); @@ -208,13 +208,13 @@ void nam::Conv1D::process_(const Eigen::Ref input, Eigen: const long j_start) const { // This is the clever part ;) - for (size_t k = 0; k < this->_weight.size(); k++) + for (size_t k = 0; k < this->mWeight.size(); k++) { - const long offset = this->_dilation * (k + 1 - this->_weight.size()); + const long offset = this->_dilation * (k + 1 - this->mWeight.size()); if (k == 0) - output.middleCols(j_start, ncols) = this->_weight[k] * input.middleCols(i_start + offset, ncols); + output.middleCols(j_start, ncols) = this->mWeight[k] * input.middleCols(i_start + offset, ncols); else - output.middleCols(j_start, ncols) += this->_weight[k] * input.middleCols(i_start + offset, ncols); + output.middleCols(j_start, ncols) += this->mWeight[k] * input.middleCols(i_start + offset, ncols); } if (this->mBias.size() > 0) output.middleCols(j_start, ncols).colwise() += this->mBias; @@ -223,14 +223,14 @@ void nam::Conv1D::process_(const Eigen::Ref input, Eigen: long nam::Conv1D::get_num_weights() const { long num_weights = this->mBias.size(); - for (size_t i = 0; i < this->_weight.size(); i++) - num_weights += this->_weight[i].size(); + for (size_t i = 0; i < this->mWeight.size(); i++) + num_weights += this->mWeight[i].size(); return num_weights; } nam::Conv1x1::Conv1x1(const int in_channels, const int out_channels, const bool _bias) { - this->_weight.resize(out_channels, in_channels); + this->mWeight.resize(out_channels, in_channels); this->_do_bias = _bias; if (_bias) this->mBias.resize(out_channels); @@ -238,9 +238,9 @@ nam::Conv1x1::Conv1x1(const int in_channels, const int out_channels, const bool void nam::Conv1x1::set_weights_(weights_it& weights) { - for (int i = 0; i < this->_weight.rows(); i++) - for (int j = 0; j < this->_weight.cols(); j++) - this->_weight(i, j) = *(weights++); + for (int i = 0; i < this->mWeight.rows(); i++) + for (int j = 0; j < this->mWeight.cols(); j++) + this->mWeight(i, j) = *(weights++); if (this->_do_bias) for (int i = 0; i < this->mBias.size(); i++) this->mBias(i) = *(weights++); @@ -249,7 +249,7 @@ void nam::Conv1x1::set_weights_(weights_it& weights) Eigen::MatrixXf nam::Conv1x1::Process(const Eigen::Ref input) const { if (this->_do_bias) - return (this->_weight * input).colwise() + this->mBias; + return (this->mWeight * input).colwise() + this->mBias; else - return this->_weight * input; + return this->mWeight * input; } diff --git a/NAM/dsp.h b/NAM/dsp.h index 2393993..c0352c3 100644 --- a/NAM/dsp.h +++ b/NAM/dsp.h @@ -109,7 +109,7 @@ class Linear : public Buffer void Process(float* input, float* output, const int numFrames) override; protected: - Eigen::VectorXf _weight; + Eigen::VectorXf mWeight; float mBias; }; @@ -129,16 +129,16 @@ class Conv1D // Indices on output for from j_start (to j_start + i_end - i_start) void process_(const Eigen::Ref input, Eigen::Ref output, const long i_start, const long i_end, const long j_start) const; - long get_in_channels() const { return this->_weight.size() > 0 ? this->_weight[0].cols() : 0; }; - long get_kernel_size() const { return this->_weight.size(); }; + long get_in_channels() const { return this->mWeight.size() > 0 ? this->mWeight[0].cols() : 0; }; + long get_kernel_size() const { return this->mWeight.size(); }; long get_num_weights() const; - long get_out_channels() const { return this->_weight.size() > 0 ? this->_weight[0].rows() : 0; }; + long get_out_channels() const { return this->mWeight.size() > 0 ? this->mWeight[0].rows() : 0; }; int get_dilation() const { return this->_dilation; }; private: // Gonna wing this... // conv[kernel](cout, cin) - std::vector _weight; + std::vector mWeight; Eigen::VectorXf mBias; int _dilation; }; @@ -153,10 +153,10 @@ class Conv1x1 // :return: (N,Cout) or (Cout,), respectively Eigen::MatrixXf Process(const Eigen::Ref input) const; - long get_out_channels() const { return this->_weight.rows(); }; + long get_out_channels() const { return this->mWeight.rows(); }; private: - Eigen::MatrixXf _weight; + Eigen::MatrixXf mWeight; Eigen::VectorXf mBias; bool _do_bias; }; From b882f5b174e110ae50d13711119df2a5914d3189 Mon Sep 17 00:00:00 2001 From: Oli Larkin Date: Sat, 20 Jan 2024 00:00:13 +0100 Subject: [PATCH 025/133] _do_bias --- NAM/dsp.cpp | 6 +++--- NAM/dsp.h | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/NAM/dsp.cpp b/NAM/dsp.cpp index b4c7d0e..6c447b5 100644 --- a/NAM/dsp.cpp +++ b/NAM/dsp.cpp @@ -231,7 +231,7 @@ long nam::Conv1D::get_num_weights() const nam::Conv1x1::Conv1x1(const int in_channels, const int out_channels, const bool _bias) { this->mWeight.resize(out_channels, in_channels); - this->_do_bias = _bias; + this->mDoBias = _bias; if (_bias) this->mBias.resize(out_channels); } @@ -241,14 +241,14 @@ void nam::Conv1x1::set_weights_(weights_it& weights) for (int i = 0; i < this->mWeight.rows(); i++) for (int j = 0; j < this->mWeight.cols(); j++) this->mWeight(i, j) = *(weights++); - if (this->_do_bias) + if (this->mDoBias) for (int i = 0; i < this->mBias.size(); i++) this->mBias(i) = *(weights++); } Eigen::MatrixXf nam::Conv1x1::Process(const Eigen::Ref input) const { - if (this->_do_bias) + if (this->mDoBias) return (this->mWeight * input).colwise() + this->mBias; else return this->mWeight * input; diff --git a/NAM/dsp.h b/NAM/dsp.h index c0352c3..c4264d6 100644 --- a/NAM/dsp.h +++ b/NAM/dsp.h @@ -158,7 +158,7 @@ class Conv1x1 private: Eigen::MatrixXf mWeight; Eigen::VectorXf mBias; - bool _do_bias; + bool mDoBias; }; // Utilities ================================================================== From 68953415bbe61107a039c35bbf646d68c36ff09e Mon Sep 17 00:00:00 2001 From: Oli Larkin Date: Sat, 20 Jan 2024 00:01:25 +0100 Subject: [PATCH 026/133] _bias -> bias --- NAM/convnet.cpp | 6 +++--- NAM/dsp.cpp | 12 ++++++------ NAM/dsp.h | 4 ++-- NAM/get_dsp.cpp | 4 ++-- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/NAM/convnet.cpp b/NAM/convnet.cpp index f4e535a..e464530 100644 --- a/NAM/convnet.cpp +++ b/NAM/convnet.cpp @@ -16,7 +16,7 @@ nam::convnet::BatchNorm::BatchNorm(const int dim, weights_it& weights) Eigen::VectorXf running_mean(dim); Eigen::VectorXf running_var(dim); Eigen::VectorXf _weight(dim); - Eigen::VectorXf _bias(dim); + Eigen::VectorXf bias(dim); for (int i = 0; i < dim; i++) running_mean(i) = *(weights++); for (int i = 0; i < dim; i++) @@ -24,7 +24,7 @@ nam::convnet::BatchNorm::BatchNorm(const int dim, weights_it& weights) for (int i = 0; i < dim; i++) _weight(i) = *(weights++); for (int i = 0; i < dim; i++) - _bias(i) = *(weights++); + bias(i) = *(weights++); float eps = *(weights++); // Convert to scale & loc @@ -32,7 +32,7 @@ nam::convnet::BatchNorm::BatchNorm(const int dim, weights_it& weights) this->loc.resize(dim); for (int i = 0; i < dim; i++) this->scale(i) = _weight(i) / sqrt(eps + running_var(i)); - this->loc = _bias - this->scale.cwiseProduct(running_mean); + this->loc = bias - this->scale.cwiseProduct(running_mean); } void nam::convnet::BatchNorm::process_(Eigen::Ref x, const long i_start, const long i_end) const diff --git a/NAM/dsp.cpp b/NAM/dsp.cpp index 6c447b5..8c2cba6 100644 --- a/NAM/dsp.cpp +++ b/NAM/dsp.cpp @@ -136,11 +136,11 @@ void nam::Buffer::Finalize(const int numFrames) // Linear ===================================================================== -nam::Linear::Linear(const int receptiveField, const bool _bias, const std::vector& weights, +nam::Linear::Linear(const int receptiveField, const bool bias, const std::vector& weights, const double expectedSampleRate) : nam::Buffer(receptiveField, expectedSampleRate) { - if ((int)weights.size() != (receptiveField + (_bias ? 1 : 0))) + if ((int)weights.size() != (receptiveField + (bias ? 1 : 0))) throw std::runtime_error( "Params vector does not match expected size based " "on architecture parameters"); @@ -149,7 +149,7 @@ nam::Linear::Linear(const int receptiveField, const bool _bias, const std::vecto // Pass in in reverse order so that dot products work out of the box. for (int i = 0; i < this->mReceptiveField; i++) this->mWeight(i) = weights[receptiveField - 1 - i]; - this->mBias = _bias ? weights[receptiveField] : (float)0.0; + this->mBias = bias ? weights[receptiveField] : (float)0.0; } void nam::Linear::Process(float* input, float* output, const int numFrames) @@ -228,11 +228,11 @@ long nam::Conv1D::get_num_weights() const return num_weights; } -nam::Conv1x1::Conv1x1(const int in_channels, const int out_channels, const bool _bias) +nam::Conv1x1::Conv1x1(const int in_channels, const int out_channels, const bool bias) { this->mWeight.resize(out_channels, in_channels); - this->mDoBias = _bias; - if (_bias) + this->mDoBias = bias; + if (bias) this->mBias.resize(out_channels); } diff --git a/NAM/dsp.h b/NAM/dsp.h index c4264d6..900726b 100644 --- a/NAM/dsp.h +++ b/NAM/dsp.h @@ -104,7 +104,7 @@ class Buffer : public DSP class Linear : public Buffer { public: - Linear(const int receptiveField, const bool _bias, const std::vector& weights, + Linear(const int receptiveField, const bool bias, const std::vector& weights, const double expectedSampleRate = -1.0); void Process(float* input, float* output, const int numFrames) override; @@ -147,7 +147,7 @@ class Conv1D class Conv1x1 { public: - Conv1x1(const int in_channels, const int out_channels, const bool _bias); + Conv1x1(const int in_channels, const int out_channels, const bool bias); void set_weights_(weights_it& weights); // :param input: (N,Cin) or (Cin,) // :return: (N,Cout) or (Cout,), respectively diff --git a/NAM/get_dsp.cpp b/NAM/get_dsp.cpp index 46a5c5d..b124bab 100644 --- a/NAM/get_dsp.cpp +++ b/NAM/get_dsp.cpp @@ -146,8 +146,8 @@ std::unique_ptr get_dsp(dspData& conf) if (architecture == "Linear") { const int receptiveField = config["receptiveField"]; - const bool _bias = config["bias"]; - out = std::make_unique(receptiveField, _bias, weights, expectedSampleRate); + const bool bias = config["bias"]; + out = std::make_unique(receptiveField, bias, weights, expectedSampleRate); } else if (architecture == "ConvNet") { From 023f3eba61effb72f377acc4d327893436922011 Mon Sep 17 00:00:00 2001 From: Oli Larkin Date: Sat, 20 Jan 2024 00:01:52 +0100 Subject: [PATCH 027/133] _weight --- NAM/convnet.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/NAM/convnet.cpp b/NAM/convnet.cpp index e464530..1fea78c 100644 --- a/NAM/convnet.cpp +++ b/NAM/convnet.cpp @@ -15,14 +15,14 @@ nam::convnet::BatchNorm::BatchNorm(const int dim, weights_it& weights) // Extract from param buffer Eigen::VectorXf running_mean(dim); Eigen::VectorXf running_var(dim); - Eigen::VectorXf _weight(dim); + Eigen::VectorXf weight(dim); Eigen::VectorXf bias(dim); for (int i = 0; i < dim; i++) running_mean(i) = *(weights++); for (int i = 0; i < dim; i++) running_var(i) = *(weights++); for (int i = 0; i < dim; i++) - _weight(i) = *(weights++); + weight(i) = *(weights++); for (int i = 0; i < dim; i++) bias(i) = *(weights++); float eps = *(weights++); @@ -31,7 +31,7 @@ nam::convnet::BatchNorm::BatchNorm(const int dim, weights_it& weights) this->scale.resize(dim); this->loc.resize(dim); for (int i = 0; i < dim; i++) - this->scale(i) = _weight(i) / sqrt(eps + running_var(i)); + this->scale(i) = weight(i) / sqrt(eps + running_var(i)); this->loc = bias - this->scale.cwiseProduct(running_mean); } From ac2c19957ad02db37e1a0ef9ad0e4def9d69719f Mon Sep 17 00:00:00 2001 From: Oli Larkin Date: Sat, 20 Jan 2024 00:03:12 +0100 Subject: [PATCH 028/133] _dilation --- NAM/dsp.cpp | 4 ++-- NAM/dsp.h | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/NAM/dsp.cpp b/NAM/dsp.cpp index 8c2cba6..69c3510 100644 --- a/NAM/dsp.cpp +++ b/NAM/dsp.cpp @@ -194,7 +194,7 @@ void nam::Conv1D::set_size_(const int in_channels, const int out_channels, const this->mBias.resize(out_channels); else this->mBias.resize(0); - this->_dilation = _dilation; + this->mDilation = _dilation; } void nam::Conv1D::set_size_and_weights_(const int in_channels, const int out_channels, const int kernel_size, @@ -210,7 +210,7 @@ void nam::Conv1D::process_(const Eigen::Ref input, Eigen: // This is the clever part ;) for (size_t k = 0; k < this->mWeight.size(); k++) { - const long offset = this->_dilation * (k + 1 - this->mWeight.size()); + const long offset = this->mDilation * (k + 1 - this->mWeight.size()); if (k == 0) output.middleCols(j_start, ncols) = this->mWeight[k] * input.middleCols(i_start + offset, ncols); else diff --git a/NAM/dsp.h b/NAM/dsp.h index 900726b..29622f5 100644 --- a/NAM/dsp.h +++ b/NAM/dsp.h @@ -118,7 +118,7 @@ class Linear : public Buffer class Conv1D { public: - Conv1D() { this->_dilation = 1; }; + Conv1D() { this->mDilation = 1; }; void set_weights_(weights_it& weights); void set_size_(const int in_channels, const int out_channels, const int kernel_size, const bool do_bias, const int _dilation); @@ -133,14 +133,14 @@ class Conv1D long get_kernel_size() const { return this->mWeight.size(); }; long get_num_weights() const; long get_out_channels() const { return this->mWeight.size() > 0 ? this->mWeight[0].rows() : 0; }; - int get_dilation() const { return this->_dilation; }; + int get_dilation() const { return this->mDilation; }; private: // Gonna wing this... // conv[kernel](cout, cin) std::vector mWeight; Eigen::VectorXf mBias; - int _dilation; + int mDilation; }; // Really just a linear layer From 483f52e37f6828f0a3382b622d06dda992bad121 Mon Sep 17 00:00:00 2001 From: Oli Larkin Date: Sat, 20 Jan 2024 00:03:29 +0100 Subject: [PATCH 029/133] _dilation --- NAM/convnet.cpp | 8 ++++---- NAM/convnet.h | 2 +- NAM/dsp.cpp | 8 ++++---- NAM/dsp.h | 4 ++-- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/NAM/convnet.cpp b/NAM/convnet.cpp index 1fea78c..3083927 100644 --- a/NAM/convnet.cpp +++ b/NAM/convnet.cpp @@ -46,13 +46,13 @@ void nam::convnet::BatchNorm::process_(Eigen::Ref x, const long } } -void nam::convnet::ConvNetBlock::set_weights_(const int in_channels, const int out_channels, const int _dilation, +void nam::convnet::ConvNetBlock::set_weights_(const int in_channels, const int out_channels, const int dilation, const bool batchnorm, const std::string activation, weights_it& weights) { this->_batchnorm = batchnorm; // HACK 2 kernel - this->conv.set_size_and_weights_(in_channels, out_channels, 2, _dilation, !batchnorm, weights); + this->conv.set_size_and_weights_(in_channels, out_channels, 2, dilation, !batchnorm, weights); if (this->_batchnorm) this->batchnorm = BatchNorm(out_channels, weights); this->activation = activations::Activation::get_activation(activation); @@ -172,8 +172,8 @@ void nam::convnet::ConvNet::RewindBuffers() { // We actually don't need to pull back a lot...just as far as the first // input sample would grab from dilation - const long _dilation = this->_blocks[k].conv.get_dilation(); - for (long i = this->mReceptiveField - _dilation, j = this->mInputBufferOffset - _dilation; + const long dilation = this->_blocks[k].conv.get_dilation(); + for (long i = this->mReceptiveField - dilation, j = this->mInputBufferOffset - dilation; j < this->mInputBufferOffset; i++, j++) for (long r = 0; r < this->_block_vals[k].rows(); r++) this->_block_vals[k](r, i) = this->_block_vals[k](r, j); diff --git a/NAM/convnet.h b/NAM/convnet.h index 0d3f93a..9e155f2 100644 --- a/NAM/convnet.h +++ b/NAM/convnet.h @@ -40,7 +40,7 @@ class ConvNetBlock { public: ConvNetBlock(){}; - void set_weights_(const int in_channels, const int out_channels, const int _dilation, const bool batchnorm, + void set_weights_(const int in_channels, const int out_channels, const int dilation, const bool batchnorm, const std::string activation, weights_it& weights); void process_(const Eigen::Ref input, Eigen::Ref output, const long i_start, const long i_end) const; long get_out_channels() const; diff --git a/NAM/dsp.cpp b/NAM/dsp.cpp index 69c3510..2513e94 100644 --- a/NAM/dsp.cpp +++ b/NAM/dsp.cpp @@ -184,7 +184,7 @@ void nam::Conv1D::set_weights_(weights_it& weights) } void nam::Conv1D::set_size_(const int in_channels, const int out_channels, const int kernel_size, const bool do_bias, - const int _dilation) + const int dilation) { this->mWeight.resize(kernel_size); for (size_t i = 0; i < this->mWeight.size(); i++) @@ -194,13 +194,13 @@ void nam::Conv1D::set_size_(const int in_channels, const int out_channels, const this->mBias.resize(out_channels); else this->mBias.resize(0); - this->mDilation = _dilation; + this->mDilation = dilation; } void nam::Conv1D::set_size_and_weights_(const int in_channels, const int out_channels, const int kernel_size, - const int _dilation, const bool do_bias, weights_it& weights) + const int dilation, const bool do_bias, weights_it& weights) { - this->set_size_(in_channels, out_channels, kernel_size, do_bias, _dilation); + this->set_size_(in_channels, out_channels, kernel_size, do_bias, dilation); this->set_weights_(weights); } diff --git a/NAM/dsp.h b/NAM/dsp.h index 29622f5..2b89d9a 100644 --- a/NAM/dsp.h +++ b/NAM/dsp.h @@ -121,8 +121,8 @@ class Conv1D Conv1D() { this->mDilation = 1; }; void set_weights_(weights_it& weights); void set_size_(const int in_channels, const int out_channels, const int kernel_size, const bool do_bias, - const int _dilation); - void set_size_and_weights_(const int in_channels, const int out_channels, const int kernel_size, const int _dilation, + const int dilation); + void set_size_and_weights_(const int in_channels, const int out_channels, const int kernel_size, const int dilation, const bool do_bias, weights_it& weights); // Process from input to output // Rightmost indices of input go from i_start to i_end, From cb74e1709579abb5c08b13cfed98aadcf80a5e71 Mon Sep 17 00:00:00 2001 From: Oli Larkin Date: Sat, 20 Jan 2024 00:04:03 +0100 Subject: [PATCH 030/133] do_bias --- NAM/dsp.cpp | 8 ++++---- NAM/dsp.h | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/NAM/dsp.cpp b/NAM/dsp.cpp index 2513e94..1250ded 100644 --- a/NAM/dsp.cpp +++ b/NAM/dsp.cpp @@ -183,14 +183,14 @@ void nam::Conv1D::set_weights_(weights_it& weights) this->mBias(i) = *(weights++); } -void nam::Conv1D::set_size_(const int in_channels, const int out_channels, const int kernel_size, const bool do_bias, +void nam::Conv1D::set_size_(const int in_channels, const int out_channels, const int kernel_size, const bool doBias, const int dilation) { this->mWeight.resize(kernel_size); for (size_t i = 0; i < this->mWeight.size(); i++) this->mWeight[i].resize(out_channels, in_channels); // y = Ax, input array (C,L) - if (do_bias) + if (doBias) this->mBias.resize(out_channels); else this->mBias.resize(0); @@ -198,9 +198,9 @@ void nam::Conv1D::set_size_(const int in_channels, const int out_channels, const } void nam::Conv1D::set_size_and_weights_(const int in_channels, const int out_channels, const int kernel_size, - const int dilation, const bool do_bias, weights_it& weights) + const int dilation, const bool doBias, weights_it& weights) { - this->set_size_(in_channels, out_channels, kernel_size, do_bias, dilation); + this->set_size_(in_channels, out_channels, kernel_size, doBias, dilation); this->set_weights_(weights); } diff --git a/NAM/dsp.h b/NAM/dsp.h index 2b89d9a..d03a743 100644 --- a/NAM/dsp.h +++ b/NAM/dsp.h @@ -120,10 +120,10 @@ class Conv1D public: Conv1D() { this->mDilation = 1; }; void set_weights_(weights_it& weights); - void set_size_(const int in_channels, const int out_channels, const int kernel_size, const bool do_bias, + void set_size_(const int in_channels, const int out_channels, const int kernel_size, const bool doBias, const int dilation); void set_size_and_weights_(const int in_channels, const int out_channels, const int kernel_size, const int dilation, - const bool do_bias, weights_it& weights); + const bool doBias, weights_it& weights); // Process from input to output // Rightmost indices of input go from i_start to i_end, // Indices on output for from j_start (to j_start + i_end - i_start) From 73f968663c563db0b5548f4783a03d5d5ee26841 Mon Sep 17 00:00:00 2001 From: Oli Larkin Date: Sat, 20 Jan 2024 00:04:41 +0100 Subject: [PATCH 031/133] process_ --- NAM/convnet.cpp | 14 +++++++------- NAM/convnet.h | 6 +++--- NAM/dsp.cpp | 2 +- NAM/dsp.h | 2 +- NAM/lstm.cpp | 6 +++--- NAM/lstm.h | 2 +- NAM/wavenet.cpp | 16 ++++++++-------- NAM/wavenet.h | 8 ++++---- 8 files changed, 28 insertions(+), 28 deletions(-) diff --git a/NAM/convnet.cpp b/NAM/convnet.cpp index 3083927..41de0b2 100644 --- a/NAM/convnet.cpp +++ b/NAM/convnet.cpp @@ -35,7 +35,7 @@ nam::convnet::BatchNorm::BatchNorm(const int dim, weights_it& weights) this->loc = bias - this->scale.cwiseProduct(running_mean); } -void nam::convnet::BatchNorm::process_(Eigen::Ref x, const long i_start, const long i_end) const +void nam::convnet::BatchNorm::Process(Eigen::Ref x, const long i_start, const long i_end) const { // todo using colwise? // #speed but conv probably dominates @@ -58,13 +58,13 @@ void nam::convnet::ConvNetBlock::set_weights_(const int in_channels, const int o this->activation = activations::Activation::get_activation(activation); } -void nam::convnet::ConvNetBlock::process_(const Eigen::Ref input, Eigen::Ref output, const long i_start, +void nam::convnet::ConvNetBlock::Process(const Eigen::Ref input, Eigen::Ref output, const long i_start, const long i_end) const { const long ncols = i_end - i_start; - this->conv.process_(input, output, i_start, ncols, i_start); + this->conv.Process(input, output, i_start, ncols, i_start); if (this->_batchnorm) - this->batchnorm.process_(output, i_start, i_end); + this->batchnorm.Process(output, i_start, i_end); this->activation->apply(output.middleCols(i_start, ncols)); } @@ -82,7 +82,7 @@ nam::convnet::_Head::_Head(const int channels, weights_it& weights) this->mBias = *(weights++); } -void nam::convnet::_Head::process_(const Eigen::Ref input, Eigen::VectorXf& output, const long i_start, +void nam::convnet::_Head::Process(const Eigen::Ref input, Eigen::VectorXf& output, const long i_start, const long i_end) const { const long length = i_end - i_start; @@ -126,9 +126,9 @@ void nam::convnet::ConvNet::Process(float* input, float* output, const int numFr for (auto i = i_start; i < i_end; i++) this->_block_vals[0](0, i) = this->mInputBuffer[i]; for (size_t i = 0; i < this->_blocks.size(); i++) - this->_blocks[i].process_(this->_block_vals[i], this->_block_vals[i + 1], i_start, i_end); + this->_blocks[i].Process(this->_block_vals[i], this->_block_vals[i + 1], i_start, i_end); // TODO clean up this allocation - this->_head.process_(this->_block_vals[this->_blocks.size()], this->_head_output, i_start, i_end); + this->_head.Process(this->_block_vals[this->_blocks.size()], this->_head_output, i_start, i_end); // Copy to required output array (TODO tighten this up) for (int s = 0; s < numFrames; s++) output[s] = this->_head_output(s); diff --git a/NAM/convnet.h b/NAM/convnet.h index 9e155f2..dd70dfe 100644 --- a/NAM/convnet.h +++ b/NAM/convnet.h @@ -24,7 +24,7 @@ class BatchNorm public: BatchNorm(){}; BatchNorm(const int dim, weights_it& weights); - void process_(Eigen::Ref input, const long i_start, const long i_end) const; + void Process(Eigen::Ref input, const long i_start, const long i_end) const; private: // TODO simplify to just ax+b @@ -42,7 +42,7 @@ class ConvNetBlock ConvNetBlock(){}; void set_weights_(const int in_channels, const int out_channels, const int dilation, const bool batchnorm, const std::string activation, weights_it& weights); - void process_(const Eigen::Ref input, Eigen::Ref output, const long i_start, const long i_end) const; + void Process(const Eigen::Ref input, Eigen::Ref output, const long i_start, const long i_end) const; long get_out_channels() const; Conv1D conv; @@ -57,7 +57,7 @@ class _Head public: _Head(){}; _Head(const int channels, weights_it& weights); - void process_(const Eigen::Ref input, Eigen::VectorXf& output, const long i_start, const long i_end) const; + void Process(const Eigen::Ref input, Eigen::VectorXf& output, const long i_start, const long i_end) const; private: Eigen::VectorXf mWeight; diff --git a/NAM/dsp.cpp b/NAM/dsp.cpp index 1250ded..922f896 100644 --- a/NAM/dsp.cpp +++ b/NAM/dsp.cpp @@ -204,7 +204,7 @@ void nam::Conv1D::set_size_and_weights_(const int in_channels, const int out_cha this->set_weights_(weights); } -void nam::Conv1D::process_(const Eigen::Ref input, Eigen::Ref output, const long i_start, const long ncols, +void nam::Conv1D::Process(const Eigen::Ref input, Eigen::Ref output, const long i_start, const long ncols, const long j_start) const { // This is the clever part ;) diff --git a/NAM/dsp.h b/NAM/dsp.h index d03a743..f43ce62 100644 --- a/NAM/dsp.h +++ b/NAM/dsp.h @@ -127,7 +127,7 @@ class Conv1D // Process from input to output // Rightmost indices of input go from i_start to i_end, // Indices on output for from j_start (to j_start + i_end - i_start) - void process_(const Eigen::Ref input, Eigen::Ref output, const long i_start, const long i_end, + void Process(const Eigen::Ref input, Eigen::Ref output, const long i_start, const long i_end, const long j_start) const; long get_in_channels() const { return this->mWeight.size() > 0 ? this->mWeight[0].cols() : 0; }; long get_kernel_size() const { return this->mWeight.size(); }; diff --git a/NAM/lstm.cpp b/NAM/lstm.cpp index 8aad57f..ccde007 100644 --- a/NAM/lstm.cpp +++ b/NAM/lstm.cpp @@ -27,7 +27,7 @@ nam::lstm::LSTMCell::LSTMCell(const int input_size, const int hidden_size, weigh this->_c[i] = *(weights++); } -void nam::lstm::LSTMCell::process_(const Eigen::VectorXf& x) +void nam::lstm::LSTMCell::Process(const Eigen::VectorXf& x) { const long hidden_size = this->_get_hidden_size(); const long input_size = this->_get_input_size(); @@ -90,8 +90,8 @@ float nam::lstm::LSTM::_process_sample(const float x) if (this->_layers.size() == 0) return x; this->_input(0) = x; - this->_layers[0].process_(this->_input); + this->_layers[0].Process(this->_input); for (size_t i = 1; i < this->_layers.size(); i++) - this->_layers[i].process_(this->_layers[i - 1].get_hidden_state()); + this->_layers[i].Process(this->_layers[i - 1].get_hidden_state()); return this->_head_weight.dot(this->_layers[this->_layers.size() - 1].get_hidden_state()) + this->_head_bias; } diff --git a/NAM/lstm.h b/NAM/lstm.h index 7bb9806..31e1ac5 100644 --- a/NAM/lstm.h +++ b/NAM/lstm.h @@ -24,7 +24,7 @@ class LSTMCell public: LSTMCell(const int input_size, const int hidden_size, weights_it& weights); Eigen::VectorXf get_hidden_state() const { return this->_xh(Eigen::placeholders::lastN(this->_get_hidden_size())); }; - void process_(const Eigen::VectorXf& x); + void Process(const Eigen::VectorXf& x); private: // Parameters diff --git a/NAM/wavenet.cpp b/NAM/wavenet.cpp index bb58044..b01344f 100644 --- a/NAM/wavenet.cpp +++ b/NAM/wavenet.cpp @@ -19,14 +19,14 @@ void nam::wavenet::_Layer::set_weights_(weights_it& weights) this->_1x1.set_weights_(weights); } -void nam::wavenet::_Layer::process_(const Eigen::Ref input, const Eigen::Ref condition, +void nam::wavenet::_Layer::Process(const Eigen::Ref input, const Eigen::Ref condition, Eigen::Ref head_input, Eigen::Ref output, const long i_start, const long j_start) { const long ncols = condition.cols(); const long channels = this->get_channels(); // Input dilated conv - this->_conv.process_(input, this->_z, i_start, ncols, 0); + this->_conv.Process(input, this->_z, i_start, ncols, 0); // Mix-in condition this->_z += this->_input_mixin.Process(condition); @@ -102,7 +102,7 @@ void nam::wavenet::_LayerArray::prepare_for_frames_(const long numFrames) this->RewindBuffers(); } -void nam::wavenet::_LayerArray::process_(const Eigen::Ref layer_inputs, const Eigen::Ref condition, +void nam::wavenet::_LayerArray::Process(const Eigen::Ref layer_inputs, const Eigen::Ref condition, Eigen::Ref head_inputs, Eigen::Ref layer_outputs, Eigen::Ref head_outputs) { @@ -112,13 +112,13 @@ void nam::wavenet::_LayerArray::process_(const Eigen::Ref { if (i == last_layer) { - this->_layers[i].process_(this->_layer_buffers[i], condition, head_inputs, + this->_layers[i].Process(this->_layer_buffers[i], condition, head_inputs, layer_outputs, this->_buffer_start, 0); } else { - this->_layers[i].process_(this->_layer_buffers[i], condition, head_inputs, + this->_layers[i].Process(this->_layer_buffers[i], condition, head_inputs, this->_layer_buffers[i + 1], this->_buffer_start, this->_buffer_start); } @@ -202,7 +202,7 @@ void nam::wavenet::_Head::set_weights_(weights_it& weights) this->_layers[i].set_weights_(weights); } -void nam::wavenet::_Head::process_(Eigen::Ref inputs, Eigen::Ref outputs) +void nam::wavenet::_Head::Process(Eigen::Ref inputs, Eigen::Ref outputs) { const size_t num_layers = this->_layers.size(); this->_apply_activation_(inputs); @@ -334,9 +334,9 @@ void nam::wavenet::WaveNet::Process(float* input, float* output, const int numFr // Sum on head output this->_head_arrays[0].setZero(); for (size_t i = 0; i < this->_layer_arrays.size(); i++) - this->_layer_arrays[i].process_(i == 0 ? this->_condition : this->_layer_array_outputs[i - 1], this->_condition, + this->_layer_arrays[i].Process(i == 0 ? this->_condition : this->_layer_array_outputs[i - 1], this->_condition, this->_head_arrays[i], this->_layer_array_outputs[i], this->_head_arrays[i + 1]); - // this->_head.process_( + // this->_head.Process( // this->_head_input, // this->_head_output //); diff --git a/NAM/wavenet.h b/NAM/wavenet.h index e2e57d1..c317469 100644 --- a/NAM/wavenet.h +++ b/NAM/wavenet.h @@ -33,7 +33,7 @@ class _Layer void set_weights_(weights_it& weights); // :param `input`: from previous layer // :param `output`: to next layer - void process_(const Eigen::Ref input, const Eigen::Ref condition, Eigen::Ref head_input, + void Process(const Eigen::Ref input, const Eigen::Ref condition, Eigen::Ref head_input, Eigen::Ref output, const long i_start, const long j_start); void set_num_frames_(const long numFrames); long get_channels() const { return this->_conv.get_in_channels(); }; @@ -101,7 +101,7 @@ class _LayerArray void prepare_for_frames_(const long numFrames); // All arrays are "short". - void process_(const Eigen::Ref layer_inputs, // Short + void Process(const Eigen::Ref layer_inputs, // Short const Eigen::Ref condition, // Short Eigen::Ref layer_outputs, // Short Eigen::Ref head_inputs, // Sum up on this. @@ -147,7 +147,7 @@ class _Head void set_weights_(weights_it& weights); // NOTE: the head transforms the provided input by applying a nonlinearity // to it in-place! - void process_(Eigen::Ref inputs, Eigen::Ref outputs); + void Process(Eigen::Ref inputs, Eigen::Ref outputs); void set_num_frames_(const long numFrames); private: @@ -157,7 +157,7 @@ class _Head activations::Activation* _activation; // Stores the outputs of the convs *except* the last one, which goes in - // The array `outputs` provided to .process_() + // The array `outputs` provided to .Process() std::vector _buffers; // Apply the activation to the provided array, in-place From 355b2d563acba2cbfa7938761525f3aa07756d8b Mon Sep 17 00:00:00 2001 From: Oli Larkin Date: Sat, 20 Jan 2024 00:05:28 +0100 Subject: [PATCH 032/133] set_weights_ --- NAM/convnet.cpp | 4 ++-- NAM/convnet.h | 2 +- NAM/dsp.cpp | 6 +++--- NAM/dsp.h | 4 ++-- NAM/wavenet.cpp | 26 +++++++++++++------------- NAM/wavenet.h | 8 ++++---- 6 files changed, 25 insertions(+), 25 deletions(-) diff --git a/NAM/convnet.cpp b/NAM/convnet.cpp index 41de0b2..f0ef798 100644 --- a/NAM/convnet.cpp +++ b/NAM/convnet.cpp @@ -46,7 +46,7 @@ void nam::convnet::BatchNorm::Process(Eigen::Ref x, const long } } -void nam::convnet::ConvNetBlock::set_weights_(const int in_channels, const int out_channels, const int dilation, +void nam::convnet::ConvNetBlock::SetWeights(const int in_channels, const int out_channels, const int dilation, const bool batchnorm, const std::string activation, weights_it& weights) { @@ -100,7 +100,7 @@ nam::convnet::ConvNet::ConvNet(const int channels, const std::vector& dilat this->_blocks.resize(dilations.size()); weights_it it = weights.begin(); for (size_t i = 0; i < dilations.size(); i++) - this->_blocks[i].set_weights_(i == 0 ? 1 : channels, channels, dilations[i], batchnorm, activation, it); + this->_blocks[i].SetWeights(i == 0 ? 1 : channels, channels, dilations[i], batchnorm, activation, it); this->_block_vals.resize(this->_blocks.size() + 1); for (auto& matrix : this->_block_vals) matrix.setZero(); diff --git a/NAM/convnet.h b/NAM/convnet.h index dd70dfe..981738e 100644 --- a/NAM/convnet.h +++ b/NAM/convnet.h @@ -40,7 +40,7 @@ class ConvNetBlock { public: ConvNetBlock(){}; - void set_weights_(const int in_channels, const int out_channels, const int dilation, const bool batchnorm, + void SetWeights(const int in_channels, const int out_channels, const int dilation, const bool batchnorm, const std::string activation, weights_it& weights); void Process(const Eigen::Ref input, Eigen::Ref output, const long i_start, const long i_end) const; long get_out_channels() const; diff --git a/NAM/dsp.cpp b/NAM/dsp.cpp index 922f896..fb57722 100644 --- a/NAM/dsp.cpp +++ b/NAM/dsp.cpp @@ -167,7 +167,7 @@ void nam::Linear::Process(float* input, float* output, const int numFrames) // NN modules ================================================================= -void nam::Conv1D::set_weights_(weights_it& weights) +void nam::Conv1D::SetWeights(weights_it& weights) { if (this->mWeight.size() > 0) { @@ -201,7 +201,7 @@ void nam::Conv1D::set_size_and_weights_(const int in_channels, const int out_cha const int dilation, const bool doBias, weights_it& weights) { this->set_size_(in_channels, out_channels, kernel_size, doBias, dilation); - this->set_weights_(weights); + this->SetWeights(weights); } void nam::Conv1D::Process(const Eigen::Ref input, Eigen::Ref output, const long i_start, const long ncols, @@ -236,7 +236,7 @@ nam::Conv1x1::Conv1x1(const int in_channels, const int out_channels, const bool this->mBias.resize(out_channels); } -void nam::Conv1x1::set_weights_(weights_it& weights) +void nam::Conv1x1::SetWeights(weights_it& weights) { for (int i = 0; i < this->mWeight.rows(); i++) for (int j = 0; j < this->mWeight.cols(); j++) diff --git a/NAM/dsp.h b/NAM/dsp.h index f43ce62..a3dedbc 100644 --- a/NAM/dsp.h +++ b/NAM/dsp.h @@ -119,7 +119,7 @@ class Conv1D { public: Conv1D() { this->mDilation = 1; }; - void set_weights_(weights_it& weights); + void SetWeights(weights_it& weights); void set_size_(const int in_channels, const int out_channels, const int kernel_size, const bool doBias, const int dilation); void set_size_and_weights_(const int in_channels, const int out_channels, const int kernel_size, const int dilation, @@ -148,7 +148,7 @@ class Conv1x1 { public: Conv1x1(const int in_channels, const int out_channels, const bool bias); - void set_weights_(weights_it& weights); + void SetWeights(weights_it& weights); // :param input: (N,Cin) or (Cin,) // :return: (N,Cout) or (Cout,), respectively Eigen::MatrixXf Process(const Eigen::Ref input) const; diff --git a/NAM/wavenet.cpp b/NAM/wavenet.cpp index b01344f..fd39050 100644 --- a/NAM/wavenet.cpp +++ b/NAM/wavenet.cpp @@ -12,11 +12,11 @@ nam::wavenet::_DilatedConv::_DilatedConv(const int in_channels, const int out_ch this->set_size_(in_channels, out_channels, kernel_size, bias, dilation); } -void nam::wavenet::_Layer::set_weights_(weights_it& weights) +void nam::wavenet::_Layer::SetWeights(weights_it& weights) { - this->_conv.set_weights_(weights); - this->_input_mixin.set_weights_(weights); - this->_1x1.set_weights_(weights); + this->_conv.SetWeights(weights); + this->_input_mixin.SetWeights(weights); + this->_1x1.SetWeights(weights); } void nam::wavenet::_Layer::Process(const Eigen::Ref input, const Eigen::Ref condition, @@ -143,12 +143,12 @@ void nam::wavenet::_LayerArray::set_num_frames_(const long numFrames) this->_layers[i].set_num_frames_(numFrames); } -void nam::wavenet::_LayerArray::set_weights_(weights_it& weights) +void nam::wavenet::_LayerArray::SetWeights(weights_it& weights) { - this->_rechannel.set_weights_(weights); + this->_rechannel.SetWeights(weights); for (size_t i = 0; i < this->_layers.size(); i++) - this->_layers[i].set_weights_(weights); - this->_head_rechannel.set_weights_(weights); + this->_layers[i].SetWeights(weights); + this->_head_rechannel.SetWeights(weights); } long nam::wavenet::_LayerArray::_get_channels() const @@ -196,10 +196,10 @@ nam::wavenet::_Head::_Head(const int input_size, const int num_layers, const int } } -void nam::wavenet::_Head::set_weights_(weights_it& weights) +void nam::wavenet::_Head::SetWeights(weights_it& weights) { for (size_t i = 0; i < this->_layers.size(); i++) - this->_layers[i].set_weights_(weights); + this->_layers[i].SetWeights(weights); } void nam::wavenet::_Head::Process(Eigen::Ref inputs, Eigen::Ref outputs) @@ -269,7 +269,7 @@ nam::wavenet::WaveNet::WaveNet(const std::vector this->_head_arrays.push_back(Eigen::MatrixXf(layer_array_params[i].head_size, 0)); } this->_head_output.resize(1, 0); // Mono output! - this->set_weights_(weights); + this->SetWeights(weights); mPrewarmSamples = 1; for (size_t i = 0; i < this->_layer_arrays.size(); i++) @@ -282,11 +282,11 @@ void nam::wavenet::WaveNet::Finalize(const int numFrames) this->_advance_buffers_(numFrames); } -void nam::wavenet::WaveNet::set_weights_(const std::vector& weights) +void nam::wavenet::WaveNet::SetWeights(const std::vector& weights) { weights_it it = weights.begin(); for (size_t i = 0; i < this->_layer_arrays.size(); i++) - this->_layer_arrays[i].set_weights_(it); + this->_layer_arrays[i].SetWeights(it); // this->_head.set_params_(it); this->_head_scale = *(it++); if (it != weights.end()) diff --git a/NAM/wavenet.h b/NAM/wavenet.h index c317469..998f602 100644 --- a/NAM/wavenet.h +++ b/NAM/wavenet.h @@ -30,7 +30,7 @@ class _Layer , _1x1(channels, channels, true) , _activation(activations::Activation::get_activation(activation)) , _gated(gated){}; - void set_weights_(weights_it& weights); + void SetWeights(weights_it& weights); // :param `input`: from previous layer // :param `output`: to next layer void Process(const Eigen::Ref input, const Eigen::Ref condition, Eigen::Ref head_input, @@ -108,7 +108,7 @@ class _LayerArray Eigen::Ref head_outputs // post head-rechannel ); void set_num_frames_(const long numFrames); - void set_weights_(weights_it& it); + void SetWeights(weights_it& it); // "Zero-indexed" receptive field. // E.g. a 1x1 convolution has a z.i.r.f. of zero. @@ -144,7 +144,7 @@ class _Head { public: _Head(const int input_size, const int num_layers, const int channels, const std::string activation); - void set_weights_(weights_it& weights); + void SetWeights(weights_it& weights); // NOTE: the head transforms the provided input by applying a nonlinearity // to it in-place! void Process(Eigen::Ref inputs, Eigen::Ref outputs); @@ -173,7 +173,7 @@ class WaveNet : public DSP ~WaveNet() = default; void Finalize(const int numFrames) override; - void set_weights_(const std::vector& weights); + void SetWeights(const std::vector& weights); private: long _num_frames; From 6eb415a4fafb1c945c9f8502a5f182e9ca7eedc6 Mon Sep 17 00:00:00 2001 From: Oli Larkin Date: Sat, 20 Jan 2024 00:05:41 +0100 Subject: [PATCH 033/133] set_size_ --- NAM/dsp.cpp | 4 ++-- NAM/dsp.h | 2 +- NAM/wavenet.cpp | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/NAM/dsp.cpp b/NAM/dsp.cpp index fb57722..3232d25 100644 --- a/NAM/dsp.cpp +++ b/NAM/dsp.cpp @@ -183,7 +183,7 @@ void nam::Conv1D::SetWeights(weights_it& weights) this->mBias(i) = *(weights++); } -void nam::Conv1D::set_size_(const int in_channels, const int out_channels, const int kernel_size, const bool doBias, +void nam::Conv1D::SetSize(const int in_channels, const int out_channels, const int kernel_size, const bool doBias, const int dilation) { this->mWeight.resize(kernel_size); @@ -200,7 +200,7 @@ void nam::Conv1D::set_size_(const int in_channels, const int out_channels, const void nam::Conv1D::set_size_and_weights_(const int in_channels, const int out_channels, const int kernel_size, const int dilation, const bool doBias, weights_it& weights) { - this->set_size_(in_channels, out_channels, kernel_size, doBias, dilation); + this->SetSize(in_channels, out_channels, kernel_size, doBias, dilation); this->SetWeights(weights); } diff --git a/NAM/dsp.h b/NAM/dsp.h index a3dedbc..9865fd9 100644 --- a/NAM/dsp.h +++ b/NAM/dsp.h @@ -120,7 +120,7 @@ class Conv1D public: Conv1D() { this->mDilation = 1; }; void SetWeights(weights_it& weights); - void set_size_(const int in_channels, const int out_channels, const int kernel_size, const bool doBias, + void SetSize(const int in_channels, const int out_channels, const int kernel_size, const bool doBias, const int dilation); void set_size_and_weights_(const int in_channels, const int out_channels, const int kernel_size, const int dilation, const bool doBias, weights_it& weights); diff --git a/NAM/wavenet.cpp b/NAM/wavenet.cpp index fd39050..520cf76 100644 --- a/NAM/wavenet.cpp +++ b/NAM/wavenet.cpp @@ -9,7 +9,7 @@ nam::wavenet::_DilatedConv::_DilatedConv(const int in_channels, const int out_channels, const int kernel_size, const int bias, const int dilation) { - this->set_size_(in_channels, out_channels, kernel_size, bias, dilation); + this->SetSize(in_channels, out_channels, kernel_size, bias, dilation); } void nam::wavenet::_Layer::SetWeights(weights_it& weights) From 59832b9868ba76465b1a4d32ee733eb5725eee14 Mon Sep 17 00:00:00 2001 From: Oli Larkin Date: Sat, 20 Jan 2024 00:05:59 +0100 Subject: [PATCH 034/133] set_size_and_weights_ --- NAM/convnet.cpp | 2 +- NAM/dsp.cpp | 2 +- NAM/dsp.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/NAM/convnet.cpp b/NAM/convnet.cpp index f0ef798..e714b13 100644 --- a/NAM/convnet.cpp +++ b/NAM/convnet.cpp @@ -52,7 +52,7 @@ void nam::convnet::ConvNetBlock::SetWeights(const int in_channels, const int out { this->_batchnorm = batchnorm; // HACK 2 kernel - this->conv.set_size_and_weights_(in_channels, out_channels, 2, dilation, !batchnorm, weights); + this->conv.SetSizeAndWeights(in_channels, out_channels, 2, dilation, !batchnorm, weights); if (this->_batchnorm) this->batchnorm = BatchNorm(out_channels, weights); this->activation = activations::Activation::get_activation(activation); diff --git a/NAM/dsp.cpp b/NAM/dsp.cpp index 3232d25..286a6b7 100644 --- a/NAM/dsp.cpp +++ b/NAM/dsp.cpp @@ -197,7 +197,7 @@ void nam::Conv1D::SetSize(const int in_channels, const int out_channels, const i this->mDilation = dilation; } -void nam::Conv1D::set_size_and_weights_(const int in_channels, const int out_channels, const int kernel_size, +void nam::Conv1D::SetSizeAndWeights(const int in_channels, const int out_channels, const int kernel_size, const int dilation, const bool doBias, weights_it& weights) { this->SetSize(in_channels, out_channels, kernel_size, doBias, dilation); diff --git a/NAM/dsp.h b/NAM/dsp.h index 9865fd9..367879b 100644 --- a/NAM/dsp.h +++ b/NAM/dsp.h @@ -122,7 +122,7 @@ class Conv1D void SetWeights(weights_it& weights); void SetSize(const int in_channels, const int out_channels, const int kernel_size, const bool doBias, const int dilation); - void set_size_and_weights_(const int in_channels, const int out_channels, const int kernel_size, const int dilation, + void SetSizeAndWeights(const int in_channels, const int out_channels, const int kernel_size, const int dilation, const bool doBias, weights_it& weights); // Process from input to output // Rightmost indices of input go from i_start to i_end, From 513b453e73a7a26acd256e4815905a9bfc04fb55 Mon Sep 17 00:00:00 2001 From: Oli Larkin Date: Sat, 20 Jan 2024 00:06:21 +0100 Subject: [PATCH 035/133] in_channels --- NAM/convnet.cpp | 4 ++-- NAM/convnet.h | 2 +- NAM/dsp.cpp | 16 ++++++++-------- NAM/dsp.h | 6 +++--- NAM/wavenet.cpp | 4 ++-- NAM/wavenet.h | 2 +- 6 files changed, 17 insertions(+), 17 deletions(-) diff --git a/NAM/convnet.cpp b/NAM/convnet.cpp index e714b13..f363a03 100644 --- a/NAM/convnet.cpp +++ b/NAM/convnet.cpp @@ -46,13 +46,13 @@ void nam::convnet::BatchNorm::Process(Eigen::Ref x, const long } } -void nam::convnet::ConvNetBlock::SetWeights(const int in_channels, const int out_channels, const int dilation, +void nam::convnet::ConvNetBlock::SetWeights(const int inChannels, const int out_channels, const int dilation, const bool batchnorm, const std::string activation, weights_it& weights) { this->_batchnorm = batchnorm; // HACK 2 kernel - this->conv.SetSizeAndWeights(in_channels, out_channels, 2, dilation, !batchnorm, weights); + this->conv.SetSizeAndWeights(inChannels, out_channels, 2, dilation, !batchnorm, weights); if (this->_batchnorm) this->batchnorm = BatchNorm(out_channels, weights); this->activation = activations::Activation::get_activation(activation); diff --git a/NAM/convnet.h b/NAM/convnet.h index 981738e..0f31027 100644 --- a/NAM/convnet.h +++ b/NAM/convnet.h @@ -40,7 +40,7 @@ class ConvNetBlock { public: ConvNetBlock(){}; - void SetWeights(const int in_channels, const int out_channels, const int dilation, const bool batchnorm, + void SetWeights(const int inChannels, const int out_channels, const int dilation, const bool batchnorm, const std::string activation, weights_it& weights); void Process(const Eigen::Ref input, Eigen::Ref output, const long i_start, const long i_end) const; long get_out_channels() const; diff --git a/NAM/dsp.cpp b/NAM/dsp.cpp index 286a6b7..9295c24 100644 --- a/NAM/dsp.cpp +++ b/NAM/dsp.cpp @@ -172,10 +172,10 @@ void nam::Conv1D::SetWeights(weights_it& weights) if (this->mWeight.size() > 0) { const long out_channels = this->mWeight[0].rows(); - const long in_channels = this->mWeight[0].cols(); + const long inChannels = this->mWeight[0].cols(); // Crazy ordering because that's how it gets flattened. for (auto i = 0; i < out_channels; i++) - for (auto j = 0; j < in_channels; j++) + for (auto j = 0; j < inChannels; j++) for (size_t k = 0; k < this->mWeight.size(); k++) this->mWeight[k](i, j) = *(weights++); } @@ -183,13 +183,13 @@ void nam::Conv1D::SetWeights(weights_it& weights) this->mBias(i) = *(weights++); } -void nam::Conv1D::SetSize(const int in_channels, const int out_channels, const int kernel_size, const bool doBias, +void nam::Conv1D::SetSize(const int inChannels, const int out_channels, const int kernel_size, const bool doBias, const int dilation) { this->mWeight.resize(kernel_size); for (size_t i = 0; i < this->mWeight.size(); i++) this->mWeight[i].resize(out_channels, - in_channels); // y = Ax, input array (C,L) + inChannels); // y = Ax, input array (C,L) if (doBias) this->mBias.resize(out_channels); else @@ -197,10 +197,10 @@ void nam::Conv1D::SetSize(const int in_channels, const int out_channels, const i this->mDilation = dilation; } -void nam::Conv1D::SetSizeAndWeights(const int in_channels, const int out_channels, const int kernel_size, +void nam::Conv1D::SetSizeAndWeights(const int inChannels, const int out_channels, const int kernel_size, const int dilation, const bool doBias, weights_it& weights) { - this->SetSize(in_channels, out_channels, kernel_size, doBias, dilation); + this->SetSize(inChannels, out_channels, kernel_size, doBias, dilation); this->SetWeights(weights); } @@ -228,9 +228,9 @@ long nam::Conv1D::get_num_weights() const return num_weights; } -nam::Conv1x1::Conv1x1(const int in_channels, const int out_channels, const bool bias) +nam::Conv1x1::Conv1x1(const int inChannels, const int out_channels, const bool bias) { - this->mWeight.resize(out_channels, in_channels); + this->mWeight.resize(out_channels, inChannels); this->mDoBias = bias; if (bias) this->mBias.resize(out_channels); diff --git a/NAM/dsp.h b/NAM/dsp.h index 367879b..e97dd1c 100644 --- a/NAM/dsp.h +++ b/NAM/dsp.h @@ -120,9 +120,9 @@ class Conv1D public: Conv1D() { this->mDilation = 1; }; void SetWeights(weights_it& weights); - void SetSize(const int in_channels, const int out_channels, const int kernel_size, const bool doBias, + void SetSize(const int inChannels, const int out_channels, const int kernel_size, const bool doBias, const int dilation); - void SetSizeAndWeights(const int in_channels, const int out_channels, const int kernel_size, const int dilation, + void SetSizeAndWeights(const int inChannels, const int out_channels, const int kernel_size, const int dilation, const bool doBias, weights_it& weights); // Process from input to output // Rightmost indices of input go from i_start to i_end, @@ -147,7 +147,7 @@ class Conv1D class Conv1x1 { public: - Conv1x1(const int in_channels, const int out_channels, const bool bias); + Conv1x1(const int inChannels, const int out_channels, const bool bias); void SetWeights(weights_it& weights); // :param input: (N,Cin) or (Cin,) // :return: (N,Cout) or (Cout,), respectively diff --git a/NAM/wavenet.cpp b/NAM/wavenet.cpp index 520cf76..1ab16d7 100644 --- a/NAM/wavenet.cpp +++ b/NAM/wavenet.cpp @@ -6,10 +6,10 @@ #include "wavenet.h" -nam::wavenet::_DilatedConv::_DilatedConv(const int in_channels, const int out_channels, const int kernel_size, +nam::wavenet::_DilatedConv::_DilatedConv(const int inChannels, const int out_channels, const int kernel_size, const int bias, const int dilation) { - this->SetSize(in_channels, out_channels, kernel_size, bias, dilation); + this->SetSize(inChannels, out_channels, kernel_size, bias, dilation); } void nam::wavenet::_Layer::SetWeights(weights_it& weights) diff --git a/NAM/wavenet.h b/NAM/wavenet.h index 998f602..74c9063 100644 --- a/NAM/wavenet.h +++ b/NAM/wavenet.h @@ -16,7 +16,7 @@ namespace wavenet class _DilatedConv : public Conv1D { public: - _DilatedConv(const int in_channels, const int out_channels, const int kernel_size, const int bias, + _DilatedConv(const int inChannels, const int out_channels, const int kernel_size, const int bias, const int dilation); }; From 265b74c22439daa61219ab1ffe2c6f31e76b877e Mon Sep 17 00:00:00 2001 From: Oli Larkin Date: Sat, 20 Jan 2024 00:06:35 +0100 Subject: [PATCH 036/133] out_channels --- NAM/convnet.cpp | 6 +++--- NAM/convnet.h | 2 +- NAM/dsp.cpp | 20 ++++++++++---------- NAM/dsp.h | 6 +++--- NAM/wavenet.cpp | 4 ++-- NAM/wavenet.h | 2 +- 6 files changed, 20 insertions(+), 20 deletions(-) diff --git a/NAM/convnet.cpp b/NAM/convnet.cpp index f363a03..8cb0674 100644 --- a/NAM/convnet.cpp +++ b/NAM/convnet.cpp @@ -46,15 +46,15 @@ void nam::convnet::BatchNorm::Process(Eigen::Ref x, const long } } -void nam::convnet::ConvNetBlock::SetWeights(const int inChannels, const int out_channels, const int dilation, +void nam::convnet::ConvNetBlock::SetWeights(const int inChannels, const int outChannels, const int dilation, const bool batchnorm, const std::string activation, weights_it& weights) { this->_batchnorm = batchnorm; // HACK 2 kernel - this->conv.SetSizeAndWeights(inChannels, out_channels, 2, dilation, !batchnorm, weights); + this->conv.SetSizeAndWeights(inChannels, outChannels, 2, dilation, !batchnorm, weights); if (this->_batchnorm) - this->batchnorm = BatchNorm(out_channels, weights); + this->batchnorm = BatchNorm(outChannels, weights); this->activation = activations::Activation::get_activation(activation); } diff --git a/NAM/convnet.h b/NAM/convnet.h index 0f31027..ac6fd59 100644 --- a/NAM/convnet.h +++ b/NAM/convnet.h @@ -40,7 +40,7 @@ class ConvNetBlock { public: ConvNetBlock(){}; - void SetWeights(const int inChannels, const int out_channels, const int dilation, const bool batchnorm, + void SetWeights(const int inChannels, const int outChannels, const int dilation, const bool batchnorm, const std::string activation, weights_it& weights); void Process(const Eigen::Ref input, Eigen::Ref output, const long i_start, const long i_end) const; long get_out_channels() const; diff --git a/NAM/dsp.cpp b/NAM/dsp.cpp index 9295c24..01eff68 100644 --- a/NAM/dsp.cpp +++ b/NAM/dsp.cpp @@ -171,10 +171,10 @@ void nam::Conv1D::SetWeights(weights_it& weights) { if (this->mWeight.size() > 0) { - const long out_channels = this->mWeight[0].rows(); + const long outChannels = this->mWeight[0].rows(); const long inChannels = this->mWeight[0].cols(); // Crazy ordering because that's how it gets flattened. - for (auto i = 0; i < out_channels; i++) + for (auto i = 0; i < outChannels; i++) for (auto j = 0; j < inChannels; j++) for (size_t k = 0; k < this->mWeight.size(); k++) this->mWeight[k](i, j) = *(weights++); @@ -183,24 +183,24 @@ void nam::Conv1D::SetWeights(weights_it& weights) this->mBias(i) = *(weights++); } -void nam::Conv1D::SetSize(const int inChannels, const int out_channels, const int kernel_size, const bool doBias, +void nam::Conv1D::SetSize(const int inChannels, const int outChannels, const int kernel_size, const bool doBias, const int dilation) { this->mWeight.resize(kernel_size); for (size_t i = 0; i < this->mWeight.size(); i++) - this->mWeight[i].resize(out_channels, + this->mWeight[i].resize(outChannels, inChannels); // y = Ax, input array (C,L) if (doBias) - this->mBias.resize(out_channels); + this->mBias.resize(outChannels); else this->mBias.resize(0); this->mDilation = dilation; } -void nam::Conv1D::SetSizeAndWeights(const int inChannels, const int out_channels, const int kernel_size, +void nam::Conv1D::SetSizeAndWeights(const int inChannels, const int outChannels, const int kernel_size, const int dilation, const bool doBias, weights_it& weights) { - this->SetSize(inChannels, out_channels, kernel_size, doBias, dilation); + this->SetSize(inChannels, outChannels, kernel_size, doBias, dilation); this->SetWeights(weights); } @@ -228,12 +228,12 @@ long nam::Conv1D::get_num_weights() const return num_weights; } -nam::Conv1x1::Conv1x1(const int inChannels, const int out_channels, const bool bias) +nam::Conv1x1::Conv1x1(const int inChannels, const int outChannels, const bool bias) { - this->mWeight.resize(out_channels, inChannels); + this->mWeight.resize(outChannels, inChannels); this->mDoBias = bias; if (bias) - this->mBias.resize(out_channels); + this->mBias.resize(outChannels); } void nam::Conv1x1::SetWeights(weights_it& weights) diff --git a/NAM/dsp.h b/NAM/dsp.h index e97dd1c..4707760 100644 --- a/NAM/dsp.h +++ b/NAM/dsp.h @@ -120,9 +120,9 @@ class Conv1D public: Conv1D() { this->mDilation = 1; }; void SetWeights(weights_it& weights); - void SetSize(const int inChannels, const int out_channels, const int kernel_size, const bool doBias, + void SetSize(const int inChannels, const int outChannels, const int kernel_size, const bool doBias, const int dilation); - void SetSizeAndWeights(const int inChannels, const int out_channels, const int kernel_size, const int dilation, + void SetSizeAndWeights(const int inChannels, const int outChannels, const int kernel_size, const int dilation, const bool doBias, weights_it& weights); // Process from input to output // Rightmost indices of input go from i_start to i_end, @@ -147,7 +147,7 @@ class Conv1D class Conv1x1 { public: - Conv1x1(const int inChannels, const int out_channels, const bool bias); + Conv1x1(const int inChannels, const int outChannels, const bool bias); void SetWeights(weights_it& weights); // :param input: (N,Cin) or (Cin,) // :return: (N,Cout) or (Cout,), respectively diff --git a/NAM/wavenet.cpp b/NAM/wavenet.cpp index 1ab16d7..f37eb89 100644 --- a/NAM/wavenet.cpp +++ b/NAM/wavenet.cpp @@ -6,10 +6,10 @@ #include "wavenet.h" -nam::wavenet::_DilatedConv::_DilatedConv(const int inChannels, const int out_channels, const int kernel_size, +nam::wavenet::_DilatedConv::_DilatedConv(const int inChannels, const int outChannels, const int kernel_size, const int bias, const int dilation) { - this->SetSize(inChannels, out_channels, kernel_size, bias, dilation); + this->SetSize(inChannels, outChannels, kernel_size, bias, dilation); } void nam::wavenet::_Layer::SetWeights(weights_it& weights) diff --git a/NAM/wavenet.h b/NAM/wavenet.h index 74c9063..0ca5389 100644 --- a/NAM/wavenet.h +++ b/NAM/wavenet.h @@ -16,7 +16,7 @@ namespace wavenet class _DilatedConv : public Conv1D { public: - _DilatedConv(const int inChannels, const int out_channels, const int kernel_size, const int bias, + _DilatedConv(const int inChannels, const int outChannels, const int kernel_size, const int bias, const int dilation); }; From e622ae2470aa08aa4a5b4314f8f4009182a6e22d Mon Sep 17 00:00:00 2001 From: Oli Larkin Date: Sat, 20 Jan 2024 00:07:03 +0100 Subject: [PATCH 037/133] kernel_size --- NAM/dsp.cpp | 8 ++++---- NAM/dsp.h | 4 ++-- NAM/wavenet.cpp | 10 +++++----- NAM/wavenet.h | 12 ++++++------ 4 files changed, 17 insertions(+), 17 deletions(-) diff --git a/NAM/dsp.cpp b/NAM/dsp.cpp index 01eff68..03412ac 100644 --- a/NAM/dsp.cpp +++ b/NAM/dsp.cpp @@ -183,10 +183,10 @@ void nam::Conv1D::SetWeights(weights_it& weights) this->mBias(i) = *(weights++); } -void nam::Conv1D::SetSize(const int inChannels, const int outChannels, const int kernel_size, const bool doBias, +void nam::Conv1D::SetSize(const int inChannels, const int outChannels, const int kernelSize, const bool doBias, const int dilation) { - this->mWeight.resize(kernel_size); + this->mWeight.resize(kernelSize); for (size_t i = 0; i < this->mWeight.size(); i++) this->mWeight[i].resize(outChannels, inChannels); // y = Ax, input array (C,L) @@ -197,10 +197,10 @@ void nam::Conv1D::SetSize(const int inChannels, const int outChannels, const int this->mDilation = dilation; } -void nam::Conv1D::SetSizeAndWeights(const int inChannels, const int outChannels, const int kernel_size, +void nam::Conv1D::SetSizeAndWeights(const int inChannels, const int outChannels, const int kernelSize, const int dilation, const bool doBias, weights_it& weights) { - this->SetSize(inChannels, outChannels, kernel_size, doBias, dilation); + this->SetSize(inChannels, outChannels, kernelSize, doBias, dilation); this->SetWeights(weights); } diff --git a/NAM/dsp.h b/NAM/dsp.h index 4707760..a31bbc9 100644 --- a/NAM/dsp.h +++ b/NAM/dsp.h @@ -120,9 +120,9 @@ class Conv1D public: Conv1D() { this->mDilation = 1; }; void SetWeights(weights_it& weights); - void SetSize(const int inChannels, const int outChannels, const int kernel_size, const bool doBias, + void SetSize(const int inChannels, const int outChannels, const int kernelSize, const bool doBias, const int dilation); - void SetSizeAndWeights(const int inChannels, const int outChannels, const int kernel_size, const int dilation, + void SetSizeAndWeights(const int inChannels, const int outChannels, const int kernelSize, const int dilation, const bool doBias, weights_it& weights); // Process from input to output // Rightmost indices of input go from i_start to i_end, diff --git a/NAM/wavenet.cpp b/NAM/wavenet.cpp index f37eb89..90384ad 100644 --- a/NAM/wavenet.cpp +++ b/NAM/wavenet.cpp @@ -6,10 +6,10 @@ #include "wavenet.h" -nam::wavenet::_DilatedConv::_DilatedConv(const int inChannels, const int outChannels, const int kernel_size, +nam::wavenet::_DilatedConv::_DilatedConv(const int inChannels, const int outChannels, const int kernelSize, const int bias, const int dilation) { - this->SetSize(inChannels, outChannels, kernel_size, bias, dilation); + this->SetSize(inChannels, outChannels, kernelSize, bias, dilation); } void nam::wavenet::_Layer::SetWeights(weights_it& weights) @@ -60,13 +60,13 @@ void nam::wavenet::_Layer::set_num_frames_(const long numFrames) #define LAYER_ARRAY_BUFFER_SIZE 65536 nam::wavenet::_LayerArray::_LayerArray(const int input_size, const int condition_size, const int head_size, - const int channels, const int kernel_size, const std::vector& dilations, + const int channels, const int kernelSize, const std::vector& dilations, const std::string activation, const bool gated, const bool head_bias) : _rechannel(input_size, channels, false) , _head_rechannel(channels, head_size, head_bias) { for (size_t i = 0; i < dilations.size(); i++) - this->_layers.push_back(_Layer(condition_size, channels, kernel_size, dilations[i], activation, gated)); + this->_layers.push_back(_Layer(condition_size, channels, kernelSize, dilations[i], activation, gated)); const long receptiveField = this->_get_receptive_field(); for (size_t i = 0; i < dilations.size(); i++) { @@ -253,7 +253,7 @@ nam::wavenet::WaveNet::WaveNet(const std::vector { this->_layer_arrays.push_back(nam::wavenet::_LayerArray( layer_array_params[i].input_size, layer_array_params[i].condition_size, layer_array_params[i].head_size, - layer_array_params[i].channels, layer_array_params[i].kernel_size, layer_array_params[i].dilations, + layer_array_params[i].channels, layer_array_params[i].kernelSize, layer_array_params[i].dilations, layer_array_params[i].activation, layer_array_params[i].gated, layer_array_params[i].head_bias)); this->_layer_array_outputs.push_back(Eigen::MatrixXf(layer_array_params[i].channels, 0)); if (i == 0) diff --git a/NAM/wavenet.h b/NAM/wavenet.h index 0ca5389..eae7d87 100644 --- a/NAM/wavenet.h +++ b/NAM/wavenet.h @@ -16,16 +16,16 @@ namespace wavenet class _DilatedConv : public Conv1D { public: - _DilatedConv(const int inChannels, const int outChannels, const int kernel_size, const int bias, + _DilatedConv(const int inChannels, const int outChannels, const int kernelSize, const int bias, const int dilation); }; class _Layer { public: - _Layer(const int condition_size, const int channels, const int kernel_size, const int dilation, + _Layer(const int condition_size, const int channels, const int kernelSize, const int dilation, const std::string activation, const bool gated) - : _conv(channels, gated ? 2 * channels : channels, kernel_size, true, dilation) + : _conv(channels, gated ? 2 * channels : channels, kernelSize, true, dilation) , _input_mixin(condition_size, gated ? 2 * channels : channels, false) , _1x1(channels, channels, true) , _activation(activations::Activation::get_activation(activation)) @@ -64,7 +64,7 @@ class LayerArrayParams , condition_size(condition_size_) , head_size(head_size_) , channels(channels_) - , kernel_size(kernel_size_) + , kernelSize(kernel_size_) , activation(activation_) , gated(gated_) , head_bias(head_bias_) @@ -77,7 +77,7 @@ class LayerArrayParams const int condition_size; const int head_size; const int channels; - const int kernel_size; + const int kernelSize; std::vector dilations; const std::string activation; const bool gated; @@ -89,7 +89,7 @@ class _LayerArray { public: _LayerArray(const int input_size, const int condition_size, const int head_size, const int channels, - const int kernel_size, const std::vector& dilations, const std::string activation, const bool gated, + const int kernelSize, const std::vector& dilations, const std::string activation, const bool gated, const bool head_bias); void advance_buffers_(const int numFrames); From 3eafcee8c8b6a9f7b20aab0c9ae4e7ee425a5cd1 Mon Sep 17 00:00:00 2001 From: Oli Larkin Date: Sat, 20 Jan 2024 00:07:41 +0100 Subject: [PATCH 038/133] get_in_channels --- NAM/dsp.h | 2 +- NAM/wavenet.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/NAM/dsp.h b/NAM/dsp.h index a31bbc9..0a7de0c 100644 --- a/NAM/dsp.h +++ b/NAM/dsp.h @@ -129,7 +129,7 @@ class Conv1D // Indices on output for from j_start (to j_start + i_end - i_start) void Process(const Eigen::Ref input, Eigen::Ref output, const long i_start, const long i_end, const long j_start) const; - long get_in_channels() const { return this->mWeight.size() > 0 ? this->mWeight[0].cols() : 0; }; + long GetInChannels() const { return this->mWeight.size() > 0 ? this->mWeight[0].cols() : 0; }; long get_kernel_size() const { return this->mWeight.size(); }; long get_num_weights() const; long get_out_channels() const { return this->mWeight.size() > 0 ? this->mWeight[0].rows() : 0; }; diff --git a/NAM/wavenet.h b/NAM/wavenet.h index eae7d87..26f1a1d 100644 --- a/NAM/wavenet.h +++ b/NAM/wavenet.h @@ -36,7 +36,7 @@ class _Layer void Process(const Eigen::Ref input, const Eigen::Ref condition, Eigen::Ref head_input, Eigen::Ref output, const long i_start, const long j_start); void set_num_frames_(const long numFrames); - long get_channels() const { return this->_conv.get_in_channels(); }; + long get_channels() const { return this->_conv.GetInChannels(); }; int get_dilation() const { return this->_conv.get_dilation(); }; long get_kernel_size() const { return this->_conv.get_kernel_size(); }; From 1b6def18082011ecacc66e290057adf7ff118fb5 Mon Sep 17 00:00:00 2001 From: Oli Larkin Date: Sat, 20 Jan 2024 00:07:59 +0100 Subject: [PATCH 039/133] GetKernelSize --- NAM/dsp.h | 2 +- NAM/wavenet.cpp | 6 +++--- NAM/wavenet.h | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/NAM/dsp.h b/NAM/dsp.h index 0a7de0c..dd81ec2 100644 --- a/NAM/dsp.h +++ b/NAM/dsp.h @@ -130,7 +130,7 @@ class Conv1D void Process(const Eigen::Ref input, Eigen::Ref output, const long i_start, const long i_end, const long j_start) const; long GetInChannels() const { return this->mWeight.size() > 0 ? this->mWeight[0].cols() : 0; }; - long get_kernel_size() const { return this->mWeight.size(); }; + long GetKernelSize() const { return this->mWeight.size(); }; long get_num_weights() const; long get_out_channels() const { return this->mWeight.size() > 0 ? this->mWeight[0].rows() : 0; }; int get_dilation() const { return this->mDilation; }; diff --git a/NAM/wavenet.cpp b/NAM/wavenet.cpp index 90384ad..49498a9 100644 --- a/NAM/wavenet.cpp +++ b/NAM/wavenet.cpp @@ -85,7 +85,7 @@ long nam::wavenet::_LayerArray::get_receptive_field() const { long result = 0; for (size_t i = 0; i < this->_layers.size(); i++) - result += this->_layers[i].get_dilation() * (this->_layers[i].get_kernel_size() - 1); + result += this->_layers[i].get_dilation() * (this->_layers[i].GetKernelSize() - 1); return result; } @@ -161,7 +161,7 @@ long nam::wavenet::_LayerArray::_get_receptive_field() const // TODO remove this and use get_receptive_field() instead! long res = 1; for (size_t i = 0; i < this->_layers.size(); i++) - res += (this->_layers[i].get_kernel_size() - 1) * this->_layers[i].get_dilation(); + res += (this->_layers[i].GetKernelSize() - 1) * this->_layers[i].get_dilation(); return res; } @@ -172,7 +172,7 @@ void nam::wavenet::_LayerArray::RewindBuffers() const long start = this->_get_receptive_field() - 1; for (size_t i = 0; i < this->_layer_buffers.size(); i++) { - const long d = (this->_layers[i].get_kernel_size() - 1) * this->_layers[i].get_dilation(); + const long d = (this->_layers[i].GetKernelSize() - 1) * this->_layers[i].get_dilation(); this->_layer_buffers[i].middleCols(start - d, d) = this->_layer_buffers[i].middleCols(this->_buffer_start - d, d); } this->_buffer_start = start; diff --git a/NAM/wavenet.h b/NAM/wavenet.h index 26f1a1d..3bc710c 100644 --- a/NAM/wavenet.h +++ b/NAM/wavenet.h @@ -38,7 +38,7 @@ class _Layer void set_num_frames_(const long numFrames); long get_channels() const { return this->_conv.GetInChannels(); }; int get_dilation() const { return this->_conv.get_dilation(); }; - long get_kernel_size() const { return this->_conv.get_kernel_size(); }; + long GetKernelSize() const { return this->_conv.GetKernelSize(); }; private: // The dilated convolution at the front of the block From 52ad4c41bdde46114dd6ebbe0a3a075221679b94 Mon Sep 17 00:00:00 2001 From: Oli Larkin Date: Sat, 20 Jan 2024 00:08:15 +0100 Subject: [PATCH 040/133] get_num_weights --- NAM/dsp.cpp | 2 +- NAM/dsp.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/NAM/dsp.cpp b/NAM/dsp.cpp index 03412ac..9f1838c 100644 --- a/NAM/dsp.cpp +++ b/NAM/dsp.cpp @@ -220,7 +220,7 @@ void nam::Conv1D::Process(const Eigen::Ref input, Eigen:: output.middleCols(j_start, ncols).colwise() += this->mBias; } -long nam::Conv1D::get_num_weights() const +long nam::Conv1D::GetNumWeights() const { long num_weights = this->mBias.size(); for (size_t i = 0; i < this->mWeight.size(); i++) diff --git a/NAM/dsp.h b/NAM/dsp.h index dd81ec2..39358f0 100644 --- a/NAM/dsp.h +++ b/NAM/dsp.h @@ -131,7 +131,7 @@ class Conv1D const long j_start) const; long GetInChannels() const { return this->mWeight.size() > 0 ? this->mWeight[0].cols() : 0; }; long GetKernelSize() const { return this->mWeight.size(); }; - long get_num_weights() const; + long GetNumWeights() const; long get_out_channels() const { return this->mWeight.size() > 0 ? this->mWeight[0].rows() : 0; }; int get_dilation() const { return this->mDilation; }; From 97c0223052fabea14916a94290540cfce3583948 Mon Sep 17 00:00:00 2001 From: Oli Larkin Date: Sat, 20 Jan 2024 00:08:32 +0100 Subject: [PATCH 041/133] get_out_channels --- NAM/convnet.cpp | 8 ++++---- NAM/convnet.h | 2 +- NAM/dsp.h | 4 ++-- NAM/wavenet.cpp | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/NAM/convnet.cpp b/NAM/convnet.cpp index 8cb0674..5f3cf09 100644 --- a/NAM/convnet.cpp +++ b/NAM/convnet.cpp @@ -69,9 +69,9 @@ void nam::convnet::ConvNetBlock::Process(const Eigen::Ref this->activation->apply(output.middleCols(i_start, ncols)); } -long nam::convnet::ConvNetBlock::get_out_channels() const +long nam::convnet::ConvNetBlock::GetOutChannels() const { - return this->conv.get_out_channels(); + return this->conv.GetOutChannels(); } nam::convnet::_Head::_Head(const int channels, weights_it& weights) @@ -154,10 +154,10 @@ void nam::convnet::ConvNet::UpdateBuffers(float* input, const int numFrames) for (size_t i = 1; i < this->_block_vals.size(); i++) { - if (this->_block_vals[i].rows() == this->_blocks[i - 1].get_out_channels() + if (this->_block_vals[i].rows() == this->_blocks[i - 1].GetOutChannels() && this->_block_vals[i].cols() == Eigen::Index(buffer_size)) continue; // Already has correct size - this->_block_vals[i].resize(this->_blocks[i - 1].get_out_channels(), buffer_size); + this->_block_vals[i].resize(this->_blocks[i - 1].GetOutChannels(), buffer_size); this->_block_vals[i].setZero(); } } diff --git a/NAM/convnet.h b/NAM/convnet.h index ac6fd59..31c1e4f 100644 --- a/NAM/convnet.h +++ b/NAM/convnet.h @@ -43,7 +43,7 @@ class ConvNetBlock void SetWeights(const int inChannels, const int outChannels, const int dilation, const bool batchnorm, const std::string activation, weights_it& weights); void Process(const Eigen::Ref input, Eigen::Ref output, const long i_start, const long i_end) const; - long get_out_channels() const; + long GetOutChannels() const; Conv1D conv; private: diff --git a/NAM/dsp.h b/NAM/dsp.h index 39358f0..b2f3ba1 100644 --- a/NAM/dsp.h +++ b/NAM/dsp.h @@ -132,7 +132,7 @@ class Conv1D long GetInChannels() const { return this->mWeight.size() > 0 ? this->mWeight[0].cols() : 0; }; long GetKernelSize() const { return this->mWeight.size(); }; long GetNumWeights() const; - long get_out_channels() const { return this->mWeight.size() > 0 ? this->mWeight[0].rows() : 0; }; + long GetOutChannels() const { return this->mWeight.size() > 0 ? this->mWeight[0].rows() : 0; }; int get_dilation() const { return this->mDilation; }; private: @@ -153,7 +153,7 @@ class Conv1x1 // :return: (N,Cout) or (Cout,), respectively Eigen::MatrixXf Process(const Eigen::Ref input) const; - long get_out_channels() const { return this->mWeight.rows(); }; + long GetOutChannels() const { return this->mWeight.rows(); }; private: Eigen::MatrixXf mWeight; diff --git a/NAM/wavenet.cpp b/NAM/wavenet.cpp index 49498a9..133aa33 100644 --- a/NAM/wavenet.cpp +++ b/NAM/wavenet.cpp @@ -48,10 +48,10 @@ void nam::wavenet::_Layer::Process(const Eigen::Ref input void nam::wavenet::_Layer::set_num_frames_(const long numFrames) { - if (this->_z.rows() == this->_conv.get_out_channels() && this->_z.cols() == numFrames) + if (this->_z.rows() == this->_conv.GetOutChannels() && this->_z.cols() == numFrames) return; // Already has correct size - this->_z.resize(this->_conv.get_out_channels(), numFrames); + this->_z.resize(this->_conv.GetOutChannels(), numFrames); this->_z.setZero(); } From 92d6769c0a2ebf21bd14d95dbbf21517479a0f8d Mon Sep 17 00:00:00 2001 From: Oli Larkin Date: Sat, 20 Jan 2024 00:08:51 +0100 Subject: [PATCH 042/133] GetDilation --- NAM/convnet.cpp | 2 +- NAM/dsp.h | 2 +- NAM/wavenet.cpp | 6 +++--- NAM/wavenet.h | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/NAM/convnet.cpp b/NAM/convnet.cpp index 5f3cf09..e7687a1 100644 --- a/NAM/convnet.cpp +++ b/NAM/convnet.cpp @@ -172,7 +172,7 @@ void nam::convnet::ConvNet::RewindBuffers() { // We actually don't need to pull back a lot...just as far as the first // input sample would grab from dilation - const long dilation = this->_blocks[k].conv.get_dilation(); + const long dilation = this->_blocks[k].conv.GetDilation(); for (long i = this->mReceptiveField - dilation, j = this->mInputBufferOffset - dilation; j < this->mInputBufferOffset; i++, j++) for (long r = 0; r < this->_block_vals[k].rows(); r++) diff --git a/NAM/dsp.h b/NAM/dsp.h index b2f3ba1..894893e 100644 --- a/NAM/dsp.h +++ b/NAM/dsp.h @@ -133,7 +133,7 @@ class Conv1D long GetKernelSize() const { return this->mWeight.size(); }; long GetNumWeights() const; long GetOutChannels() const { return this->mWeight.size() > 0 ? this->mWeight[0].rows() : 0; }; - int get_dilation() const { return this->mDilation; }; + int GetDilation() const { return this->mDilation; }; private: // Gonna wing this... diff --git a/NAM/wavenet.cpp b/NAM/wavenet.cpp index 133aa33..6e1aa1c 100644 --- a/NAM/wavenet.cpp +++ b/NAM/wavenet.cpp @@ -85,7 +85,7 @@ long nam::wavenet::_LayerArray::get_receptive_field() const { long result = 0; for (size_t i = 0; i < this->_layers.size(); i++) - result += this->_layers[i].get_dilation() * (this->_layers[i].GetKernelSize() - 1); + result += this->_layers[i].GetDilation() * (this->_layers[i].GetKernelSize() - 1); return result; } @@ -161,7 +161,7 @@ long nam::wavenet::_LayerArray::_get_receptive_field() const // TODO remove this and use get_receptive_field() instead! long res = 1; for (size_t i = 0; i < this->_layers.size(); i++) - res += (this->_layers[i].GetKernelSize() - 1) * this->_layers[i].get_dilation(); + res += (this->_layers[i].GetKernelSize() - 1) * this->_layers[i].GetDilation(); return res; } @@ -172,7 +172,7 @@ void nam::wavenet::_LayerArray::RewindBuffers() const long start = this->_get_receptive_field() - 1; for (size_t i = 0; i < this->_layer_buffers.size(); i++) { - const long d = (this->_layers[i].GetKernelSize() - 1) * this->_layers[i].get_dilation(); + const long d = (this->_layers[i].GetKernelSize() - 1) * this->_layers[i].GetDilation(); this->_layer_buffers[i].middleCols(start - d, d) = this->_layer_buffers[i].middleCols(this->_buffer_start - d, d); } this->_buffer_start = start; diff --git a/NAM/wavenet.h b/NAM/wavenet.h index 3bc710c..f757fde 100644 --- a/NAM/wavenet.h +++ b/NAM/wavenet.h @@ -37,7 +37,7 @@ class _Layer Eigen::Ref output, const long i_start, const long j_start); void set_num_frames_(const long numFrames); long get_channels() const { return this->_conv.GetInChannels(); }; - int get_dilation() const { return this->_conv.get_dilation(); }; + int GetDilation() const { return this->_conv.GetDilation(); }; long GetKernelSize() const { return this->_conv.GetKernelSize(); }; private: From 180a4759a7b1143659c38b9b21fd91bb6c0abc9a Mon Sep 17 00:00:00 2001 From: Oli Larkin Date: Sat, 20 Jan 2024 00:09:57 +0100 Subject: [PATCH 043/133] VerifyConfigVersion --- NAM/dsp.h | 2 +- NAM/get_dsp.cpp | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/NAM/dsp.h b/NAM/dsp.h index 894893e..3bd802c 100644 --- a/NAM/dsp.h +++ b/NAM/dsp.h @@ -191,7 +191,7 @@ struct dspData // Verify that the config that we are building our model from is supported by // this plugin version. -void verify_config_version(const std::string version); +void VerifyConfigVersion(const std::string version); // Takes the model file and uses it to instantiate an instance of DSP. std::unique_ptr get_dsp(const std::filesystem::path model_file); diff --git a/NAM/get_dsp.cpp b/NAM/get_dsp.cpp index b124bab..d9b01d1 100644 --- a/NAM/get_dsp.cpp +++ b/NAM/get_dsp.cpp @@ -53,7 +53,7 @@ Version ParseVersion(const std::string& versionStr) return version; } -void verify_config_version(const std::string versionStr) +void VerifyConfigVersion(const std::string versionStr) { Version version = ParseVersion(versionStr); if (version.major != 0 || version.minor != 5) @@ -93,7 +93,7 @@ std::unique_ptr get_dsp(const std::filesystem::path config_filename, dspDat std::ifstream i(config_filename); nlohmann::json j; i >> j; - verify_config_version(j["version"]); + VerifyConfigVersion(j["version"]); auto architecture = j["architecture"]; nlohmann::json config = j["config"]; @@ -124,7 +124,7 @@ std::unique_ptr get_dsp(const std::filesystem::path config_filename, dspDat std::unique_ptr get_dsp(dspData& conf) { - verify_config_version(conf.version); + VerifyConfigVersion(conf.version); auto& architecture = conf.architecture; nlohmann::json& config = conf.config; From b9519c6250b14dd98f9fd508703831983e72e4d4 Mon Sep 17 00:00:00 2001 From: Oli Larkin Date: Sat, 20 Jan 2024 00:10:24 +0100 Subject: [PATCH 044/133] get_dsp --- NAM/dsp.h | 10 +++++----- NAM/get_dsp.cpp | 14 +++++++------- tools/benchmodel.cpp | 2 +- tools/loadmodel.cpp | 2 +- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/NAM/dsp.h b/NAM/dsp.h index 3bd802c..b1625a8 100644 --- a/NAM/dsp.h +++ b/NAM/dsp.h @@ -162,11 +162,11 @@ class Conv1x1 }; // Utilities ================================================================== -// Implemented in get_dsp.cpp +// Implemented in GetDSP.cpp // Data for a DSP object // :param version: Data version. Follows the conventions established in the trainer code. -// :param architecture: Defines the high-level architecture. Supported are (as per `get-dsp()` in get_dsp.cpp): +// :param architecture: Defines the high-level architecture. Supported are (as per `get-dsp()` in GetDSP.cpp): // * "CatLSTM" // * "CatWaveNet" // * "ConvNet" @@ -194,11 +194,11 @@ struct dspData void VerifyConfigVersion(const std::string version); // Takes the model file and uses it to instantiate an instance of DSP. -std::unique_ptr get_dsp(const std::filesystem::path model_file); +std::unique_ptr GetDSP(const std::filesystem::path model_file); // Creates an instance of DSP. Also returns a dspData struct that holds the data of the model. -std::unique_ptr get_dsp(const std::filesystem::path model_file, dspData& returnedConfig); +std::unique_ptr GetDSP(const std::filesystem::path model_file, dspData& returnedConfig); // Instantiates a DSP object from dsp_config struct. -std::unique_ptr get_dsp(dspData& conf); +std::unique_ptr GetDSP(dspData& conf); // Legacy loader for directory-type DSPs std::unique_ptr get_dsp_legacy(const std::filesystem::path dirname); }; // namespace nam diff --git a/NAM/get_dsp.cpp b/NAM/get_dsp.cpp index d9b01d1..31be09e 100644 --- a/NAM/get_dsp.cpp +++ b/NAM/get_dsp.cpp @@ -80,13 +80,13 @@ std::vector GetWeights(nlohmann::json const& j, const std::filesystem::pa throw std::runtime_error("Corrupted model file is missing weights."); } -std::unique_ptr get_dsp(const std::filesystem::path config_filename) +std::unique_ptr GetDSP(const std::filesystem::path config_filename) { dspData temp; - return get_dsp(config_filename, temp); + return GetDSP(config_filename, temp); } -std::unique_ptr get_dsp(const std::filesystem::path config_filename, dspData& returnedConfig) +std::unique_ptr GetDSP(const std::filesystem::path config_filename, dspData& returnedConfig) { if (!std::filesystem::exists(config_filename)) throw std::runtime_error("Config JSON doesn't exist!\n"); @@ -113,16 +113,16 @@ std::unique_ptr get_dsp(const std::filesystem::path config_filename, dspDat } - /*Copy to a new dsp_config object for get_dsp below, + /*Copy to a new dsp_config object for GetDSP below, since not sure if weights actually get modified as being non-const references on some - model constructors inside get_dsp(dsp_config& conf). + model constructors inside GetDSP(dsp_config& conf). We need to return unmodified version of dsp_config via returnedConfig.*/ dspData conf = returnedConfig; - return get_dsp(conf); + return GetDSP(conf); } -std::unique_ptr get_dsp(dspData& conf) +std::unique_ptr GetDSP(dspData& conf) { VerifyConfigVersion(conf.version); diff --git a/tools/benchmodel.cpp b/tools/benchmodel.cpp index 986093a..15467c0 100644 --- a/tools/benchmodel.cpp +++ b/tools/benchmodel.cpp @@ -27,7 +27,7 @@ int main(int argc, char* argv[]) std::unique_ptr model; model.reset(); - model = std::move(nam::get_dsp(modelPath)); + model = std::move(nam::GetDSP(modelPath)); if (model == nullptr) { diff --git a/tools/loadmodel.cpp b/tools/loadmodel.cpp index 8a1b889..e415b27 100644 --- a/tools/loadmodel.cpp +++ b/tools/loadmodel.cpp @@ -9,7 +9,7 @@ int main(int argc, char* argv[]) fprintf(stderr, "Loading model [%s]\n", modelPath); - auto model = nam::get_dsp(modelPath); + auto model = nam::GetDSP(modelPath); if (model != nullptr) { From 7afdef895302e9ed1c2f88ef164ea7099bca859d Mon Sep 17 00:00:00 2001 From: Oli Larkin Date: Sat, 20 Jan 2024 00:10:43 +0100 Subject: [PATCH 045/133] model_file --- NAM/dsp.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/NAM/dsp.h b/NAM/dsp.h index b1625a8..a17ef8d 100644 --- a/NAM/dsp.h +++ b/NAM/dsp.h @@ -194,9 +194,9 @@ struct dspData void VerifyConfigVersion(const std::string version); // Takes the model file and uses it to instantiate an instance of DSP. -std::unique_ptr GetDSP(const std::filesystem::path model_file); +std::unique_ptr GetDSP(const std::filesystem::path modelFile); // Creates an instance of DSP. Also returns a dspData struct that holds the data of the model. -std::unique_ptr GetDSP(const std::filesystem::path model_file, dspData& returnedConfig); +std::unique_ptr GetDSP(const std::filesystem::path modelFile, dspData& returnedConfig); // Instantiates a DSP object from dsp_config struct. std::unique_ptr GetDSP(dspData& conf); // Legacy loader for directory-type DSPs From 116a3c5a2a590d05480459224b377c78f1e798a3 Mon Sep 17 00:00:00 2001 From: Oli Larkin Date: Sat, 20 Jan 2024 00:11:21 +0100 Subject: [PATCH 046/133] GetDSPLegacy --- NAM/dsp.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NAM/dsp.h b/NAM/dsp.h index a17ef8d..8f9fa36 100644 --- a/NAM/dsp.h +++ b/NAM/dsp.h @@ -200,5 +200,5 @@ std::unique_ptr GetDSP(const std::filesystem::path modelFile, dspData& retu // Instantiates a DSP object from dsp_config struct. std::unique_ptr GetDSP(dspData& conf); // Legacy loader for directory-type DSPs -std::unique_ptr get_dsp_legacy(const std::filesystem::path dirname); +std::unique_ptr GetDSPLegacy(const std::filesystem::path dirname); }; // namespace nam From 0aebcddb3bf4c218f064d3cb68da5dcb959fd4a7 Mon Sep 17 00:00:00 2001 From: Oli Larkin Date: Sat, 20 Jan 2024 00:13:38 +0100 Subject: [PATCH 047/133] apply --- NAM/activations.h | 20 ++++++++++---------- NAM/convnet.cpp | 2 +- NAM/wavenet.cpp | 6 +++--- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/NAM/activations.h b/NAM/activations.h index 51b03d9..d19a424 100644 --- a/NAM/activations.h +++ b/NAM/activations.h @@ -45,13 +45,13 @@ class Activation public: Activation() = default; virtual ~Activation() = default; - virtual void apply(Eigen::Ref matrix) { apply(matrix.data(), matrix.rows() * matrix.cols()); } - virtual void apply(Eigen::Block block) { apply(block.data(), block.rows() * block.cols()); } - virtual void apply(Eigen::Block block) + virtual void Apply(Eigen::Ref matrix) { Apply(matrix.data(), matrix.rows() * matrix.cols()); } + virtual void Apply(Eigen::Block block) { Apply(block.data(), block.rows() * block.cols()); } + virtual void Apply(Eigen::Block block) { - apply(block.data(), block.rows() * block.cols()); + Apply(block.data(), block.rows() * block.cols()); } - virtual void apply(float* data, long size) {} + virtual void Apply(float* data, long size) {} static Activation* get_activation(const std::string name); static void enable_fast_tanh(); @@ -65,7 +65,7 @@ class Activation class ActivationTanh : public Activation { public: - void apply(float* data, long size) override + void Apply(float* data, long size) override { for (long pos = 0; pos < size; pos++) { @@ -77,7 +77,7 @@ class ActivationTanh : public Activation class ActivationHardTanh : public Activation { public: - void apply(float* data, long size) override + void Apply(float* data, long size) override { for (long pos = 0; pos < size; pos++) { @@ -89,7 +89,7 @@ class ActivationHardTanh : public Activation class ActivationFastTanh : public Activation { public: - void apply(float* data, long size) override + void Apply(float* data, long size) override { for (long pos = 0; pos < size; pos++) { @@ -101,7 +101,7 @@ class ActivationFastTanh : public Activation class ActivationReLU : public Activation { public: - void apply(float* data, long size) override + void Apply(float* data, long size) override { for (long pos = 0; pos < size; pos++) { @@ -113,7 +113,7 @@ class ActivationReLU : public Activation class ActivationSigmoid : public Activation { public: - void apply(float* data, long size) override + void Apply(float* data, long size) override { for (long pos = 0; pos < size; pos++) { diff --git a/NAM/convnet.cpp b/NAM/convnet.cpp index e7687a1..fce73eb 100644 --- a/NAM/convnet.cpp +++ b/NAM/convnet.cpp @@ -66,7 +66,7 @@ void nam::convnet::ConvNetBlock::Process(const Eigen::Ref if (this->_batchnorm) this->batchnorm.Process(output, i_start, i_end); - this->activation->apply(output.middleCols(i_start, ncols)); + this->activation->Apply(output.middleCols(i_start, ncols)); } long nam::convnet::ConvNetBlock::GetOutChannels() const diff --git a/NAM/wavenet.cpp b/NAM/wavenet.cpp index 6e1aa1c..45186e5 100644 --- a/NAM/wavenet.cpp +++ b/NAM/wavenet.cpp @@ -30,11 +30,11 @@ void nam::wavenet::_Layer::Process(const Eigen::Ref input // Mix-in condition this->_z += this->_input_mixin.Process(condition); - this->_activation->apply(this->_z); + this->_activation->Apply(this->_z); if (this->_gated) { - activations::Activation::get_activation("Sigmoid")->apply(this->_z.block(channels, 0, channels, this->_z.cols())); + activations::Activation::get_activation("Sigmoid")->Apply(this->_z.block(channels, 0, channels, this->_z.cols())); this->_z.topRows(channels).array() *= this->_z.bottomRows(channels).array(); // this->_z.topRows(channels) = this->_z.topRows(channels).cwiseProduct( @@ -235,7 +235,7 @@ void nam::wavenet::_Head::set_num_frames_(const long numFrames) void nam::wavenet::_Head::_apply_activation_(Eigen::Ref x) { - this->_activation->apply(x); + this->_activation->Apply(x); } // WaveNet ==================================================================== From 5ecaa6bf83a97141d57a2d76a788b2802a768315 Mon Sep 17 00:00:00 2001 From: Oli Larkin Date: Sat, 20 Jan 2024 00:14:17 +0100 Subject: [PATCH 048/133] get_activation --- NAM/activations.cpp | 2 +- NAM/activations.h | 2 +- NAM/convnet.cpp | 2 +- NAM/wavenet.cpp | 4 ++-- NAM/wavenet.h | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/NAM/activations.cpp b/NAM/activations.cpp index 92f1d8d..56c6cf5 100644 --- a/NAM/activations.cpp +++ b/NAM/activations.cpp @@ -13,7 +13,7 @@ std::unordered_map nam::activations: nam::activations::Activation* tanh_bak = nullptr; -nam::activations::Activation* nam::activations::Activation::get_activation(const std::string name) +nam::activations::Activation* nam::activations::Activation::GetActivation(const std::string name) { if (_activations.find(name) == _activations.end()) return nullptr; diff --git a/NAM/activations.h b/NAM/activations.h index d19a424..232ea8b 100644 --- a/NAM/activations.h +++ b/NAM/activations.h @@ -53,7 +53,7 @@ class Activation } virtual void Apply(float* data, long size) {} - static Activation* get_activation(const std::string name); + static Activation* GetActivation(const std::string name); static void enable_fast_tanh(); static void disable_fast_tanh(); static bool using_fast_tanh; diff --git a/NAM/convnet.cpp b/NAM/convnet.cpp index fce73eb..d932e6e 100644 --- a/NAM/convnet.cpp +++ b/NAM/convnet.cpp @@ -55,7 +55,7 @@ void nam::convnet::ConvNetBlock::SetWeights(const int inChannels, const int outC this->conv.SetSizeAndWeights(inChannels, outChannels, 2, dilation, !batchnorm, weights); if (this->_batchnorm) this->batchnorm = BatchNorm(outChannels, weights); - this->activation = activations::Activation::get_activation(activation); + this->activation = activations::Activation::GetActivation(activation); } void nam::convnet::ConvNetBlock::Process(const Eigen::Ref input, Eigen::Ref output, const long i_start, diff --git a/NAM/wavenet.cpp b/NAM/wavenet.cpp index 45186e5..cb1caf0 100644 --- a/NAM/wavenet.cpp +++ b/NAM/wavenet.cpp @@ -34,7 +34,7 @@ void nam::wavenet::_Layer::Process(const Eigen::Ref input if (this->_gated) { - activations::Activation::get_activation("Sigmoid")->Apply(this->_z.block(channels, 0, channels, this->_z.cols())); + activations::Activation::GetActivation("Sigmoid")->Apply(this->_z.block(channels, 0, channels, this->_z.cols())); this->_z.topRows(channels).array() *= this->_z.bottomRows(channels).array(); // this->_z.topRows(channels) = this->_z.topRows(channels).cwiseProduct( @@ -183,7 +183,7 @@ void nam::wavenet::_LayerArray::RewindBuffers() nam::wavenet::_Head::_Head(const int input_size, const int num_layers, const int channels, const std::string activation) : _channels(channels) , _head(num_layers > 0 ? channels : input_size, 1, true) -, _activation(activations::Activation::get_activation(activation)) +, _activation(activations::Activation::GetActivation(activation)) { assert(num_layers > 0); int dx = input_size; diff --git a/NAM/wavenet.h b/NAM/wavenet.h index f757fde..e7f40d0 100644 --- a/NAM/wavenet.h +++ b/NAM/wavenet.h @@ -28,7 +28,7 @@ class _Layer : _conv(channels, gated ? 2 * channels : channels, kernelSize, true, dilation) , _input_mixin(condition_size, gated ? 2 * channels : channels, false) , _1x1(channels, channels, true) - , _activation(activations::Activation::get_activation(activation)) + , _activation(activations::Activation::GetActivation(activation)) , _gated(gated){}; void SetWeights(weights_it& weights); // :param `input`: from previous layer From 52b8bdfccf9c1f6d69a642c7ac6f1de3fb4adfb3 Mon Sep 17 00:00:00 2001 From: Oli Larkin Date: Sat, 20 Jan 2024 00:14:54 +0100 Subject: [PATCH 049/133] enable_fast_tanh --- NAM/activations.cpp | 2 +- NAM/activations.h | 2 +- tools/benchmodel.cpp | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/NAM/activations.cpp b/NAM/activations.cpp index 56c6cf5..d363d1c 100644 --- a/NAM/activations.cpp +++ b/NAM/activations.cpp @@ -21,7 +21,7 @@ nam::activations::Activation* nam::activations::Activation::GetActivation(const return _activations[name]; } -void nam::activations::Activation::enable_fast_tanh() +void nam::activations::Activation::EnableFastTanh() { nam::activations::Activation::using_fast_tanh = true; diff --git a/NAM/activations.h b/NAM/activations.h index 232ea8b..51a14ee 100644 --- a/NAM/activations.h +++ b/NAM/activations.h @@ -54,7 +54,7 @@ class Activation virtual void Apply(float* data, long size) {} static Activation* GetActivation(const std::string name); - static void enable_fast_tanh(); + static void EnableFastTanh(); static void disable_fast_tanh(); static bool using_fast_tanh; diff --git a/tools/benchmodel.cpp b/tools/benchmodel.cpp index 15467c0..6055e73 100644 --- a/tools/benchmodel.cpp +++ b/tools/benchmodel.cpp @@ -22,7 +22,7 @@ int main(int argc, char* argv[]) std::cout << "Loading model " << modelPath << "\n"; // Turn on fast tanh approximation - nam::activations::Activation::enable_fast_tanh(); + nam::activations::Activation::EnableFastTanh(); std::unique_ptr model; From 7f09e1d8d821a09f47785eac2ef78f280cc9f673 Mon Sep 17 00:00:00 2001 From: Oli Larkin Date: Sat, 20 Jan 2024 00:15:19 +0100 Subject: [PATCH 050/133] disable_fast_tanh --- NAM/activations.cpp | 2 +- NAM/activations.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/NAM/activations.cpp b/NAM/activations.cpp index d363d1c..45b6bd5 100644 --- a/NAM/activations.cpp +++ b/NAM/activations.cpp @@ -32,7 +32,7 @@ void nam::activations::Activation::EnableFastTanh() } } -void nam::activations::Activation::disable_fast_tanh() +void nam::activations::Activation::DisableFastTanh() { nam::activations::Activation::using_fast_tanh = false; diff --git a/NAM/activations.h b/NAM/activations.h index 51a14ee..769b838 100644 --- a/NAM/activations.h +++ b/NAM/activations.h @@ -55,7 +55,7 @@ class Activation static Activation* GetActivation(const std::string name); static void EnableFastTanh(); - static void disable_fast_tanh(); + static void DisableFastTanh(); static bool using_fast_tanh; protected: From 56f4015fc72fcecdc590d36f4a94498548d46093 Mon Sep 17 00:00:00 2001 From: Oli Larkin Date: Sat, 20 Jan 2024 00:15:47 +0100 Subject: [PATCH 051/133] sUsingFastTanh --- NAM/activations.cpp | 6 +++--- NAM/activations.h | 2 +- NAM/lstm.cpp | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/NAM/activations.cpp b/NAM/activations.cpp index 45b6bd5..ca37364 100644 --- a/NAM/activations.cpp +++ b/NAM/activations.cpp @@ -6,7 +6,7 @@ nam::activations::ActivationHardTanh _HARD_TANH = nam::activations::ActivationHa nam::activations::ActivationReLU _RELU = nam::activations::ActivationReLU(); nam::activations::ActivationSigmoid _SIGMOID = nam::activations::ActivationSigmoid(); -bool nam::activations::Activation::using_fast_tanh = false; +bool nam::activations::Activation::sUsingFastTanh = false; std::unordered_map nam::activations::Activation::_activations = {{"Tanh", &_TANH}, {"Hardtanh", &_HARD_TANH}, {"Fasttanh", &_FAST_TANH}, {"ReLU", &_RELU}, {"Sigmoid", &_SIGMOID}}; @@ -23,7 +23,7 @@ nam::activations::Activation* nam::activations::Activation::GetActivation(const void nam::activations::Activation::EnableFastTanh() { - nam::activations::Activation::using_fast_tanh = true; + nam::activations::Activation::sUsingFastTanh = true; if (_activations["Tanh"] != _activations["Fasttanh"]) { @@ -34,7 +34,7 @@ void nam::activations::Activation::EnableFastTanh() void nam::activations::Activation::DisableFastTanh() { - nam::activations::Activation::using_fast_tanh = false; + nam::activations::Activation::sUsingFastTanh = false; if (_activations["Tanh"] == _activations["Fasttanh"]) { diff --git a/NAM/activations.h b/NAM/activations.h index 769b838..d70dafc 100644 --- a/NAM/activations.h +++ b/NAM/activations.h @@ -56,7 +56,7 @@ class Activation static Activation* GetActivation(const std::string name); static void EnableFastTanh(); static void DisableFastTanh(); - static bool using_fast_tanh; + static bool sUsingFastTanh; protected: static std::unordered_map _activations; diff --git a/NAM/lstm.cpp b/NAM/lstm.cpp index ccde007..acaea47 100644 --- a/NAM/lstm.cpp +++ b/NAM/lstm.cpp @@ -42,7 +42,7 @@ void nam::lstm::LSTMCell::Process(const Eigen::VectorXf& x) const long o_offset = 3 * hidden_size; const long h_offset = input_size; - if (activations::Activation::using_fast_tanh) + if (activations::Activation::sUsingFastTanh) { for (auto i = 0; i < hidden_size; i++) this->_c[i] = From f454366200c8ed3491a1d43100fb589344d03e00 Mon Sep 17 00:00:00 2001 From: Oli Larkin Date: Sat, 20 Jan 2024 00:17:57 +0100 Subject: [PATCH 052/133] _verify_weights --- NAM/convnet.cpp | 4 ++-- NAM/convnet.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/NAM/convnet.cpp b/NAM/convnet.cpp index d932e6e..83ebf54 100644 --- a/NAM/convnet.cpp +++ b/NAM/convnet.cpp @@ -96,7 +96,7 @@ nam::convnet::ConvNet::ConvNet(const int channels, const std::vector& dilat const double expectedSampleRate) : Buffer(*std::max_element(dilations.begin(), dilations.end()), expectedSampleRate) { - this->_verify_weights(channels, dilations, batchnorm, weights.size()); + this->VerifyWeights(channels, dilations, batchnorm, weights.size()); this->_blocks.resize(dilations.size()); weights_it it = weights.begin(); for (size_t i = 0; i < dilations.size(); i++) @@ -134,7 +134,7 @@ void nam::convnet::ConvNet::Process(float* input, float* output, const int numFr output[s] = this->_head_output(s); } -void nam::convnet::ConvNet::_verify_weights(const int channels, const std::vector& dilations, const bool batchnorm, +void nam::convnet::ConvNet::VerifyWeights(const int channels, const std::vector& dilations, const bool batchnorm, const size_t actual_weights) { // TODO diff --git a/NAM/convnet.h b/NAM/convnet.h index 31c1e4f..4b1a0aa 100644 --- a/NAM/convnet.h +++ b/NAM/convnet.h @@ -76,7 +76,7 @@ class ConvNet : public Buffer std::vector _block_vals; Eigen::VectorXf _head_output; _Head _head; - void _verify_weights(const int channels, const std::vector& dilations, const bool batchnorm, + void VerifyWeights(const int channels, const std::vector& dilations, const bool batchnorm, const size_t actual_weights); void UpdateBuffers(float* input, const int numFrames) override; void RewindBuffers() override; From 8097e06c907d99ac2390fea9e5cb2446eaba825a Mon Sep 17 00:00:00 2001 From: Oli Larkin Date: Sat, 20 Jan 2024 00:18:34 +0100 Subject: [PATCH 053/133] _head --- NAM/convnet.cpp | 4 ++-- NAM/convnet.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/NAM/convnet.cpp b/NAM/convnet.cpp index 83ebf54..7623dc4 100644 --- a/NAM/convnet.cpp +++ b/NAM/convnet.cpp @@ -105,7 +105,7 @@ nam::convnet::ConvNet::ConvNet(const int channels, const std::vector& dilat for (auto& matrix : this->_block_vals) matrix.setZero(); std::fill(this->mInputBuffer.begin(), this->mInputBuffer.end(), 0.0f); - this->_head = _Head(channels, it); + this->mHead = _Head(channels, it); if (it != weights.end()) throw std::runtime_error("Didn't touch all the weights when initializing ConvNet"); @@ -128,7 +128,7 @@ void nam::convnet::ConvNet::Process(float* input, float* output, const int numFr for (size_t i = 0; i < this->_blocks.size(); i++) this->_blocks[i].Process(this->_block_vals[i], this->_block_vals[i + 1], i_start, i_end); // TODO clean up this allocation - this->_head.Process(this->_block_vals[this->_blocks.size()], this->_head_output, i_start, i_end); + this->mHead.Process(this->_block_vals[this->_blocks.size()], this->_head_output, i_start, i_end); // Copy to required output array (TODO tighten this up) for (int s = 0; s < numFrames; s++) output[s] = this->_head_output(s); diff --git a/NAM/convnet.h b/NAM/convnet.h index 4b1a0aa..d9e0ce1 100644 --- a/NAM/convnet.h +++ b/NAM/convnet.h @@ -75,7 +75,7 @@ class ConvNet : public Buffer std::vector _blocks; std::vector _block_vals; Eigen::VectorXf _head_output; - _Head _head; + _Head mHead; void VerifyWeights(const int channels, const std::vector& dilations, const bool batchnorm, const size_t actual_weights); void UpdateBuffers(float* input, const int numFrames) override; From b04e553847f1f2baaac95f2dda17771ed638f63e Mon Sep 17 00:00:00 2001 From: Oli Larkin Date: Sat, 20 Jan 2024 00:19:03 +0100 Subject: [PATCH 054/133] _head_output --- NAM/convnet.cpp | 4 ++-- NAM/convnet.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/NAM/convnet.cpp b/NAM/convnet.cpp index 7623dc4..831d922 100644 --- a/NAM/convnet.cpp +++ b/NAM/convnet.cpp @@ -128,10 +128,10 @@ void nam::convnet::ConvNet::Process(float* input, float* output, const int numFr for (size_t i = 0; i < this->_blocks.size(); i++) this->_blocks[i].Process(this->_block_vals[i], this->_block_vals[i + 1], i_start, i_end); // TODO clean up this allocation - this->mHead.Process(this->_block_vals[this->_blocks.size()], this->_head_output, i_start, i_end); + this->mHead.Process(this->_block_vals[this->_blocks.size()], this->mHeadOutput, i_start, i_end); // Copy to required output array (TODO tighten this up) for (int s = 0; s < numFrames; s++) - output[s] = this->_head_output(s); + output[s] = this->mHeadOutput(s); } void nam::convnet::ConvNet::VerifyWeights(const int channels, const std::vector& dilations, const bool batchnorm, diff --git a/NAM/convnet.h b/NAM/convnet.h index d9e0ce1..793acec 100644 --- a/NAM/convnet.h +++ b/NAM/convnet.h @@ -74,7 +74,7 @@ class ConvNet : public Buffer protected: std::vector _blocks; std::vector _block_vals; - Eigen::VectorXf _head_output; + Eigen::VectorXf mHeadOutput; _Head mHead; void VerifyWeights(const int channels, const std::vector& dilations, const bool batchnorm, const size_t actual_weights); From e029787cc37eebc5d644cf0110aa296f435874f7 Mon Sep 17 00:00:00 2001 From: Oli Larkin Date: Sat, 20 Jan 2024 00:19:27 +0100 Subject: [PATCH 055/133] mBlockVals --- NAM/convnet.cpp | 32 ++++++++++++++++---------------- NAM/convnet.h | 2 +- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/NAM/convnet.cpp b/NAM/convnet.cpp index 831d922..dd0af98 100644 --- a/NAM/convnet.cpp +++ b/NAM/convnet.cpp @@ -101,8 +101,8 @@ nam::convnet::ConvNet::ConvNet(const int channels, const std::vector& dilat weights_it it = weights.begin(); for (size_t i = 0; i < dilations.size(); i++) this->_blocks[i].SetWeights(i == 0 ? 1 : channels, channels, dilations[i], batchnorm, activation, it); - this->_block_vals.resize(this->_blocks.size() + 1); - for (auto& matrix : this->_block_vals) + this->mBlockVals.resize(this->_blocks.size() + 1); + for (auto& matrix : this->mBlockVals) matrix.setZero(); std::fill(this->mInputBuffer.begin(), this->mInputBuffer.end(), 0.0f); this->mHead = _Head(channels, it); @@ -124,11 +124,11 @@ void nam::convnet::ConvNet::Process(float* input, float* output, const int numFr const long i_end = i_start + numFrames; // TODO one unnecessary copy :/ #speed for (auto i = i_start; i < i_end; i++) - this->_block_vals[0](0, i) = this->mInputBuffer[i]; + this->mBlockVals[0](0, i) = this->mInputBuffer[i]; for (size_t i = 0; i < this->_blocks.size(); i++) - this->_blocks[i].Process(this->_block_vals[i], this->_block_vals[i + 1], i_start, i_end); + this->_blocks[i].Process(this->mBlockVals[i], this->mBlockVals[i + 1], i_start, i_end); // TODO clean up this allocation - this->mHead.Process(this->_block_vals[this->_blocks.size()], this->mHeadOutput, i_start, i_end); + this->mHead.Process(this->mBlockVals[this->_blocks.size()], this->mHeadOutput, i_start, i_end); // Copy to required output array (TODO tighten this up) for (int s = 0; s < numFrames; s++) output[s] = this->mHeadOutput(s); @@ -146,19 +146,19 @@ void nam::convnet::ConvNet::UpdateBuffers(float* input, const int numFrames) const size_t buffer_size = this->mInputBuffer.size(); - if (this->_block_vals[0].rows() != Eigen::Index(1) || this->_block_vals[0].cols() != Eigen::Index(buffer_size)) + if (this->mBlockVals[0].rows() != Eigen::Index(1) || this->mBlockVals[0].cols() != Eigen::Index(buffer_size)) { - this->_block_vals[0].resize(1, buffer_size); - this->_block_vals[0].setZero(); + this->mBlockVals[0].resize(1, buffer_size); + this->mBlockVals[0].setZero(); } - for (size_t i = 1; i < this->_block_vals.size(); i++) + for (size_t i = 1; i < this->mBlockVals.size(); i++) { - if (this->_block_vals[i].rows() == this->_blocks[i - 1].GetOutChannels() - && this->_block_vals[i].cols() == Eigen::Index(buffer_size)) + if (this->mBlockVals[i].rows() == this->_blocks[i - 1].GetOutChannels() + && this->mBlockVals[i].cols() == Eigen::Index(buffer_size)) continue; // Already has correct size - this->_block_vals[i].resize(this->_blocks[i - 1].GetOutChannels(), buffer_size); - this->_block_vals[i].setZero(); + this->mBlockVals[i].resize(this->_blocks[i - 1].GetOutChannels(), buffer_size); + this->mBlockVals[i].setZero(); } } @@ -168,15 +168,15 @@ void nam::convnet::ConvNet::RewindBuffers() // resets the offset index // The last _block_vals is the output of the last block and doesn't need to be // rewound. - for (size_t k = 0; k < this->_block_vals.size() - 1; k++) + for (size_t k = 0; k < this->mBlockVals.size() - 1; k++) { // We actually don't need to pull back a lot...just as far as the first // input sample would grab from dilation const long dilation = this->_blocks[k].conv.GetDilation(); for (long i = this->mReceptiveField - dilation, j = this->mInputBufferOffset - dilation; j < this->mInputBufferOffset; i++, j++) - for (long r = 0; r < this->_block_vals[k].rows(); r++) - this->_block_vals[k](r, i) = this->_block_vals[k](r, j); + for (long r = 0; r < this->mBlockVals[k].rows(); r++) + this->mBlockVals[k](r, i) = this->mBlockVals[k](r, j); } // Now we can do the rest of the rewind this->Buffer::RewindBuffers(); diff --git a/NAM/convnet.h b/NAM/convnet.h index 793acec..97f0ae2 100644 --- a/NAM/convnet.h +++ b/NAM/convnet.h @@ -73,7 +73,7 @@ class ConvNet : public Buffer protected: std::vector _blocks; - std::vector _block_vals; + std::vector mBlockVals; Eigen::VectorXf mHeadOutput; _Head mHead; void VerifyWeights(const int channels, const std::vector& dilations, const bool batchnorm, From ae667b939b134d288bec7fc202665c3f0db15d24 Mon Sep 17 00:00:00 2001 From: Oli Larkin Date: Sat, 20 Jan 2024 00:19:48 +0100 Subject: [PATCH 056/133] mBlocks --- NAM/convnet.cpp | 18 +++++++++--------- NAM/convnet.h | 2 +- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/NAM/convnet.cpp b/NAM/convnet.cpp index dd0af98..dccdcc0 100644 --- a/NAM/convnet.cpp +++ b/NAM/convnet.cpp @@ -97,11 +97,11 @@ nam::convnet::ConvNet::ConvNet(const int channels, const std::vector& dilat : Buffer(*std::max_element(dilations.begin(), dilations.end()), expectedSampleRate) { this->VerifyWeights(channels, dilations, batchnorm, weights.size()); - this->_blocks.resize(dilations.size()); + this->mBlocks.resize(dilations.size()); weights_it it = weights.begin(); for (size_t i = 0; i < dilations.size(); i++) - this->_blocks[i].SetWeights(i == 0 ? 1 : channels, channels, dilations[i], batchnorm, activation, it); - this->mBlockVals.resize(this->_blocks.size() + 1); + this->mBlocks[i].SetWeights(i == 0 ? 1 : channels, channels, dilations[i], batchnorm, activation, it); + this->mBlockVals.resize(this->mBlocks.size() + 1); for (auto& matrix : this->mBlockVals) matrix.setZero(); std::fill(this->mInputBuffer.begin(), this->mInputBuffer.end(), 0.0f); @@ -125,10 +125,10 @@ void nam::convnet::ConvNet::Process(float* input, float* output, const int numFr // TODO one unnecessary copy :/ #speed for (auto i = i_start; i < i_end; i++) this->mBlockVals[0](0, i) = this->mInputBuffer[i]; - for (size_t i = 0; i < this->_blocks.size(); i++) - this->_blocks[i].Process(this->mBlockVals[i], this->mBlockVals[i + 1], i_start, i_end); + for (size_t i = 0; i < this->mBlocks.size(); i++) + this->mBlocks[i].Process(this->mBlockVals[i], this->mBlockVals[i + 1], i_start, i_end); // TODO clean up this allocation - this->mHead.Process(this->mBlockVals[this->_blocks.size()], this->mHeadOutput, i_start, i_end); + this->mHead.Process(this->mBlockVals[this->mBlocks.size()], this->mHeadOutput, i_start, i_end); // Copy to required output array (TODO tighten this up) for (int s = 0; s < numFrames; s++) output[s] = this->mHeadOutput(s); @@ -154,10 +154,10 @@ void nam::convnet::ConvNet::UpdateBuffers(float* input, const int numFrames) for (size_t i = 1; i < this->mBlockVals.size(); i++) { - if (this->mBlockVals[i].rows() == this->_blocks[i - 1].GetOutChannels() + if (this->mBlockVals[i].rows() == this->mBlocks[i - 1].GetOutChannels() && this->mBlockVals[i].cols() == Eigen::Index(buffer_size)) continue; // Already has correct size - this->mBlockVals[i].resize(this->_blocks[i - 1].GetOutChannels(), buffer_size); + this->mBlockVals[i].resize(this->mBlocks[i - 1].GetOutChannels(), buffer_size); this->mBlockVals[i].setZero(); } } @@ -172,7 +172,7 @@ void nam::convnet::ConvNet::RewindBuffers() { // We actually don't need to pull back a lot...just as far as the first // input sample would grab from dilation - const long dilation = this->_blocks[k].conv.GetDilation(); + const long dilation = this->mBlocks[k].conv.GetDilation(); for (long i = this->mReceptiveField - dilation, j = this->mInputBufferOffset - dilation; j < this->mInputBufferOffset; i++, j++) for (long r = 0; r < this->mBlockVals[k].rows(); r++) diff --git a/NAM/convnet.h b/NAM/convnet.h index 97f0ae2..b7a8e65 100644 --- a/NAM/convnet.h +++ b/NAM/convnet.h @@ -72,7 +72,7 @@ class ConvNet : public Buffer ~ConvNet() = default; protected: - std::vector _blocks; + std::vector mBlocks; std::vector mBlockVals; Eigen::VectorXf mHeadOutput; _Head mHead; From 42b469af438e7a50e83e229d39c5f5d12f0306d2 Mon Sep 17 00:00:00 2001 From: Oli Larkin Date: Sat, 20 Jan 2024 00:20:28 +0100 Subject: [PATCH 057/133] actual_weights --- NAM/convnet.cpp | 2 +- NAM/convnet.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/NAM/convnet.cpp b/NAM/convnet.cpp index dccdcc0..2db8169 100644 --- a/NAM/convnet.cpp +++ b/NAM/convnet.cpp @@ -135,7 +135,7 @@ void nam::convnet::ConvNet::Process(float* input, float* output, const int numFr } void nam::convnet::ConvNet::VerifyWeights(const int channels, const std::vector& dilations, const bool batchnorm, - const size_t actual_weights) + const size_t actualWeights) { // TODO } diff --git a/NAM/convnet.h b/NAM/convnet.h index b7a8e65..7045cad 100644 --- a/NAM/convnet.h +++ b/NAM/convnet.h @@ -77,7 +77,7 @@ class ConvNet : public Buffer Eigen::VectorXf mHeadOutput; _Head mHead; void VerifyWeights(const int channels, const std::vector& dilations, const bool batchnorm, - const size_t actual_weights); + const size_t actualWeights); void UpdateBuffers(float* input, const int numFrames) override; void RewindBuffers() override; From d859806ade3665136f87bbc9b4a3140a34eedf67 Mon Sep 17 00:00:00 2001 From: Oli Larkin Date: Sat, 20 Jan 2024 00:21:08 +0100 Subject: [PATCH 058/133] _Head --- NAM/convnet.cpp | 6 +++--- NAM/convnet.h | 8 ++++---- NAM/wavenet.cpp | 10 +++++----- NAM/wavenet.h | 4 ++-- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/NAM/convnet.cpp b/NAM/convnet.cpp index 2db8169..b6b640e 100644 --- a/NAM/convnet.cpp +++ b/NAM/convnet.cpp @@ -74,7 +74,7 @@ long nam::convnet::ConvNetBlock::GetOutChannels() const return this->conv.GetOutChannels(); } -nam::convnet::_Head::_Head(const int channels, weights_it& weights) +nam::convnet::Head::Head(const int channels, weights_it& weights) { this->mWeight.resize(channels); for (int i = 0; i < channels; i++) @@ -82,7 +82,7 @@ nam::convnet::_Head::_Head(const int channels, weights_it& weights) this->mBias = *(weights++); } -void nam::convnet::_Head::Process(const Eigen::Ref input, Eigen::VectorXf& output, const long i_start, +void nam::convnet::Head::Process(const Eigen::Ref input, Eigen::VectorXf& output, const long i_start, const long i_end) const { const long length = i_end - i_start; @@ -105,7 +105,7 @@ nam::convnet::ConvNet::ConvNet(const int channels, const std::vector& dilat for (auto& matrix : this->mBlockVals) matrix.setZero(); std::fill(this->mInputBuffer.begin(), this->mInputBuffer.end(), 0.0f); - this->mHead = _Head(channels, it); + this->mHead = Head(channels, it); if (it != weights.end()) throw std::runtime_error("Didn't touch all the weights when initializing ConvNet"); diff --git a/NAM/convnet.h b/NAM/convnet.h index 7045cad..6ac9594 100644 --- a/NAM/convnet.h +++ b/NAM/convnet.h @@ -52,11 +52,11 @@ class ConvNetBlock activations::Activation* activation = nullptr; }; -class _Head +class Head { public: - _Head(){}; - _Head(const int channels, weights_it& weights); + Head(){}; + Head(const int channels, weights_it& weights); void Process(const Eigen::Ref input, Eigen::VectorXf& output, const long i_start, const long i_end) const; private: @@ -75,7 +75,7 @@ class ConvNet : public Buffer std::vector mBlocks; std::vector mBlockVals; Eigen::VectorXf mHeadOutput; - _Head mHead; + Head mHead; void VerifyWeights(const int channels, const std::vector& dilations, const bool batchnorm, const size_t actualWeights); void UpdateBuffers(float* input, const int numFrames) override; diff --git a/NAM/wavenet.cpp b/NAM/wavenet.cpp index cb1caf0..98ad6ae 100644 --- a/NAM/wavenet.cpp +++ b/NAM/wavenet.cpp @@ -180,7 +180,7 @@ void nam::wavenet::_LayerArray::RewindBuffers() // Head ======================================================================= -nam::wavenet::_Head::_Head(const int input_size, const int num_layers, const int channels, const std::string activation) +nam::wavenet::Head::Head(const int input_size, const int num_layers, const int channels, const std::string activation) : _channels(channels) , _head(num_layers > 0 ? channels : input_size, 1, true) , _activation(activations::Activation::GetActivation(activation)) @@ -196,13 +196,13 @@ nam::wavenet::_Head::_Head(const int input_size, const int num_layers, const int } } -void nam::wavenet::_Head::SetWeights(weights_it& weights) +void nam::wavenet::Head::SetWeights(weights_it& weights) { for (size_t i = 0; i < this->_layers.size(); i++) this->_layers[i].SetWeights(weights); } -void nam::wavenet::_Head::Process(Eigen::Ref inputs, Eigen::Ref outputs) +void nam::wavenet::Head::Process(Eigen::Ref inputs, Eigen::Ref outputs) { const size_t num_layers = this->_layers.size(); this->_apply_activation_(inputs); @@ -222,7 +222,7 @@ void nam::wavenet::_Head::Process(Eigen::Ref inputs, Eigen::Ref } } -void nam::wavenet::_Head::set_num_frames_(const long numFrames) +void nam::wavenet::Head::set_num_frames_(const long numFrames) { for (size_t i = 0; i < this->_buffers.size(); i++) { @@ -233,7 +233,7 @@ void nam::wavenet::_Head::set_num_frames_(const long numFrames) } } -void nam::wavenet::_Head::_apply_activation_(Eigen::Ref x) +void nam::wavenet::Head::_apply_activation_(Eigen::Ref x) { this->_activation->Apply(x); } diff --git a/NAM/wavenet.h b/NAM/wavenet.h index e7f40d0..c0e62e6 100644 --- a/NAM/wavenet.h +++ b/NAM/wavenet.h @@ -140,10 +140,10 @@ class _LayerArray // The head module // [Act->Conv] x L -class _Head +class Head { public: - _Head(const int input_size, const int num_layers, const int channels, const std::string activation); + Head(const int input_size, const int num_layers, const int channels, const std::string activation); void SetWeights(weights_it& weights); // NOTE: the head transforms the provided input by applying a nonlinearity // to it in-place! From 57a313296b51abab4832c2d9d7ace636cb1be2ee Mon Sep 17 00:00:00 2001 From: Oli Larkin Date: Sat, 20 Jan 2024 00:26:01 +0100 Subject: [PATCH 059/133] mBatchnorm --- NAM/convnet.cpp | 14 +++++++------- NAM/convnet.h | 4 ++-- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/NAM/convnet.cpp b/NAM/convnet.cpp index b6b640e..ab7e00e 100644 --- a/NAM/convnet.cpp +++ b/NAM/convnet.cpp @@ -47,14 +47,14 @@ void nam::convnet::BatchNorm::Process(Eigen::Ref x, const long } void nam::convnet::ConvNetBlock::SetWeights(const int inChannels, const int outChannels, const int dilation, - const bool batchnorm, const std::string activation, + const bool doBatchNorm, const std::string activation, weights_it& weights) { - this->_batchnorm = batchnorm; + this->mDoBatchNorm = doBatchNorm; // HACK 2 kernel - this->conv.SetSizeAndWeights(inChannels, outChannels, 2, dilation, !batchnorm, weights); - if (this->_batchnorm) - this->batchnorm = BatchNorm(outChannels, weights); + this->conv.SetSizeAndWeights(inChannels, outChannels, 2, dilation, !doBatchNorm, weights); + if (this->mDoBatchNorm) + this->mBatchnorm = BatchNorm(outChannels, weights); this->activation = activations::Activation::GetActivation(activation); } @@ -63,8 +63,8 @@ void nam::convnet::ConvNetBlock::Process(const Eigen::Ref { const long ncols = i_end - i_start; this->conv.Process(input, output, i_start, ncols, i_start); - if (this->_batchnorm) - this->batchnorm.Process(output, i_start, i_end); + if (this->mDoBatchNorm) + this->mBatchnorm.Process(output, i_start, i_end); this->activation->Apply(output.middleCols(i_start, ncols)); } diff --git a/NAM/convnet.h b/NAM/convnet.h index 6ac9594..85b8f2d 100644 --- a/NAM/convnet.h +++ b/NAM/convnet.h @@ -47,8 +47,8 @@ class ConvNetBlock Conv1D conv; private: - BatchNorm batchnorm; - bool _batchnorm = false; + BatchNorm mBatchnorm; + bool mDoBatchNorm = false; activations::Activation* activation = nullptr; }; From 3774bb4a8f68f1bf186f3828b406ccb881582a02 Mon Sep 17 00:00:00 2001 From: Oli Larkin Date: Sat, 20 Jan 2024 00:27:23 +0100 Subject: [PATCH 060/133] mScale --- NAM/convnet.cpp | 8 ++++---- NAM/convnet.h | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/NAM/convnet.cpp b/NAM/convnet.cpp index ab7e00e..5a2928b 100644 --- a/NAM/convnet.cpp +++ b/NAM/convnet.cpp @@ -28,11 +28,11 @@ nam::convnet::BatchNorm::BatchNorm(const int dim, weights_it& weights) float eps = *(weights++); // Convert to scale & loc - this->scale.resize(dim); + this->mScale.resize(dim); this->loc.resize(dim); for (int i = 0; i < dim; i++) - this->scale(i) = weight(i) / sqrt(eps + running_var(i)); - this->loc = bias - this->scale.cwiseProduct(running_mean); + this->mScale(i) = weight(i) / sqrt(eps + running_var(i)); + this->loc = bias - this->mScale.cwiseProduct(running_mean); } void nam::convnet::BatchNorm::Process(Eigen::Ref x, const long i_start, const long i_end) const @@ -41,7 +41,7 @@ void nam::convnet::BatchNorm::Process(Eigen::Ref x, const long // #speed but conv probably dominates for (auto i = i_start; i < i_end; i++) { - x.col(i) = x.col(i).cwiseProduct(this->scale); + x.col(i) = x.col(i).cwiseProduct(this->mScale); x.col(i) += this->loc; } } diff --git a/NAM/convnet.h b/NAM/convnet.h index 85b8f2d..b9d83c3 100644 --- a/NAM/convnet.h +++ b/NAM/convnet.h @@ -32,7 +32,7 @@ class BatchNorm // y = ax+b // a = w / sqrt(v+eps) // b = a * m + bias - Eigen::VectorXf scale; + Eigen::VectorXf mScale; Eigen::VectorXf loc; }; From 61bfe24cd0180280794fe213fb64e47ec5facc4d Mon Sep 17 00:00:00 2001 From: Oli Larkin Date: Sat, 20 Jan 2024 00:27:36 +0100 Subject: [PATCH 061/133] loc --- NAM/convnet.cpp | 6 +++--- NAM/convnet.h | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/NAM/convnet.cpp b/NAM/convnet.cpp index 5a2928b..4b52aee 100644 --- a/NAM/convnet.cpp +++ b/NAM/convnet.cpp @@ -29,10 +29,10 @@ nam::convnet::BatchNorm::BatchNorm(const int dim, weights_it& weights) // Convert to scale & loc this->mScale.resize(dim); - this->loc.resize(dim); + this->mLoc.resize(dim); for (int i = 0; i < dim; i++) this->mScale(i) = weight(i) / sqrt(eps + running_var(i)); - this->loc = bias - this->mScale.cwiseProduct(running_mean); + this->mLoc = bias - this->mScale.cwiseProduct(running_mean); } void nam::convnet::BatchNorm::Process(Eigen::Ref x, const long i_start, const long i_end) const @@ -42,7 +42,7 @@ void nam::convnet::BatchNorm::Process(Eigen::Ref x, const long for (auto i = i_start; i < i_end; i++) { x.col(i) = x.col(i).cwiseProduct(this->mScale); - x.col(i) += this->loc; + x.col(i) += this->mLoc; } } diff --git a/NAM/convnet.h b/NAM/convnet.h index b9d83c3..175e2cc 100644 --- a/NAM/convnet.h +++ b/NAM/convnet.h @@ -33,7 +33,7 @@ class BatchNorm // a = w / sqrt(v+eps) // b = a * m + bias Eigen::VectorXf mScale; - Eigen::VectorXf loc; + Eigen::VectorXf mLoc; }; class ConvNetBlock From c39606cca2e3b527fb0301945f54ed6ae8087bb8 Mon Sep 17 00:00:00 2001 From: Oli Larkin Date: Sat, 20 Jan 2024 00:28:30 +0100 Subject: [PATCH 062/133] mHeadBias --- NAM/lstm.cpp | 4 ++-- NAM/lstm.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/NAM/lstm.cpp b/NAM/lstm.cpp index acaea47..2ea3db4 100644 --- a/NAM/lstm.cpp +++ b/NAM/lstm.cpp @@ -75,7 +75,7 @@ nam::lstm::LSTM::LSTM(const int num_layers, const int input_size, const int hidd this->_head_weight.resize(hidden_size); for (int i = 0; i < hidden_size; i++) this->_head_weight[i] = *(it++); - this->_head_bias = *(it++); + this->mHeadBias = *(it++); assert(it == weights.end()); } @@ -93,5 +93,5 @@ float nam::lstm::LSTM::_process_sample(const float x) this->_layers[0].Process(this->_input); for (size_t i = 1; i < this->_layers.size(); i++) this->_layers[i].Process(this->_layers[i - 1].get_hidden_state()); - return this->_head_weight.dot(this->_layers[this->_layers.size() - 1].get_hidden_state()) + this->_head_bias; + return this->_head_weight.dot(this->_layers[this->_layers.size() - 1].get_hidden_state()) + this->mHeadBias; } diff --git a/NAM/lstm.h b/NAM/lstm.h index 31e1ac5..8517449 100644 --- a/NAM/lstm.h +++ b/NAM/lstm.h @@ -56,7 +56,7 @@ class LSTM : public DSP protected: Eigen::VectorXf _head_weight; - float _head_bias; + float mHeadBias; void Process(float* input, float* output, const int numFrames) override; std::vector _layers; From aadaa0678694356c0c09cb46e7282200da0e6d90 Mon Sep 17 00:00:00 2001 From: Oli Larkin Date: Sat, 20 Jan 2024 00:28:49 +0100 Subject: [PATCH 063/133] mHeadWeight --- NAM/lstm.cpp | 6 +++--- NAM/lstm.h | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/NAM/lstm.cpp b/NAM/lstm.cpp index 2ea3db4..07a636c 100644 --- a/NAM/lstm.cpp +++ b/NAM/lstm.cpp @@ -72,9 +72,9 @@ nam::lstm::LSTM::LSTM(const int num_layers, const int input_size, const int hidd auto it = weights.begin(); for (int i = 0; i < num_layers; i++) this->_layers.push_back(LSTMCell(i == 0 ? input_size : hidden_size, hidden_size, it)); - this->_head_weight.resize(hidden_size); + this->mHeadWeight.resize(hidden_size); for (int i = 0; i < hidden_size; i++) - this->_head_weight[i] = *(it++); + this->mHeadWeight[i] = *(it++); this->mHeadBias = *(it++); assert(it == weights.end()); } @@ -93,5 +93,5 @@ float nam::lstm::LSTM::_process_sample(const float x) this->_layers[0].Process(this->_input); for (size_t i = 1; i < this->_layers.size(); i++) this->_layers[i].Process(this->_layers[i - 1].get_hidden_state()); - return this->_head_weight.dot(this->_layers[this->_layers.size() - 1].get_hidden_state()) + this->mHeadBias; + return this->mHeadWeight.dot(this->_layers[this->_layers.size() - 1].get_hidden_state()) + this->mHeadBias; } diff --git a/NAM/lstm.h b/NAM/lstm.h index 8517449..487f8b1 100644 --- a/NAM/lstm.h +++ b/NAM/lstm.h @@ -55,7 +55,7 @@ class LSTM : public DSP ~LSTM() = default; protected: - Eigen::VectorXf _head_weight; + Eigen::VectorXf mHeadWeight; float mHeadBias; void Process(float* input, float* output, const int numFrames) override; std::vector _layers; From f3c400f1953fa1d93285c98e8fcb7edb76f98248 Mon Sep 17 00:00:00 2001 From: Oli Larkin Date: Sat, 20 Jan 2024 00:29:03 +0100 Subject: [PATCH 064/133] _layers --- NAM/lstm.cpp | 12 ++++++------ NAM/lstm.h | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/NAM/lstm.cpp b/NAM/lstm.cpp index 07a636c..8e9b6a2 100644 --- a/NAM/lstm.cpp +++ b/NAM/lstm.cpp @@ -71,7 +71,7 @@ nam::lstm::LSTM::LSTM(const int num_layers, const int input_size, const int hidd this->_input.resize(1); auto it = weights.begin(); for (int i = 0; i < num_layers; i++) - this->_layers.push_back(LSTMCell(i == 0 ? input_size : hidden_size, hidden_size, it)); + this->mLayers.push_back(LSTMCell(i == 0 ? input_size : hidden_size, hidden_size, it)); this->mHeadWeight.resize(hidden_size); for (int i = 0; i < hidden_size; i++) this->mHeadWeight[i] = *(it++); @@ -87,11 +87,11 @@ void nam::lstm::LSTM::Process(float* input, float* output, const int numFrames) float nam::lstm::LSTM::_process_sample(const float x) { - if (this->_layers.size() == 0) + if (this->mLayers.size() == 0) return x; this->_input(0) = x; - this->_layers[0].Process(this->_input); - for (size_t i = 1; i < this->_layers.size(); i++) - this->_layers[i].Process(this->_layers[i - 1].get_hidden_state()); - return this->mHeadWeight.dot(this->_layers[this->_layers.size() - 1].get_hidden_state()) + this->mHeadBias; + this->mLayers[0].Process(this->_input); + for (size_t i = 1; i < this->mLayers.size(); i++) + this->mLayers[i].Process(this->mLayers[i - 1].get_hidden_state()); + return this->mHeadWeight.dot(this->mLayers[this->mLayers.size() - 1].get_hidden_state()) + this->mHeadBias; } diff --git a/NAM/lstm.h b/NAM/lstm.h index 487f8b1..8f2c2ce 100644 --- a/NAM/lstm.h +++ b/NAM/lstm.h @@ -58,7 +58,7 @@ class LSTM : public DSP Eigen::VectorXf mHeadWeight; float mHeadBias; void Process(float* input, float* output, const int numFrames) override; - std::vector _layers; + std::vector mLayers; float _process_sample(const float x); From d491f556eed7fe23aca53c9369b8ae048c9d54ef Mon Sep 17 00:00:00 2001 From: Oli Larkin Date: Sat, 20 Jan 2024 00:29:24 +0100 Subject: [PATCH 065/133] _process_sample --- NAM/lstm.cpp | 4 ++-- NAM/lstm.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/NAM/lstm.cpp b/NAM/lstm.cpp index 8e9b6a2..2abbf73 100644 --- a/NAM/lstm.cpp +++ b/NAM/lstm.cpp @@ -82,10 +82,10 @@ nam::lstm::LSTM::LSTM(const int num_layers, const int input_size, const int hidd void nam::lstm::LSTM::Process(float* input, float* output, const int numFrames) { for (auto i = 0; i < numFrames; i++) - output[i] = this->_process_sample(input[i]); + output[i] = this->ProcessSample(input[i]); } -float nam::lstm::LSTM::_process_sample(const float x) +float nam::lstm::LSTM::ProcessSample(const float x) { if (this->mLayers.size() == 0) return x; diff --git a/NAM/lstm.h b/NAM/lstm.h index 8f2c2ce..fdbba72 100644 --- a/NAM/lstm.h +++ b/NAM/lstm.h @@ -60,7 +60,7 @@ class LSTM : public DSP void Process(float* input, float* output, const int numFrames) override; std::vector mLayers; - float _process_sample(const float x); + float ProcessSample(const float x); // Input to the LSTM. // Since this is assumed to not be a parametric model, its shape should be (1,) From 33ae6a2fc0f41cb8557ce657b925b21b000784b1 Mon Sep 17 00:00:00 2001 From: Oli Larkin Date: Sat, 20 Jan 2024 00:29:43 +0100 Subject: [PATCH 066/133] input --- NAM/lstm.cpp | 6 +++--- NAM/lstm.h | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/NAM/lstm.cpp b/NAM/lstm.cpp index 2abbf73..545becc 100644 --- a/NAM/lstm.cpp +++ b/NAM/lstm.cpp @@ -68,7 +68,7 @@ nam::lstm::LSTM::LSTM(const int num_layers, const int input_size, const int hidd const double expectedSampleRate) : DSP(expectedSampleRate) { - this->_input.resize(1); + this->mInput.resize(1); auto it = weights.begin(); for (int i = 0; i < num_layers; i++) this->mLayers.push_back(LSTMCell(i == 0 ? input_size : hidden_size, hidden_size, it)); @@ -89,8 +89,8 @@ float nam::lstm::LSTM::ProcessSample(const float x) { if (this->mLayers.size() == 0) return x; - this->_input(0) = x; - this->mLayers[0].Process(this->_input); + this->mInput(0) = x; + this->mLayers[0].Process(this->mInput); for (size_t i = 1; i < this->mLayers.size(); i++) this->mLayers[i].Process(this->mLayers[i - 1].get_hidden_state()); return this->mHeadWeight.dot(this->mLayers[this->mLayers.size() - 1].get_hidden_state()) + this->mHeadBias; diff --git a/NAM/lstm.h b/NAM/lstm.h index fdbba72..4874ab0 100644 --- a/NAM/lstm.h +++ b/NAM/lstm.h @@ -64,7 +64,7 @@ class LSTM : public DSP // Input to the LSTM. // Since this is assumed to not be a parametric model, its shape should be (1,) - Eigen::VectorXf _input; + Eigen::VectorXf mInput; }; }; // namespace lstm }; // namespace nam From 23171a1e7b93f0f7710f5ba974a4ca56e26ab5b1 Mon Sep 17 00:00:00 2001 From: Oli Larkin Date: Sat, 20 Jan 2024 00:31:33 +0100 Subject: [PATCH 067/133] num_layers --- NAM/get_dsp.cpp | 4 ++-- NAM/lstm.cpp | 4 ++-- NAM/lstm.h | 2 +- NAM/wavenet.cpp | 20 ++++++++++---------- NAM/wavenet.h | 2 +- 5 files changed, 16 insertions(+), 16 deletions(-) diff --git a/NAM/get_dsp.cpp b/NAM/get_dsp.cpp index 31be09e..06bb582 100644 --- a/NAM/get_dsp.cpp +++ b/NAM/get_dsp.cpp @@ -161,10 +161,10 @@ std::unique_ptr GetDSP(dspData& conf) } else if (architecture == "LSTM") { - const int num_layers = config["num_layers"]; + const int numLayers = config["num_layers"]; const int input_size = config["input_size"]; const int hidden_size = config["hidden_size"]; - out = std::make_unique(num_layers, input_size, hidden_size, weights, expectedSampleRate); + out = std::make_unique(numLayers, input_size, hidden_size, weights, expectedSampleRate); } else if (architecture == "WaveNet") { diff --git a/NAM/lstm.cpp b/NAM/lstm.cpp index 545becc..0e2e32d 100644 --- a/NAM/lstm.cpp +++ b/NAM/lstm.cpp @@ -64,13 +64,13 @@ void nam::lstm::LSTMCell::Process(const Eigen::VectorXf& x) } } -nam::lstm::LSTM::LSTM(const int num_layers, const int input_size, const int hidden_size, const std::vector& weights, +nam::lstm::LSTM::LSTM(const int numLayers, const int input_size, const int hidden_size, const std::vector& weights, const double expectedSampleRate) : DSP(expectedSampleRate) { this->mInput.resize(1); auto it = weights.begin(); - for (int i = 0; i < num_layers; i++) + for (int i = 0; i < numLayers; i++) this->mLayers.push_back(LSTMCell(i == 0 ? input_size : hidden_size, hidden_size, it)); this->mHeadWeight.resize(hidden_size); for (int i = 0; i < hidden_size; i++) diff --git a/NAM/lstm.h b/NAM/lstm.h index 4874ab0..df0bb0a 100644 --- a/NAM/lstm.h +++ b/NAM/lstm.h @@ -50,7 +50,7 @@ class LSTMCell class LSTM : public DSP { public: - LSTM(const int num_layers, const int input_size, const int hidden_size, const std::vector& weights, + LSTM(const int numLayers, const int input_size, const int hidden_size, const std::vector& weights, const double expectedSampleRate = -1.0); ~LSTM() = default; diff --git a/NAM/wavenet.cpp b/NAM/wavenet.cpp index 98ad6ae..64ba888 100644 --- a/NAM/wavenet.cpp +++ b/NAM/wavenet.cpp @@ -180,18 +180,18 @@ void nam::wavenet::_LayerArray::RewindBuffers() // Head ======================================================================= -nam::wavenet::Head::Head(const int input_size, const int num_layers, const int channels, const std::string activation) +nam::wavenet::Head::Head(const int input_size, const int numLayers, const int channels, const std::string activation) : _channels(channels) -, _head(num_layers > 0 ? channels : input_size, 1, true) +, _head(numLayers > 0 ? channels : input_size, 1, true) , _activation(activations::Activation::GetActivation(activation)) { - assert(num_layers > 0); + assert(numLayers > 0); int dx = input_size; - for (int i = 0; i < num_layers; i++) + for (int i = 0; i < numLayers; i++) { - this->_layers.push_back(Conv1x1(dx, i == num_layers - 1 ? 1 : channels, true)); + this->_layers.push_back(Conv1x1(dx, i == numLayers - 1 ? 1 : channels, true)); dx = channels; - if (i < num_layers - 1) + if (i < numLayers - 1) this->_buffers.push_back(Eigen::MatrixXf()); } } @@ -204,17 +204,17 @@ void nam::wavenet::Head::SetWeights(weights_it& weights) void nam::wavenet::Head::Process(Eigen::Ref inputs, Eigen::Ref outputs) { - const size_t num_layers = this->_layers.size(); + const size_t numLayers = this->_layers.size(); this->_apply_activation_(inputs); - if (num_layers == 1) + if (numLayers == 1) outputs = this->_layers[0].Process(inputs); else { this->_buffers[0] = this->_layers[0].Process(inputs); - for (size_t i = 1; i < num_layers; i++) + for (size_t i = 1; i < numLayers; i++) { // Asserted > 0 layers this->_apply_activation_(this->_buffers[i - 1]); - if (i < num_layers - 1) + if (i < numLayers - 1) this->_buffers[i] = this->_layers[i].Process(this->_buffers[i - 1]); else outputs = this->_layers[i].Process(this->_buffers[i - 1]); diff --git a/NAM/wavenet.h b/NAM/wavenet.h index c0e62e6..326c7ed 100644 --- a/NAM/wavenet.h +++ b/NAM/wavenet.h @@ -143,7 +143,7 @@ class _LayerArray class Head { public: - Head(const int input_size, const int num_layers, const int channels, const std::string activation); + Head(const int input_size, const int numLayers, const int channels, const std::string activation); void SetWeights(weights_it& weights); // NOTE: the head transforms the provided input by applying a nonlinearity // to it in-place! From a4659f833ef9ee2a5a490bb4c281dc370326d6b5 Mon Sep 17 00:00:00 2001 From: Oli Larkin Date: Sat, 20 Jan 2024 00:32:12 +0100 Subject: [PATCH 068/133] input_size --- NAM/get_dsp.cpp | 6 +++--- NAM/lstm.cpp | 18 +++++++++--------- NAM/lstm.h | 4 ++-- NAM/wavenet.cpp | 12 ++++++------ NAM/wavenet.h | 8 ++++---- 5 files changed, 24 insertions(+), 24 deletions(-) diff --git a/NAM/get_dsp.cpp b/NAM/get_dsp.cpp index 06bb582..7fc9693 100644 --- a/NAM/get_dsp.cpp +++ b/NAM/get_dsp.cpp @@ -162,9 +162,9 @@ std::unique_ptr GetDSP(dspData& conf) else if (architecture == "LSTM") { const int numLayers = config["num_layers"]; - const int input_size = config["input_size"]; - const int hidden_size = config["hidden_size"]; - out = std::make_unique(numLayers, input_size, hidden_size, weights, expectedSampleRate); + const int inputSize = config["input_size"]; + const int hiddenSize = config["hidden_size"]; + out = std::make_unique(numLayers, inputSize, hiddenSize, weights, expectedSampleRate); } else if (architecture == "WaveNet") { diff --git a/NAM/lstm.cpp b/NAM/lstm.cpp index 0e2e32d..124a44a 100644 --- a/NAM/lstm.cpp +++ b/NAM/lstm.cpp @@ -5,12 +5,12 @@ #include "dsp.h" #include "lstm.h" -nam::lstm::LSTMCell::LSTMCell(const int input_size, const int hidden_size, weights_it& weights) +nam::lstm::LSTMCell::LSTMCell(const int inputSize, const int hidden_size, weights_it& weights) { // Resize arrays - this->_w.resize(4 * hidden_size, input_size + hidden_size); + this->_w.resize(4 * hidden_size, inputSize + hidden_size); this->_b.resize(4 * hidden_size); - this->_xh.resize(input_size + hidden_size); + this->_xh.resize(inputSize + hidden_size); this->_ifgo.resize(4 * hidden_size); this->_c.resize(hidden_size); @@ -20,7 +20,7 @@ nam::lstm::LSTMCell::LSTMCell(const int input_size, const int hidden_size, weigh this->_w(i, j) = *(weights++); for (int i = 0; i < this->_b.size(); i++) this->_b[i] = *(weights++); - const int h_offset = input_size; + const int h_offset = inputSize; for (int i = 0; i < hidden_size; i++) this->_xh[i + h_offset] = *(weights++); for (int i = 0; i < hidden_size; i++) @@ -30,9 +30,9 @@ nam::lstm::LSTMCell::LSTMCell(const int input_size, const int hidden_size, weigh void nam::lstm::LSTMCell::Process(const Eigen::VectorXf& x) { const long hidden_size = this->_get_hidden_size(); - const long input_size = this->_get_input_size(); + const long inputSize = this->_get_input_size(); // Assign inputs - this->_xh(Eigen::seq(0, input_size - 1)) = x; + this->_xh(Eigen::seq(0, inputSize - 1)) = x; // The matmul this->_ifgo = this->_w * this->_xh + this->_b; // Elementwise updates (apply nonlinearities here) @@ -40,7 +40,7 @@ void nam::lstm::LSTMCell::Process(const Eigen::VectorXf& x) const long f_offset = hidden_size; const long g_offset = 2 * hidden_size; const long o_offset = 3 * hidden_size; - const long h_offset = input_size; + const long h_offset = inputSize; if (activations::Activation::sUsingFastTanh) { @@ -64,14 +64,14 @@ void nam::lstm::LSTMCell::Process(const Eigen::VectorXf& x) } } -nam::lstm::LSTM::LSTM(const int numLayers, const int input_size, const int hidden_size, const std::vector& weights, +nam::lstm::LSTM::LSTM(const int numLayers, const int inputSize, const int hidden_size, const std::vector& weights, const double expectedSampleRate) : DSP(expectedSampleRate) { this->mInput.resize(1); auto it = weights.begin(); for (int i = 0; i < numLayers; i++) - this->mLayers.push_back(LSTMCell(i == 0 ? input_size : hidden_size, hidden_size, it)); + this->mLayers.push_back(LSTMCell(i == 0 ? inputSize : hidden_size, hidden_size, it)); this->mHeadWeight.resize(hidden_size); for (int i = 0; i < hidden_size; i++) this->mHeadWeight[i] = *(it++); diff --git a/NAM/lstm.h b/NAM/lstm.h index df0bb0a..d200926 100644 --- a/NAM/lstm.h +++ b/NAM/lstm.h @@ -22,7 +22,7 @@ namespace lstm class LSTMCell { public: - LSTMCell(const int input_size, const int hidden_size, weights_it& weights); + LSTMCell(const int inputSize, const int hidden_size, weights_it& weights); Eigen::VectorXf get_hidden_state() const { return this->_xh(Eigen::placeholders::lastN(this->_get_hidden_size())); }; void Process(const Eigen::VectorXf& x); @@ -50,7 +50,7 @@ class LSTMCell class LSTM : public DSP { public: - LSTM(const int numLayers, const int input_size, const int hidden_size, const std::vector& weights, + LSTM(const int numLayers, const int inputSize, const int hidden_size, const std::vector& weights, const double expectedSampleRate = -1.0); ~LSTM() = default; diff --git a/NAM/wavenet.cpp b/NAM/wavenet.cpp index 64ba888..3306d55 100644 --- a/NAM/wavenet.cpp +++ b/NAM/wavenet.cpp @@ -59,10 +59,10 @@ void nam::wavenet::_Layer::set_num_frames_(const long numFrames) #define LAYER_ARRAY_BUFFER_SIZE 65536 -nam::wavenet::_LayerArray::_LayerArray(const int input_size, const int condition_size, const int head_size, +nam::wavenet::_LayerArray::_LayerArray(const int inputSize, const int condition_size, const int head_size, const int channels, const int kernelSize, const std::vector& dilations, const std::string activation, const bool gated, const bool head_bias) -: _rechannel(input_size, channels, false) +: _rechannel(inputSize, channels, false) , _head_rechannel(channels, head_size, head_bias) { for (size_t i = 0; i < dilations.size(); i++) @@ -180,13 +180,13 @@ void nam::wavenet::_LayerArray::RewindBuffers() // Head ======================================================================= -nam::wavenet::Head::Head(const int input_size, const int numLayers, const int channels, const std::string activation) +nam::wavenet::Head::Head(const int inputSize, const int numLayers, const int channels, const std::string activation) : _channels(channels) -, _head(numLayers > 0 ? channels : input_size, 1, true) +, _head(numLayers > 0 ? channels : inputSize, 1, true) , _activation(activations::Activation::GetActivation(activation)) { assert(numLayers > 0); - int dx = input_size; + int dx = inputSize; for (int i = 0; i < numLayers; i++) { this->_layers.push_back(Conv1x1(dx, i == numLayers - 1 ? 1 : channels, true)); @@ -252,7 +252,7 @@ nam::wavenet::WaveNet::WaveNet(const std::vector for (size_t i = 0; i < layer_array_params.size(); i++) { this->_layer_arrays.push_back(nam::wavenet::_LayerArray( - layer_array_params[i].input_size, layer_array_params[i].condition_size, layer_array_params[i].head_size, + layer_array_params[i].inputSize, layer_array_params[i].condition_size, layer_array_params[i].head_size, layer_array_params[i].channels, layer_array_params[i].kernelSize, layer_array_params[i].dilations, layer_array_params[i].activation, layer_array_params[i].gated, layer_array_params[i].head_bias)); this->_layer_array_outputs.push_back(Eigen::MatrixXf(layer_array_params[i].channels, 0)); diff --git a/NAM/wavenet.h b/NAM/wavenet.h index 326c7ed..f6f98cb 100644 --- a/NAM/wavenet.h +++ b/NAM/wavenet.h @@ -60,7 +60,7 @@ class LayerArrayParams LayerArrayParams(const int input_size_, const int condition_size_, const int head_size_, const int channels_, const int kernel_size_, const std::vector& dilations_, const std::string activation_, const bool gated_, const bool head_bias_) - : input_size(input_size_) + : inputSize(input_size_) , condition_size(condition_size_) , head_size(head_size_) , channels(channels_) @@ -73,7 +73,7 @@ class LayerArrayParams this->dilations.push_back(dilations_[i]); }; - const int input_size; + const int inputSize; const int condition_size; const int head_size; const int channels; @@ -88,7 +88,7 @@ class LayerArrayParams class _LayerArray { public: - _LayerArray(const int input_size, const int condition_size, const int head_size, const int channels, + _LayerArray(const int inputSize, const int condition_size, const int head_size, const int channels, const int kernelSize, const std::vector& dilations, const std::string activation, const bool gated, const bool head_bias); @@ -143,7 +143,7 @@ class _LayerArray class Head { public: - Head(const int input_size, const int numLayers, const int channels, const std::string activation); + Head(const int inputSize, const int numLayers, const int channels, const std::string activation); void SetWeights(weights_it& weights); // NOTE: the head transforms the provided input by applying a nonlinearity // to it in-place! From 3673a3d06ccb641cd5b5415b072a16a277b8eefd Mon Sep 17 00:00:00 2001 From: Oli Larkin Date: Sat, 20 Jan 2024 00:33:11 +0100 Subject: [PATCH 069/133] hidden_size --- NAM/lstm.cpp | 40 ++++++++++++++++++++-------------------- NAM/lstm.h | 4 ++-- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/NAM/lstm.cpp b/NAM/lstm.cpp index 124a44a..31fe008 100644 --- a/NAM/lstm.cpp +++ b/NAM/lstm.cpp @@ -5,14 +5,14 @@ #include "dsp.h" #include "lstm.h" -nam::lstm::LSTMCell::LSTMCell(const int inputSize, const int hidden_size, weights_it& weights) +nam::lstm::LSTMCell::LSTMCell(const int inputSize, const int hiddenSize, weights_it& weights) { // Resize arrays - this->_w.resize(4 * hidden_size, inputSize + hidden_size); - this->_b.resize(4 * hidden_size); - this->_xh.resize(inputSize + hidden_size); - this->_ifgo.resize(4 * hidden_size); - this->_c.resize(hidden_size); + this->_w.resize(4 * hiddenSize, inputSize + hiddenSize); + this->_b.resize(4 * hiddenSize); + this->_xh.resize(inputSize + hiddenSize); + this->_ifgo.resize(4 * hiddenSize); + this->_c.resize(hiddenSize); // Assign in row-major because that's how PyTorch goes. for (int i = 0; i < this->_w.rows(); i++) @@ -21,15 +21,15 @@ nam::lstm::LSTMCell::LSTMCell(const int inputSize, const int hidden_size, weight for (int i = 0; i < this->_b.size(); i++) this->_b[i] = *(weights++); const int h_offset = inputSize; - for (int i = 0; i < hidden_size; i++) + for (int i = 0; i < hiddenSize; i++) this->_xh[i + h_offset] = *(weights++); - for (int i = 0; i < hidden_size; i++) + for (int i = 0; i < hiddenSize; i++) this->_c[i] = *(weights++); } void nam::lstm::LSTMCell::Process(const Eigen::VectorXf& x) { - const long hidden_size = this->_get_hidden_size(); + const long hiddenSize = this->_get_hidden_size(); const long inputSize = this->_get_input_size(); // Assign inputs this->_xh(Eigen::seq(0, inputSize - 1)) = x; @@ -37,43 +37,43 @@ void nam::lstm::LSTMCell::Process(const Eigen::VectorXf& x) this->_ifgo = this->_w * this->_xh + this->_b; // Elementwise updates (apply nonlinearities here) const long i_offset = 0; - const long f_offset = hidden_size; - const long g_offset = 2 * hidden_size; - const long o_offset = 3 * hidden_size; + const long f_offset = hiddenSize; + const long g_offset = 2 * hiddenSize; + const long o_offset = 3 * hiddenSize; const long h_offset = inputSize; if (activations::Activation::sUsingFastTanh) { - for (auto i = 0; i < hidden_size; i++) + for (auto i = 0; i < hiddenSize; i++) this->_c[i] = activations::fast_sigmoid(this->_ifgo[i + f_offset]) * this->_c[i] + activations::fast_sigmoid(this->_ifgo[i + i_offset]) * activations::fast_tanh(this->_ifgo[i + g_offset]); - for (int i = 0; i < hidden_size; i++) + for (int i = 0; i < hiddenSize; i++) this->_xh[i + h_offset] = activations::fast_sigmoid(this->_ifgo[i + o_offset]) * activations::fast_tanh(this->_c[i]); } else { - for (auto i = 0; i < hidden_size; i++) + for (auto i = 0; i < hiddenSize; i++) this->_c[i] = activations::sigmoid(this->_ifgo[i + f_offset]) * this->_c[i] + activations::sigmoid(this->_ifgo[i + i_offset]) * tanhf(this->_ifgo[i + g_offset]); - for (int i = 0; i < hidden_size; i++) + for (int i = 0; i < hiddenSize; i++) this->_xh[i + h_offset] = activations::sigmoid(this->_ifgo[i + o_offset]) * tanhf(this->_c[i]); } } -nam::lstm::LSTM::LSTM(const int numLayers, const int inputSize, const int hidden_size, const std::vector& weights, +nam::lstm::LSTM::LSTM(const int numLayers, const int inputSize, const int hiddenSize, const std::vector& weights, const double expectedSampleRate) : DSP(expectedSampleRate) { this->mInput.resize(1); auto it = weights.begin(); for (int i = 0; i < numLayers; i++) - this->mLayers.push_back(LSTMCell(i == 0 ? inputSize : hidden_size, hidden_size, it)); - this->mHeadWeight.resize(hidden_size); - for (int i = 0; i < hidden_size; i++) + this->mLayers.push_back(LSTMCell(i == 0 ? inputSize : hiddenSize, hiddenSize, it)); + this->mHeadWeight.resize(hiddenSize); + for (int i = 0; i < hiddenSize; i++) this->mHeadWeight[i] = *(it++); this->mHeadBias = *(it++); assert(it == weights.end()); diff --git a/NAM/lstm.h b/NAM/lstm.h index d200926..070b18f 100644 --- a/NAM/lstm.h +++ b/NAM/lstm.h @@ -22,7 +22,7 @@ namespace lstm class LSTMCell { public: - LSTMCell(const int inputSize, const int hidden_size, weights_it& weights); + LSTMCell(const int inputSize, const int hiddenSize, weights_it& weights); Eigen::VectorXf get_hidden_state() const { return this->_xh(Eigen::placeholders::lastN(this->_get_hidden_size())); }; void Process(const Eigen::VectorXf& x); @@ -50,7 +50,7 @@ class LSTMCell class LSTM : public DSP { public: - LSTM(const int numLayers, const int inputSize, const int hidden_size, const std::vector& weights, + LSTM(const int numLayers, const int inputSize, const int hiddenSize, const std::vector& weights, const double expectedSampleRate = -1.0); ~LSTM() = default; From 045df5af11b94ee7eebe343b27d2304f83eab808 Mon Sep 17 00:00:00 2001 From: Oli Larkin Date: Sat, 20 Jan 2024 00:35:27 +0100 Subject: [PATCH 070/133] GetHiddenSize --- NAM/lstm.cpp | 2 +- NAM/lstm.h | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/NAM/lstm.cpp b/NAM/lstm.cpp index 31fe008..1cb4cfa 100644 --- a/NAM/lstm.cpp +++ b/NAM/lstm.cpp @@ -29,7 +29,7 @@ nam::lstm::LSTMCell::LSTMCell(const int inputSize, const int hiddenSize, weights void nam::lstm::LSTMCell::Process(const Eigen::VectorXf& x) { - const long hiddenSize = this->_get_hidden_size(); + const long hiddenSize = this->GetHiddenSize(); const long inputSize = this->_get_input_size(); // Assign inputs this->_xh(Eigen::seq(0, inputSize - 1)) = x; diff --git a/NAM/lstm.h b/NAM/lstm.h index 070b18f..d93df3c 100644 --- a/NAM/lstm.h +++ b/NAM/lstm.h @@ -23,7 +23,7 @@ class LSTMCell { public: LSTMCell(const int inputSize, const int hiddenSize, weights_it& weights); - Eigen::VectorXf get_hidden_state() const { return this->_xh(Eigen::placeholders::lastN(this->_get_hidden_size())); }; + Eigen::VectorXf get_hidden_state() const { return this->_xh(Eigen::placeholders::lastN(this->GetHiddenSize())); }; void Process(const Eigen::VectorXf& x); private: @@ -42,8 +42,8 @@ class LSTMCell // Cell state Eigen::VectorXf _c; - long _get_hidden_size() const { return this->_b.size() / 4; }; - long _get_input_size() const { return this->_xh.size() - this->_get_hidden_size(); }; + long GetHiddenSize() const { return this->_b.size() / 4; }; + long _get_input_size() const { return this->_xh.size() - this->GetHiddenSize(); }; }; // The multi-layer LSTM model From afb6ef1114466757854db1f754a4693fb2ef795f Mon Sep 17 00:00:00 2001 From: Oli Larkin Date: Sat, 20 Jan 2024 00:35:43 +0100 Subject: [PATCH 071/133] _get_input_size --- NAM/lstm.cpp | 2 +- NAM/lstm.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/NAM/lstm.cpp b/NAM/lstm.cpp index 1cb4cfa..92538bd 100644 --- a/NAM/lstm.cpp +++ b/NAM/lstm.cpp @@ -30,7 +30,7 @@ nam::lstm::LSTMCell::LSTMCell(const int inputSize, const int hiddenSize, weights void nam::lstm::LSTMCell::Process(const Eigen::VectorXf& x) { const long hiddenSize = this->GetHiddenSize(); - const long inputSize = this->_get_input_size(); + const long inputSize = this->GetInputSize(); // Assign inputs this->_xh(Eigen::seq(0, inputSize - 1)) = x; // The matmul diff --git a/NAM/lstm.h b/NAM/lstm.h index d93df3c..6378878 100644 --- a/NAM/lstm.h +++ b/NAM/lstm.h @@ -43,7 +43,7 @@ class LSTMCell Eigen::VectorXf _c; long GetHiddenSize() const { return this->_b.size() / 4; }; - long _get_input_size() const { return this->_xh.size() - this->GetHiddenSize(); }; + long GetInputSize() const { return this->_xh.size() - this->GetHiddenSize(); }; }; // The multi-layer LSTM model From fc3cfb1ad7a86e24b225cd77615bd71ef8308108 Mon Sep 17 00:00:00 2001 From: Oli Larkin Date: Sat, 20 Jan 2024 00:36:16 +0100 Subject: [PATCH 072/133] get_hidden_state --- NAM/lstm.cpp | 4 ++-- NAM/lstm.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/NAM/lstm.cpp b/NAM/lstm.cpp index 92538bd..ac90c8e 100644 --- a/NAM/lstm.cpp +++ b/NAM/lstm.cpp @@ -92,6 +92,6 @@ float nam::lstm::LSTM::ProcessSample(const float x) this->mInput(0) = x; this->mLayers[0].Process(this->mInput); for (size_t i = 1; i < this->mLayers.size(); i++) - this->mLayers[i].Process(this->mLayers[i - 1].get_hidden_state()); - return this->mHeadWeight.dot(this->mLayers[this->mLayers.size() - 1].get_hidden_state()) + this->mHeadBias; + this->mLayers[i].Process(this->mLayers[i - 1].GetHiddenState()); + return this->mHeadWeight.dot(this->mLayers[this->mLayers.size() - 1].GetHiddenState()) + this->mHeadBias; } diff --git a/NAM/lstm.h b/NAM/lstm.h index 6378878..100894a 100644 --- a/NAM/lstm.h +++ b/NAM/lstm.h @@ -23,7 +23,7 @@ class LSTMCell { public: LSTMCell(const int inputSize, const int hiddenSize, weights_it& weights); - Eigen::VectorXf get_hidden_state() const { return this->_xh(Eigen::placeholders::lastN(this->GetHiddenSize())); }; + Eigen::VectorXf GetHiddenState() const { return this->_xh(Eigen::placeholders::lastN(this->GetHiddenSize())); }; void Process(const Eigen::VectorXf& x); private: From 1cbec54b3af2ac2b38a37435fb1979ddf4719f74 Mon Sep 17 00:00:00 2001 From: Oli Larkin Date: Sat, 20 Jan 2024 00:37:37 +0100 Subject: [PATCH 073/133] _set_num_frames_ --- NAM/wavenet.cpp | 4 ++-- NAM/wavenet.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/NAM/wavenet.cpp b/NAM/wavenet.cpp index 3306d55..b36e6fa 100644 --- a/NAM/wavenet.cpp +++ b/NAM/wavenet.cpp @@ -325,7 +325,7 @@ void nam::wavenet::WaveNet::_set_condition_array(float* input, const int numFram void nam::wavenet::WaveNet::Process(float* input, float* output, const int numFrames) { - this->_set_num_frames_(numFrames); + this->SetNumFrames(numFrames); this->_prepare_for_frames_(numFrames); this->_set_condition_array(input, numFrames); @@ -353,7 +353,7 @@ void nam::wavenet::WaveNet::Process(float* input, float* output, const int numFr } } -void nam::wavenet::WaveNet::_set_num_frames_(const long numFrames) +void nam::wavenet::WaveNet::SetNumFrames(const long numFrames) { if (numFrames == this->_num_frames) return; diff --git a/NAM/wavenet.h b/NAM/wavenet.h index f6f98cb..972a949 100644 --- a/NAM/wavenet.h +++ b/NAM/wavenet.h @@ -197,7 +197,7 @@ class WaveNet : public DSP // Fill in the "condition" array that's fed into the various parts of the net. virtual void _set_condition_array(float* input, const int numFrames); // Ensure that all buffer arrays are the right size for this numFrames - void _set_num_frames_(const long numFrames); + void SetNumFrames(const long numFrames); }; }; // namespace wavenet }; // namespace nam From d5b723d133f8b4666dd66aff51c852582c1031f2 Mon Sep 17 00:00:00 2001 From: Oli Larkin Date: Sat, 20 Jan 2024 00:37:56 +0100 Subject: [PATCH 074/133] _set_condition_array --- NAM/wavenet.cpp | 4 ++-- NAM/wavenet.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/NAM/wavenet.cpp b/NAM/wavenet.cpp index b36e6fa..d024f5f 100644 --- a/NAM/wavenet.cpp +++ b/NAM/wavenet.cpp @@ -315,7 +315,7 @@ void nam::wavenet::WaveNet::_prepare_for_frames_(const long numFrames) this->_layer_arrays[i].prepare_for_frames_(numFrames); } -void nam::wavenet::WaveNet::_set_condition_array(float* input, const int numFrames) +void nam::wavenet::WaveNet::SetConditionArray(float* input, const int numFrames) { for (int j = 0; j < numFrames; j++) { @@ -327,7 +327,7 @@ void nam::wavenet::WaveNet::Process(float* input, float* output, const int numFr { this->SetNumFrames(numFrames); this->_prepare_for_frames_(numFrames); - this->_set_condition_array(input, numFrames); + this->SetConditionArray(input, numFrames); // Main layer arrays: // Layer-to-layer diff --git a/NAM/wavenet.h b/NAM/wavenet.h index 972a949..5dc66df 100644 --- a/NAM/wavenet.h +++ b/NAM/wavenet.h @@ -195,7 +195,7 @@ class WaveNet : public DSP virtual int _get_condition_dim() const { return 1; }; // Fill in the "condition" array that's fed into the various parts of the net. - virtual void _set_condition_array(float* input, const int numFrames); + virtual void SetConditionArray(float* input, const int numFrames); // Ensure that all buffer arrays are the right size for this numFrames void SetNumFrames(const long numFrames); }; From 44139123a13fc1b376eb8fe45bdf22d4bf3148f5 Mon Sep 17 00:00:00 2001 From: Oli Larkin Date: Sat, 20 Jan 2024 00:38:19 +0100 Subject: [PATCH 075/133] _get_condition_dim --- NAM/wavenet.cpp | 2 +- NAM/wavenet.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/NAM/wavenet.cpp b/NAM/wavenet.cpp index d024f5f..05f4242 100644 --- a/NAM/wavenet.cpp +++ b/NAM/wavenet.cpp @@ -358,7 +358,7 @@ void nam::wavenet::WaveNet::SetNumFrames(const long numFrames) if (numFrames == this->_num_frames) return; - this->_condition.resize(this->_get_condition_dim(), numFrames); + this->_condition.resize(this->GetConditionDim(), numFrames); for (size_t i = 0; i < this->_head_arrays.size(); i++) this->_head_arrays[i].resize(this->_head_arrays[i].rows(), numFrames); for (size_t i = 0; i < this->_layer_array_outputs.size(); i++) diff --git a/NAM/wavenet.h b/NAM/wavenet.h index 5dc66df..1609be5 100644 --- a/NAM/wavenet.h +++ b/NAM/wavenet.h @@ -193,7 +193,7 @@ class WaveNet : public DSP void _prepare_for_frames_(const long numFrames); void Process(float* input, float* output, const int numFrames) override; - virtual int _get_condition_dim() const { return 1; }; + virtual int GetConditionDim() const { return 1; }; // Fill in the "condition" array that's fed into the various parts of the net. virtual void SetConditionArray(float* input, const int numFrames); // Ensure that all buffer arrays are the right size for this numFrames From 6181f498e2cb2f0dbeb40d6b328261e08a92e3c8 Mon Sep 17 00:00:00 2001 From: Oli Larkin Date: Sat, 20 Jan 2024 00:38:41 +0100 Subject: [PATCH 076/133] PrepareForFrames --- NAM/wavenet.cpp | 4 ++-- NAM/wavenet.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/NAM/wavenet.cpp b/NAM/wavenet.cpp index 05f4242..43efa2a 100644 --- a/NAM/wavenet.cpp +++ b/NAM/wavenet.cpp @@ -309,7 +309,7 @@ void nam::wavenet::WaveNet::_advance_buffers_(const int numFrames) this->_layer_arrays[i].advance_buffers_(numFrames); } -void nam::wavenet::WaveNet::_prepare_for_frames_(const long numFrames) +void nam::wavenet::WaveNet::PrepareForFrames(const long numFrames) { for (size_t i = 0; i < this->_layer_arrays.size(); i++) this->_layer_arrays[i].prepare_for_frames_(numFrames); @@ -326,7 +326,7 @@ void nam::wavenet::WaveNet::SetConditionArray(float* input, const int numFrames) void nam::wavenet::WaveNet::Process(float* input, float* output, const int numFrames) { this->SetNumFrames(numFrames); - this->_prepare_for_frames_(numFrames); + this->PrepareForFrames(numFrames); this->SetConditionArray(input, numFrames); // Main layer arrays: diff --git a/NAM/wavenet.h b/NAM/wavenet.h index 1609be5..83f6653 100644 --- a/NAM/wavenet.h +++ b/NAM/wavenet.h @@ -190,7 +190,7 @@ class WaveNet : public DSP Eigen::MatrixXf _head_output; void _advance_buffers_(const int numFrames); - void _prepare_for_frames_(const long numFrames); + void PrepareForFrames(const long numFrames); void Process(float* input, float* output, const int numFrames) override; virtual int GetConditionDim() const { return 1; }; From 977bc78aa1f05d54aa0fe0ae6caeb2c8191f224c Mon Sep 17 00:00:00 2001 From: Oli Larkin Date: Sat, 20 Jan 2024 00:39:02 +0100 Subject: [PATCH 077/133] AdvanceBuffers --- NAM/wavenet.cpp | 4 ++-- NAM/wavenet.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/NAM/wavenet.cpp b/NAM/wavenet.cpp index 43efa2a..0ae71a6 100644 --- a/NAM/wavenet.cpp +++ b/NAM/wavenet.cpp @@ -279,7 +279,7 @@ nam::wavenet::WaveNet::WaveNet(const std::vector void nam::wavenet::WaveNet::Finalize(const int numFrames) { this->DSP::Finalize(numFrames); - this->_advance_buffers_(numFrames); + this->AdvanceBuffers(numFrames); } void nam::wavenet::WaveNet::SetWeights(const std::vector& weights) @@ -303,7 +303,7 @@ void nam::wavenet::WaveNet::SetWeights(const std::vector& weights) } } -void nam::wavenet::WaveNet::_advance_buffers_(const int numFrames) +void nam::wavenet::WaveNet::AdvanceBuffers(const int numFrames) { for (size_t i = 0; i < this->_layer_arrays.size(); i++) this->_layer_arrays[i].advance_buffers_(numFrames); diff --git a/NAM/wavenet.h b/NAM/wavenet.h index 83f6653..1c0b7d4 100644 --- a/NAM/wavenet.h +++ b/NAM/wavenet.h @@ -189,7 +189,7 @@ class WaveNet : public DSP float _head_scale; Eigen::MatrixXf _head_output; - void _advance_buffers_(const int numFrames); + void AdvanceBuffers(const int numFrames); void PrepareForFrames(const long numFrames); void Process(float* input, float* output, const int numFrames) override; From 95f2edfaa81482c2c9799069b4edb6df7e113310 Mon Sep 17 00:00:00 2001 From: Oli Larkin Date: Sat, 20 Jan 2024 00:39:34 +0100 Subject: [PATCH 078/133] _head_output --- NAM/wavenet.cpp | 6 +++--- NAM/wavenet.h | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/NAM/wavenet.cpp b/NAM/wavenet.cpp index 0ae71a6..c9ccc78 100644 --- a/NAM/wavenet.cpp +++ b/NAM/wavenet.cpp @@ -268,7 +268,7 @@ nam::wavenet::WaveNet::WaveNet(const std::vector } this->_head_arrays.push_back(Eigen::MatrixXf(layer_array_params[i].head_size, 0)); } - this->_head_output.resize(1, 0); // Mono output! + this->mHeadOutput.resize(1, 0); // Mono output! this->SetWeights(weights); mPrewarmSamples = 1; @@ -363,8 +363,8 @@ void nam::wavenet::WaveNet::SetNumFrames(const long numFrames) this->_head_arrays[i].resize(this->_head_arrays[i].rows(), numFrames); for (size_t i = 0; i < this->_layer_array_outputs.size(); i++) this->_layer_array_outputs[i].resize(this->_layer_array_outputs[i].rows(), numFrames); - this->_head_output.resize(this->_head_output.rows(), numFrames); - this->_head_output.setZero(); + this->mHeadOutput.resize(this->mHeadOutput.rows(), numFrames); + this->mHeadOutput.setZero(); for (size_t i = 0; i < this->_layer_arrays.size(); i++) this->_layer_arrays[i].set_num_frames_(numFrames); diff --git a/NAM/wavenet.h b/NAM/wavenet.h index 1c0b7d4..8a6dddf 100644 --- a/NAM/wavenet.h +++ b/NAM/wavenet.h @@ -187,7 +187,7 @@ class WaveNet : public DSP // One more than total layer arrays std::vector _head_arrays; float _head_scale; - Eigen::MatrixXf _head_output; + Eigen::MatrixXf mHeadOutput; void AdvanceBuffers(const int numFrames); void PrepareForFrames(const long numFrames); From 3b366e872bf00086e7f98960f301be2d44764834 Mon Sep 17 00:00:00 2001 From: Oli Larkin Date: Sat, 20 Jan 2024 00:39:54 +0100 Subject: [PATCH 079/133] mHeadScale --- NAM/wavenet.cpp | 6 +++--- NAM/wavenet.h | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/NAM/wavenet.cpp b/NAM/wavenet.cpp index c9ccc78..5a8fbff 100644 --- a/NAM/wavenet.cpp +++ b/NAM/wavenet.cpp @@ -245,7 +245,7 @@ nam::wavenet::WaveNet::WaveNet(const std::vector const double expectedSampleRate) : DSP(expectedSampleRate) , _num_frames(0) -, _head_scale(head_scale) +, mHeadScale(head_scale) { if (with_head) throw std::runtime_error("Head not implemented!"); @@ -288,7 +288,7 @@ void nam::wavenet::WaveNet::SetWeights(const std::vector& weights) for (size_t i = 0; i < this->_layer_arrays.size(); i++) this->_layer_arrays[i].SetWeights(it); // this->_head.set_params_(it); - this->_head_scale = *(it++); + this->mHeadScale = *(it++); if (it != weights.end()) { std::stringstream ss; @@ -348,7 +348,7 @@ void nam::wavenet::WaveNet::Process(float* input, float* output, const int numFr assert(this->_head_arrays[final_head_array].rows() == 1); for (int s = 0; s < numFrames; s++) { - float out = this->_head_scale * this->_head_arrays[final_head_array](0, s); + float out = this->mHeadScale * this->_head_arrays[final_head_array](0, s); output[s] = out; } } diff --git a/NAM/wavenet.h b/NAM/wavenet.h index 8a6dddf..67d769d 100644 --- a/NAM/wavenet.h +++ b/NAM/wavenet.h @@ -186,7 +186,7 @@ class WaveNet : public DSP Eigen::MatrixXf _condition; // One more than total layer arrays std::vector _head_arrays; - float _head_scale; + float mHeadScale; Eigen::MatrixXf mHeadOutput; void AdvanceBuffers(const int numFrames); From 485f8a1a1c7275d0d0b7e03180e227b5f1077656 Mon Sep 17 00:00:00 2001 From: Oli Larkin Date: Sat, 20 Jan 2024 00:40:12 +0100 Subject: [PATCH 080/133] mHeadArrays --- NAM/wavenet.cpp | 18 +++++++++--------- NAM/wavenet.h | 2 +- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/NAM/wavenet.cpp b/NAM/wavenet.cpp index 5a8fbff..eff0dd3 100644 --- a/NAM/wavenet.cpp +++ b/NAM/wavenet.cpp @@ -257,7 +257,7 @@ nam::wavenet::WaveNet::WaveNet(const std::vector layer_array_params[i].activation, layer_array_params[i].gated, layer_array_params[i].head_bias)); this->_layer_array_outputs.push_back(Eigen::MatrixXf(layer_array_params[i].channels, 0)); if (i == 0) - this->_head_arrays.push_back(Eigen::MatrixXf(layer_array_params[i].channels, 0)); + this->mHeadArrays.push_back(Eigen::MatrixXf(layer_array_params[i].channels, 0)); if (i > 0) if (layer_array_params[i].channels != layer_array_params[i - 1].head_size) { @@ -266,7 +266,7 @@ nam::wavenet::WaveNet::WaveNet(const std::vector << ") doesn't match head_size of preceding layer (" << layer_array_params[i - 1].head_size << "!\n"; throw std::runtime_error(ss.str().c_str()); } - this->_head_arrays.push_back(Eigen::MatrixXf(layer_array_params[i].head_size, 0)); + this->mHeadArrays.push_back(Eigen::MatrixXf(layer_array_params[i].head_size, 0)); } this->mHeadOutput.resize(1, 0); // Mono output! this->SetWeights(weights); @@ -332,10 +332,10 @@ void nam::wavenet::WaveNet::Process(float* input, float* output, const int numFr // Main layer arrays: // Layer-to-layer // Sum on head output - this->_head_arrays[0].setZero(); + this->mHeadArrays[0].setZero(); for (size_t i = 0; i < this->_layer_arrays.size(); i++) this->_layer_arrays[i].Process(i == 0 ? this->_condition : this->_layer_array_outputs[i - 1], this->_condition, - this->_head_arrays[i], this->_layer_array_outputs[i], this->_head_arrays[i + 1]); + this->mHeadArrays[i], this->_layer_array_outputs[i], this->mHeadArrays[i + 1]); // this->_head.Process( // this->_head_input, // this->_head_output @@ -344,11 +344,11 @@ void nam::wavenet::WaveNet::Process(float* input, float* output, const int numFr // Hack: apply head scale here; revisit when/if I activate the head. // assert(this->_head_output.rows() == 1); - const long final_head_array = this->_head_arrays.size() - 1; - assert(this->_head_arrays[final_head_array].rows() == 1); + const long final_head_array = this->mHeadArrays.size() - 1; + assert(this->mHeadArrays[final_head_array].rows() == 1); for (int s = 0; s < numFrames; s++) { - float out = this->mHeadScale * this->_head_arrays[final_head_array](0, s); + float out = this->mHeadScale * this->mHeadArrays[final_head_array](0, s); output[s] = out; } } @@ -359,8 +359,8 @@ void nam::wavenet::WaveNet::SetNumFrames(const long numFrames) return; this->_condition.resize(this->GetConditionDim(), numFrames); - for (size_t i = 0; i < this->_head_arrays.size(); i++) - this->_head_arrays[i].resize(this->_head_arrays[i].rows(), numFrames); + for (size_t i = 0; i < this->mHeadArrays.size(); i++) + this->mHeadArrays[i].resize(this->mHeadArrays[i].rows(), numFrames); for (size_t i = 0; i < this->_layer_array_outputs.size(); i++) this->_layer_array_outputs[i].resize(this->_layer_array_outputs[i].rows(), numFrames); this->mHeadOutput.resize(this->mHeadOutput.rows(), numFrames); diff --git a/NAM/wavenet.h b/NAM/wavenet.h index 67d769d..495c36a 100644 --- a/NAM/wavenet.h +++ b/NAM/wavenet.h @@ -185,7 +185,7 @@ class WaveNet : public DSP // Element-wise arrays: Eigen::MatrixXf _condition; // One more than total layer arrays - std::vector _head_arrays; + std::vector mHeadArrays; float mHeadScale; Eigen::MatrixXf mHeadOutput; From 4deb410586f60afca6e42b3ad3d621f55ab223c2 Mon Sep 17 00:00:00 2001 From: Oli Larkin Date: Sat, 20 Jan 2024 00:40:29 +0100 Subject: [PATCH 081/133] mCondition --- NAM/wavenet.cpp | 6 +++--- NAM/wavenet.h | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/NAM/wavenet.cpp b/NAM/wavenet.cpp index eff0dd3..bd07701 100644 --- a/NAM/wavenet.cpp +++ b/NAM/wavenet.cpp @@ -319,7 +319,7 @@ void nam::wavenet::WaveNet::SetConditionArray(float* input, const int numFrames) { for (int j = 0; j < numFrames; j++) { - this->_condition(0, j) = input[j]; + this->mCondition(0, j) = input[j]; } } @@ -334,7 +334,7 @@ void nam::wavenet::WaveNet::Process(float* input, float* output, const int numFr // Sum on head output this->mHeadArrays[0].setZero(); for (size_t i = 0; i < this->_layer_arrays.size(); i++) - this->_layer_arrays[i].Process(i == 0 ? this->_condition : this->_layer_array_outputs[i - 1], this->_condition, + this->_layer_arrays[i].Process(i == 0 ? this->mCondition : this->_layer_array_outputs[i - 1], this->mCondition, this->mHeadArrays[i], this->_layer_array_outputs[i], this->mHeadArrays[i + 1]); // this->_head.Process( // this->_head_input, @@ -358,7 +358,7 @@ void nam::wavenet::WaveNet::SetNumFrames(const long numFrames) if (numFrames == this->_num_frames) return; - this->_condition.resize(this->GetConditionDim(), numFrames); + this->mCondition.resize(this->GetConditionDim(), numFrames); for (size_t i = 0; i < this->mHeadArrays.size(); i++) this->mHeadArrays[i].resize(this->mHeadArrays[i].rows(), numFrames); for (size_t i = 0; i < this->_layer_array_outputs.size(); i++) diff --git a/NAM/wavenet.h b/NAM/wavenet.h index 495c36a..a385887 100644 --- a/NAM/wavenet.h +++ b/NAM/wavenet.h @@ -183,7 +183,7 @@ class WaveNet : public DSP // Head _head; // Element-wise arrays: - Eigen::MatrixXf _condition; + Eigen::MatrixXf mCondition; // One more than total layer arrays std::vector mHeadArrays; float mHeadScale; From a98e18198ae3461e99cd836378b37d3ae225fe0b Mon Sep 17 00:00:00 2001 From: Oli Larkin Date: Sat, 20 Jan 2024 00:40:50 +0100 Subject: [PATCH 082/133] mLayerArrayOutputs --- NAM/wavenet.cpp | 10 +++++----- NAM/wavenet.h | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/NAM/wavenet.cpp b/NAM/wavenet.cpp index bd07701..b2a0e25 100644 --- a/NAM/wavenet.cpp +++ b/NAM/wavenet.cpp @@ -255,7 +255,7 @@ nam::wavenet::WaveNet::WaveNet(const std::vector layer_array_params[i].inputSize, layer_array_params[i].condition_size, layer_array_params[i].head_size, layer_array_params[i].channels, layer_array_params[i].kernelSize, layer_array_params[i].dilations, layer_array_params[i].activation, layer_array_params[i].gated, layer_array_params[i].head_bias)); - this->_layer_array_outputs.push_back(Eigen::MatrixXf(layer_array_params[i].channels, 0)); + this->mLayerArrayOutputs.push_back(Eigen::MatrixXf(layer_array_params[i].channels, 0)); if (i == 0) this->mHeadArrays.push_back(Eigen::MatrixXf(layer_array_params[i].channels, 0)); if (i > 0) @@ -334,8 +334,8 @@ void nam::wavenet::WaveNet::Process(float* input, float* output, const int numFr // Sum on head output this->mHeadArrays[0].setZero(); for (size_t i = 0; i < this->_layer_arrays.size(); i++) - this->_layer_arrays[i].Process(i == 0 ? this->mCondition : this->_layer_array_outputs[i - 1], this->mCondition, - this->mHeadArrays[i], this->_layer_array_outputs[i], this->mHeadArrays[i + 1]); + this->_layer_arrays[i].Process(i == 0 ? this->mCondition : this->mLayerArrayOutputs[i - 1], this->mCondition, + this->mHeadArrays[i], this->mLayerArrayOutputs[i], this->mHeadArrays[i + 1]); // this->_head.Process( // this->_head_input, // this->_head_output @@ -361,8 +361,8 @@ void nam::wavenet::WaveNet::SetNumFrames(const long numFrames) this->mCondition.resize(this->GetConditionDim(), numFrames); for (size_t i = 0; i < this->mHeadArrays.size(); i++) this->mHeadArrays[i].resize(this->mHeadArrays[i].rows(), numFrames); - for (size_t i = 0; i < this->_layer_array_outputs.size(); i++) - this->_layer_array_outputs[i].resize(this->_layer_array_outputs[i].rows(), numFrames); + for (size_t i = 0; i < this->mLayerArrayOutputs.size(); i++) + this->mLayerArrayOutputs[i].resize(this->mLayerArrayOutputs[i].rows(), numFrames); this->mHeadOutput.resize(this->mHeadOutput.rows(), numFrames); this->mHeadOutput.setZero(); diff --git a/NAM/wavenet.h b/NAM/wavenet.h index a385887..990a841 100644 --- a/NAM/wavenet.h +++ b/NAM/wavenet.h @@ -179,7 +179,7 @@ class WaveNet : public DSP long _num_frames; std::vector<_LayerArray> _layer_arrays; // Their outputs - std::vector _layer_array_outputs; + std::vector mLayerArrayOutputs; // Head _head; // Element-wise arrays: From 67bc968cb7c9f4a1fbaf30da248784e80c419c0a Mon Sep 17 00:00:00 2001 From: Oli Larkin Date: Sat, 20 Jan 2024 00:41:11 +0100 Subject: [PATCH 083/133] mLayerArrays --- NAM/wavenet.cpp | 26 +++++++++++++------------- NAM/wavenet.h | 2 +- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/NAM/wavenet.cpp b/NAM/wavenet.cpp index b2a0e25..4771261 100644 --- a/NAM/wavenet.cpp +++ b/NAM/wavenet.cpp @@ -251,7 +251,7 @@ nam::wavenet::WaveNet::WaveNet(const std::vector throw std::runtime_error("Head not implemented!"); for (size_t i = 0; i < layer_array_params.size(); i++) { - this->_layer_arrays.push_back(nam::wavenet::_LayerArray( + this->mLayerArrays.push_back(nam::wavenet::_LayerArray( layer_array_params[i].inputSize, layer_array_params[i].condition_size, layer_array_params[i].head_size, layer_array_params[i].channels, layer_array_params[i].kernelSize, layer_array_params[i].dilations, layer_array_params[i].activation, layer_array_params[i].gated, layer_array_params[i].head_bias)); @@ -272,8 +272,8 @@ nam::wavenet::WaveNet::WaveNet(const std::vector this->SetWeights(weights); mPrewarmSamples = 1; - for (size_t i = 0; i < this->_layer_arrays.size(); i++) - mPrewarmSamples += this->_layer_arrays[i].get_receptive_field(); + for (size_t i = 0; i < this->mLayerArrays.size(); i++) + mPrewarmSamples += this->mLayerArrays[i].get_receptive_field(); } void nam::wavenet::WaveNet::Finalize(const int numFrames) @@ -285,8 +285,8 @@ void nam::wavenet::WaveNet::Finalize(const int numFrames) void nam::wavenet::WaveNet::SetWeights(const std::vector& weights) { weights_it it = weights.begin(); - for (size_t i = 0; i < this->_layer_arrays.size(); i++) - this->_layer_arrays[i].SetWeights(it); + for (size_t i = 0; i < this->mLayerArrays.size(); i++) + this->mLayerArrays[i].SetWeights(it); // this->_head.set_params_(it); this->mHeadScale = *(it++); if (it != weights.end()) @@ -305,14 +305,14 @@ void nam::wavenet::WaveNet::SetWeights(const std::vector& weights) void nam::wavenet::WaveNet::AdvanceBuffers(const int numFrames) { - for (size_t i = 0; i < this->_layer_arrays.size(); i++) - this->_layer_arrays[i].advance_buffers_(numFrames); + for (size_t i = 0; i < this->mLayerArrays.size(); i++) + this->mLayerArrays[i].advance_buffers_(numFrames); } void nam::wavenet::WaveNet::PrepareForFrames(const long numFrames) { - for (size_t i = 0; i < this->_layer_arrays.size(); i++) - this->_layer_arrays[i].prepare_for_frames_(numFrames); + for (size_t i = 0; i < this->mLayerArrays.size(); i++) + this->mLayerArrays[i].prepare_for_frames_(numFrames); } void nam::wavenet::WaveNet::SetConditionArray(float* input, const int numFrames) @@ -333,8 +333,8 @@ void nam::wavenet::WaveNet::Process(float* input, float* output, const int numFr // Layer-to-layer // Sum on head output this->mHeadArrays[0].setZero(); - for (size_t i = 0; i < this->_layer_arrays.size(); i++) - this->_layer_arrays[i].Process(i == 0 ? this->mCondition : this->mLayerArrayOutputs[i - 1], this->mCondition, + for (size_t i = 0; i < this->mLayerArrays.size(); i++) + this->mLayerArrays[i].Process(i == 0 ? this->mCondition : this->mLayerArrayOutputs[i - 1], this->mCondition, this->mHeadArrays[i], this->mLayerArrayOutputs[i], this->mHeadArrays[i + 1]); // this->_head.Process( // this->_head_input, @@ -366,8 +366,8 @@ void nam::wavenet::WaveNet::SetNumFrames(const long numFrames) this->mHeadOutput.resize(this->mHeadOutput.rows(), numFrames); this->mHeadOutput.setZero(); - for (size_t i = 0; i < this->_layer_arrays.size(); i++) - this->_layer_arrays[i].set_num_frames_(numFrames); + for (size_t i = 0; i < this->mLayerArrays.size(); i++) + this->mLayerArrays[i].set_num_frames_(numFrames); // this->_head.set_num_frames_(numFrames); this->_num_frames = numFrames; } diff --git a/NAM/wavenet.h b/NAM/wavenet.h index 990a841..8863096 100644 --- a/NAM/wavenet.h +++ b/NAM/wavenet.h @@ -177,7 +177,7 @@ class WaveNet : public DSP private: long _num_frames; - std::vector<_LayerArray> _layer_arrays; + std::vector<_LayerArray> mLayerArrays; // Their outputs std::vector mLayerArrayOutputs; // Head _head; From 1040bb7e0b6efdb5504e4ef63c227c7a8538d929 Mon Sep 17 00:00:00 2001 From: Oli Larkin Date: Sat, 20 Jan 2024 00:41:58 +0100 Subject: [PATCH 084/133] _LayerArray --- NAM/wavenet.cpp | 22 +++++++++++----------- NAM/wavenet.h | 6 +++--- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/NAM/wavenet.cpp b/NAM/wavenet.cpp index 4771261..4f7c2c4 100644 --- a/NAM/wavenet.cpp +++ b/NAM/wavenet.cpp @@ -59,7 +59,7 @@ void nam::wavenet::_Layer::set_num_frames_(const long numFrames) #define LAYER_ARRAY_BUFFER_SIZE 65536 -nam::wavenet::_LayerArray::_LayerArray(const int inputSize, const int condition_size, const int head_size, +nam::wavenet::LayerArray::LayerArray(const int inputSize, const int condition_size, const int head_size, const int channels, const int kernelSize, const std::vector& dilations, const std::string activation, const bool gated, const bool head_bias) : _rechannel(inputSize, channels, false) @@ -76,12 +76,12 @@ nam::wavenet::_LayerArray::_LayerArray(const int inputSize, const int condition_ this->_buffer_start = this->_get_receptive_field() - 1; } -void nam::wavenet::_LayerArray::advance_buffers_(const int numFrames) +void nam::wavenet::LayerArray::advance_buffers_(const int numFrames) { this->_buffer_start += numFrames; } -long nam::wavenet::_LayerArray::get_receptive_field() const +long nam::wavenet::LayerArray::get_receptive_field() const { long result = 0; for (size_t i = 0; i < this->_layers.size(); i++) @@ -89,7 +89,7 @@ long nam::wavenet::_LayerArray::get_receptive_field() const return result; } -void nam::wavenet::_LayerArray::prepare_for_frames_(const long numFrames) +void nam::wavenet::LayerArray::prepare_for_frames_(const long numFrames) { // Example: // _buffer_start = 0 @@ -102,7 +102,7 @@ void nam::wavenet::_LayerArray::prepare_for_frames_(const long numFrames) this->RewindBuffers(); } -void nam::wavenet::_LayerArray::Process(const Eigen::Ref layer_inputs, const Eigen::Ref condition, +void nam::wavenet::LayerArray::Process(const Eigen::Ref layer_inputs, const Eigen::Ref condition, Eigen::Ref head_inputs, Eigen::Ref layer_outputs, Eigen::Ref head_outputs) { @@ -127,7 +127,7 @@ void nam::wavenet::_LayerArray::Process(const Eigen::Ref head_outputs = this->_head_rechannel.Process(head_inputs); } -void nam::wavenet::_LayerArray::set_num_frames_(const long numFrames) +void nam::wavenet::LayerArray::set_num_frames_(const long numFrames) { // Wavenet checks for unchanged numFrames; if we made it here, there's // something to do. @@ -143,7 +143,7 @@ void nam::wavenet::_LayerArray::set_num_frames_(const long numFrames) this->_layers[i].set_num_frames_(numFrames); } -void nam::wavenet::_LayerArray::SetWeights(weights_it& weights) +void nam::wavenet::LayerArray::SetWeights(weights_it& weights) { this->_rechannel.SetWeights(weights); for (size_t i = 0; i < this->_layers.size(); i++) @@ -151,12 +151,12 @@ void nam::wavenet::_LayerArray::SetWeights(weights_it& weights) this->_head_rechannel.SetWeights(weights); } -long nam::wavenet::_LayerArray::_get_channels() const +long nam::wavenet::LayerArray::_get_channels() const { return this->_layers.size() > 0 ? this->_layers[0].get_channels() : 0; } -long nam::wavenet::_LayerArray::_get_receptive_field() const +long nam::wavenet::LayerArray::_get_receptive_field() const { // TODO remove this and use get_receptive_field() instead! long res = 1; @@ -165,7 +165,7 @@ long nam::wavenet::_LayerArray::_get_receptive_field() const return res; } -void nam::wavenet::_LayerArray::RewindBuffers() +void nam::wavenet::LayerArray::RewindBuffers() // Consider wrapping instead... // Can make this smaller--largest dilation, not receptive field! { @@ -251,7 +251,7 @@ nam::wavenet::WaveNet::WaveNet(const std::vector throw std::runtime_error("Head not implemented!"); for (size_t i = 0; i < layer_array_params.size(); i++) { - this->mLayerArrays.push_back(nam::wavenet::_LayerArray( + this->mLayerArrays.push_back(nam::wavenet::LayerArray( layer_array_params[i].inputSize, layer_array_params[i].condition_size, layer_array_params[i].head_size, layer_array_params[i].channels, layer_array_params[i].kernelSize, layer_array_params[i].dilations, layer_array_params[i].activation, layer_array_params[i].gated, layer_array_params[i].head_bias)); diff --git a/NAM/wavenet.h b/NAM/wavenet.h index 8863096..c3ec812 100644 --- a/NAM/wavenet.h +++ b/NAM/wavenet.h @@ -85,10 +85,10 @@ class LayerArrayParams }; // An array of layers with the same channels, kernel sizes, activations. -class _LayerArray +class LayerArray { public: - _LayerArray(const int inputSize, const int condition_size, const int head_size, const int channels, + LayerArray(const int inputSize, const int condition_size, const int head_size, const int channels, const int kernelSize, const std::vector& dilations, const std::string activation, const bool gated, const bool head_bias); @@ -177,7 +177,7 @@ class WaveNet : public DSP private: long _num_frames; - std::vector<_LayerArray> mLayerArrays; + std::vector mLayerArrays; // Their outputs std::vector mLayerArrayOutputs; // Head _head; From e9a5092fb6cdd9ca278cd0ea4b3e23eb03fd14bd Mon Sep 17 00:00:00 2001 From: Oli Larkin Date: Sat, 20 Jan 2024 00:42:31 +0100 Subject: [PATCH 085/133] _num_frames --- NAM/wavenet.cpp | 6 +++--- NAM/wavenet.h | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/NAM/wavenet.cpp b/NAM/wavenet.cpp index 4f7c2c4..994e18d 100644 --- a/NAM/wavenet.cpp +++ b/NAM/wavenet.cpp @@ -244,7 +244,7 @@ nam::wavenet::WaveNet::WaveNet(const std::vector const float head_scale, const bool with_head, const std::vector& weights, const double expectedSampleRate) : DSP(expectedSampleRate) -, _num_frames(0) +, mNumFrames(0) , mHeadScale(head_scale) { if (with_head) @@ -355,7 +355,7 @@ void nam::wavenet::WaveNet::Process(float* input, float* output, const int numFr void nam::wavenet::WaveNet::SetNumFrames(const long numFrames) { - if (numFrames == this->_num_frames) + if (numFrames == this->mNumFrames) return; this->mCondition.resize(this->GetConditionDim(), numFrames); @@ -369,5 +369,5 @@ void nam::wavenet::WaveNet::SetNumFrames(const long numFrames) for (size_t i = 0; i < this->mLayerArrays.size(); i++) this->mLayerArrays[i].set_num_frames_(numFrames); // this->_head.set_num_frames_(numFrames); - this->_num_frames = numFrames; + this->mNumFrames = numFrames; } diff --git a/NAM/wavenet.h b/NAM/wavenet.h index c3ec812..84f85a3 100644 --- a/NAM/wavenet.h +++ b/NAM/wavenet.h @@ -176,7 +176,7 @@ class WaveNet : public DSP void SetWeights(const std::vector& weights); private: - long _num_frames; + long mNumFrames; std::vector mLayerArrays; // Their outputs std::vector mLayerArrayOutputs; From a5e5a9837800f5a7db570230176a0263d4385a26 Mon Sep 17 00:00:00 2001 From: Oli Larkin Date: Sat, 20 Jan 2024 00:43:13 +0100 Subject: [PATCH 086/133] layer_array_params --- NAM/get_dsp.cpp | 6 +++--- NAM/wavenet.cpp | 22 +++++++++++----------- NAM/wavenet.h | 2 +- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/NAM/get_dsp.cpp b/NAM/get_dsp.cpp index 7fc9693..461f3d6 100644 --- a/NAM/get_dsp.cpp +++ b/NAM/get_dsp.cpp @@ -168,21 +168,21 @@ std::unique_ptr GetDSP(dspData& conf) } else if (architecture == "WaveNet") { - std::vector layer_array_params; + std::vector layerArrayParams; for (size_t i = 0; i < config["layers"].size(); i++) { nlohmann::json layer_config = config["layers"][i]; std::vector dilations; for (size_t j = 0; j < layer_config["dilations"].size(); j++) dilations.push_back(layer_config["dilations"][j]); - layer_array_params.push_back( + layerArrayParams.push_back( wavenet::LayerArrayParams(layer_config["input_size"], layer_config["condition_size"], layer_config["head_size"], layer_config["channels"], layer_config["kernel_size"], dilations, layer_config["activation"], layer_config["gated"], layer_config["head_bias"])); } const bool with_head = config["head"] == NULL; const float head_scale = config["head_scale"]; - out = std::make_unique(layer_array_params, head_scale, with_head, weights, expectedSampleRate); + out = std::make_unique(layerArrayParams, head_scale, with_head, weights, expectedSampleRate); } else { diff --git a/NAM/wavenet.cpp b/NAM/wavenet.cpp index 994e18d..b55b902 100644 --- a/NAM/wavenet.cpp +++ b/NAM/wavenet.cpp @@ -240,7 +240,7 @@ void nam::wavenet::Head::_apply_activation_(Eigen::Ref x) // WaveNet ==================================================================== -nam::wavenet::WaveNet::WaveNet(const std::vector& layer_array_params, +nam::wavenet::WaveNet::WaveNet(const std::vector& layerArrayParams, const float head_scale, const bool with_head, const std::vector& weights, const double expectedSampleRate) : DSP(expectedSampleRate) @@ -249,24 +249,24 @@ nam::wavenet::WaveNet::WaveNet(const std::vector { if (with_head) throw std::runtime_error("Head not implemented!"); - for (size_t i = 0; i < layer_array_params.size(); i++) + for (size_t i = 0; i < layerArrayParams.size(); i++) { this->mLayerArrays.push_back(nam::wavenet::LayerArray( - layer_array_params[i].inputSize, layer_array_params[i].condition_size, layer_array_params[i].head_size, - layer_array_params[i].channels, layer_array_params[i].kernelSize, layer_array_params[i].dilations, - layer_array_params[i].activation, layer_array_params[i].gated, layer_array_params[i].head_bias)); - this->mLayerArrayOutputs.push_back(Eigen::MatrixXf(layer_array_params[i].channels, 0)); + layerArrayParams[i].inputSize, layerArrayParams[i].condition_size, layerArrayParams[i].head_size, + layerArrayParams[i].channels, layerArrayParams[i].kernelSize, layerArrayParams[i].dilations, + layerArrayParams[i].activation, layerArrayParams[i].gated, layerArrayParams[i].head_bias)); + this->mLayerArrayOutputs.push_back(Eigen::MatrixXf(layerArrayParams[i].channels, 0)); if (i == 0) - this->mHeadArrays.push_back(Eigen::MatrixXf(layer_array_params[i].channels, 0)); + this->mHeadArrays.push_back(Eigen::MatrixXf(layerArrayParams[i].channels, 0)); if (i > 0) - if (layer_array_params[i].channels != layer_array_params[i - 1].head_size) + if (layerArrayParams[i].channels != layerArrayParams[i - 1].head_size) { std::stringstream ss; - ss << "channels of layer " << i << " (" << layer_array_params[i].channels - << ") doesn't match head_size of preceding layer (" << layer_array_params[i - 1].head_size << "!\n"; + ss << "channels of layer " << i << " (" << layerArrayParams[i].channels + << ") doesn't match head_size of preceding layer (" << layerArrayParams[i - 1].head_size << "!\n"; throw std::runtime_error(ss.str().c_str()); } - this->mHeadArrays.push_back(Eigen::MatrixXf(layer_array_params[i].head_size, 0)); + this->mHeadArrays.push_back(Eigen::MatrixXf(layerArrayParams[i].head_size, 0)); } this->mHeadOutput.resize(1, 0); // Mono output! this->SetWeights(weights); diff --git a/NAM/wavenet.h b/NAM/wavenet.h index 84f85a3..3ce3dc9 100644 --- a/NAM/wavenet.h +++ b/NAM/wavenet.h @@ -168,7 +168,7 @@ class Head class WaveNet : public DSP { public: - WaveNet(const std::vector& layer_array_params, const float head_scale, const bool with_head, + WaveNet(const std::vector& layerArrayParams, const float head_scale, const bool with_head, const std::vector& weights, const double expectedSampleRate = -1.0); ~WaveNet() = default; From 8d953b5aedffae29de9694b9b7f539602320a155 Mon Sep 17 00:00:00 2001 From: Oli Larkin Date: Sat, 20 Jan 2024 00:43:56 +0100 Subject: [PATCH 087/133] head_scale --- NAM/get_dsp.cpp | 4 ++-- NAM/wavenet.cpp | 4 ++-- NAM/wavenet.h | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/NAM/get_dsp.cpp b/NAM/get_dsp.cpp index 461f3d6..cc5fdd9 100644 --- a/NAM/get_dsp.cpp +++ b/NAM/get_dsp.cpp @@ -181,8 +181,8 @@ std::unique_ptr GetDSP(dspData& conf) layer_config["activation"], layer_config["gated"], layer_config["head_bias"])); } const bool with_head = config["head"] == NULL; - const float head_scale = config["head_scale"]; - out = std::make_unique(layerArrayParams, head_scale, with_head, weights, expectedSampleRate); + const float headScale = config["head_scale"]; + out = std::make_unique(layerArrayParams, headScale, with_head, weights, expectedSampleRate); } else { diff --git a/NAM/wavenet.cpp b/NAM/wavenet.cpp index b55b902..91a5947 100644 --- a/NAM/wavenet.cpp +++ b/NAM/wavenet.cpp @@ -241,11 +241,11 @@ void nam::wavenet::Head::_apply_activation_(Eigen::Ref x) // WaveNet ==================================================================== nam::wavenet::WaveNet::WaveNet(const std::vector& layerArrayParams, - const float head_scale, const bool with_head, const std::vector& weights, + const float headScale, const bool with_head, const std::vector& weights, const double expectedSampleRate) : DSP(expectedSampleRate) , mNumFrames(0) -, mHeadScale(head_scale) +, mHeadScale(headScale) { if (with_head) throw std::runtime_error("Head not implemented!"); diff --git a/NAM/wavenet.h b/NAM/wavenet.h index 3ce3dc9..e9b872c 100644 --- a/NAM/wavenet.h +++ b/NAM/wavenet.h @@ -168,7 +168,7 @@ class Head class WaveNet : public DSP { public: - WaveNet(const std::vector& layerArrayParams, const float head_scale, const bool with_head, + WaveNet(const std::vector& layerArrayParams, const float headScale, const bool with_head, const std::vector& weights, const double expectedSampleRate = -1.0); ~WaveNet() = default; From 26243685d8ea462c0d910e1c641c3beba15384ae Mon Sep 17 00:00:00 2001 From: Oli Larkin Date: Sat, 20 Jan 2024 00:44:21 +0100 Subject: [PATCH 088/133] with_head --- NAM/get_dsp.cpp | 4 ++-- NAM/wavenet.cpp | 4 ++-- NAM/wavenet.h | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/NAM/get_dsp.cpp b/NAM/get_dsp.cpp index cc5fdd9..150a1ad 100644 --- a/NAM/get_dsp.cpp +++ b/NAM/get_dsp.cpp @@ -180,9 +180,9 @@ std::unique_ptr GetDSP(dspData& conf) layer_config["channels"], layer_config["kernel_size"], dilations, layer_config["activation"], layer_config["gated"], layer_config["head_bias"])); } - const bool with_head = config["head"] == NULL; + const bool withHead = config["head"] == NULL; const float headScale = config["head_scale"]; - out = std::make_unique(layerArrayParams, headScale, with_head, weights, expectedSampleRate); + out = std::make_unique(layerArrayParams, headScale, withHead, weights, expectedSampleRate); } else { diff --git a/NAM/wavenet.cpp b/NAM/wavenet.cpp index 91a5947..6613ae9 100644 --- a/NAM/wavenet.cpp +++ b/NAM/wavenet.cpp @@ -241,13 +241,13 @@ void nam::wavenet::Head::_apply_activation_(Eigen::Ref x) // WaveNet ==================================================================== nam::wavenet::WaveNet::WaveNet(const std::vector& layerArrayParams, - const float headScale, const bool with_head, const std::vector& weights, + const float headScale, const bool withHead, const std::vector& weights, const double expectedSampleRate) : DSP(expectedSampleRate) , mNumFrames(0) , mHeadScale(headScale) { - if (with_head) + if (withHead) throw std::runtime_error("Head not implemented!"); for (size_t i = 0; i < layerArrayParams.size(); i++) { diff --git a/NAM/wavenet.h b/NAM/wavenet.h index e9b872c..e55337b 100644 --- a/NAM/wavenet.h +++ b/NAM/wavenet.h @@ -168,7 +168,7 @@ class Head class WaveNet : public DSP { public: - WaveNet(const std::vector& layerArrayParams, const float headScale, const bool with_head, + WaveNet(const std::vector& layerArrayParams, const float headScale, const bool withHead, const std::vector& weights, const double expectedSampleRate = -1.0); ~WaveNet() = default; From ef59cb9239e27a3b6fdae2dbf01ccdddb2e86aaa Mon Sep 17 00:00:00 2001 From: Oli Larkin Date: Sat, 20 Jan 2024 00:44:45 +0100 Subject: [PATCH 089/133] _apply_activation_ --- NAM/wavenet.cpp | 6 +++--- NAM/wavenet.h | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/NAM/wavenet.cpp b/NAM/wavenet.cpp index 6613ae9..a668bdb 100644 --- a/NAM/wavenet.cpp +++ b/NAM/wavenet.cpp @@ -205,7 +205,7 @@ void nam::wavenet::Head::SetWeights(weights_it& weights) void nam::wavenet::Head::Process(Eigen::Ref inputs, Eigen::Ref outputs) { const size_t numLayers = this->_layers.size(); - this->_apply_activation_(inputs); + this->ApplyActivation(inputs); if (numLayers == 1) outputs = this->_layers[0].Process(inputs); else @@ -213,7 +213,7 @@ void nam::wavenet::Head::Process(Eigen::Ref inputs, Eigen::Ref< this->_buffers[0] = this->_layers[0].Process(inputs); for (size_t i = 1; i < numLayers; i++) { // Asserted > 0 layers - this->_apply_activation_(this->_buffers[i - 1]); + this->ApplyActivation(this->_buffers[i - 1]); if (i < numLayers - 1) this->_buffers[i] = this->_layers[i].Process(this->_buffers[i - 1]); else @@ -233,7 +233,7 @@ void nam::wavenet::Head::set_num_frames_(const long numFrames) } } -void nam::wavenet::Head::_apply_activation_(Eigen::Ref x) +void nam::wavenet::Head::ApplyActivation(Eigen::Ref x) { this->_activation->Apply(x); } diff --git a/NAM/wavenet.h b/NAM/wavenet.h index e55337b..ef7c9ba 100644 --- a/NAM/wavenet.h +++ b/NAM/wavenet.h @@ -161,7 +161,7 @@ class Head std::vector _buffers; // Apply the activation to the provided array, in-place - void _apply_activation_(Eigen::Ref x); + void ApplyActivation(Eigen::Ref x); }; // The main WaveNet model From 8e968df0c0bdcbd6240be09924e6430ee577d744 Mon Sep 17 00:00:00 2001 From: Oli Larkin Date: Sat, 20 Jan 2024 00:45:06 +0100 Subject: [PATCH 090/133] _buffers --- NAM/wavenet.cpp | 18 +++++++++--------- NAM/wavenet.h | 2 +- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/NAM/wavenet.cpp b/NAM/wavenet.cpp index a668bdb..18617fd 100644 --- a/NAM/wavenet.cpp +++ b/NAM/wavenet.cpp @@ -192,7 +192,7 @@ nam::wavenet::Head::Head(const int inputSize, const int numLayers, const int cha this->_layers.push_back(Conv1x1(dx, i == numLayers - 1 ? 1 : channels, true)); dx = channels; if (i < numLayers - 1) - this->_buffers.push_back(Eigen::MatrixXf()); + this->mBuffers.push_back(Eigen::MatrixXf()); } } @@ -210,26 +210,26 @@ void nam::wavenet::Head::Process(Eigen::Ref inputs, Eigen::Ref< outputs = this->_layers[0].Process(inputs); else { - this->_buffers[0] = this->_layers[0].Process(inputs); + this->mBuffers[0] = this->_layers[0].Process(inputs); for (size_t i = 1; i < numLayers; i++) { // Asserted > 0 layers - this->ApplyActivation(this->_buffers[i - 1]); + this->ApplyActivation(this->mBuffers[i - 1]); if (i < numLayers - 1) - this->_buffers[i] = this->_layers[i].Process(this->_buffers[i - 1]); + this->mBuffers[i] = this->_layers[i].Process(this->mBuffers[i - 1]); else - outputs = this->_layers[i].Process(this->_buffers[i - 1]); + outputs = this->_layers[i].Process(this->mBuffers[i - 1]); } } } void nam::wavenet::Head::set_num_frames_(const long numFrames) { - for (size_t i = 0; i < this->_buffers.size(); i++) + for (size_t i = 0; i < this->mBuffers.size(); i++) { - if (this->_buffers[i].rows() == this->_channels && this->_buffers[i].cols() == numFrames) + if (this->mBuffers[i].rows() == this->_channels && this->mBuffers[i].cols() == numFrames) continue; // Already has correct size - this->_buffers[i].resize(this->_channels, numFrames); - this->_buffers[i].setZero(); + this->mBuffers[i].resize(this->_channels, numFrames); + this->mBuffers[i].setZero(); } } diff --git a/NAM/wavenet.h b/NAM/wavenet.h index ef7c9ba..c19c435 100644 --- a/NAM/wavenet.h +++ b/NAM/wavenet.h @@ -158,7 +158,7 @@ class Head // Stores the outputs of the convs *except* the last one, which goes in // The array `outputs` provided to .Process() - std::vector _buffers; + std::vector mBuffers; // Apply the activation to the provided array, in-place void ApplyActivation(Eigen::Ref x); From 02e493427b2f2f2f6e8475418cb038dd9233d22d Mon Sep 17 00:00:00 2001 From: Oli Larkin Date: Sat, 20 Jan 2024 00:45:27 +0100 Subject: [PATCH 091/133] mActivation --- NAM/wavenet.cpp | 4 ++-- NAM/wavenet.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/NAM/wavenet.cpp b/NAM/wavenet.cpp index 18617fd..5b674b3 100644 --- a/NAM/wavenet.cpp +++ b/NAM/wavenet.cpp @@ -183,7 +183,7 @@ void nam::wavenet::LayerArray::RewindBuffers() nam::wavenet::Head::Head(const int inputSize, const int numLayers, const int channels, const std::string activation) : _channels(channels) , _head(numLayers > 0 ? channels : inputSize, 1, true) -, _activation(activations::Activation::GetActivation(activation)) +, mActivation(activations::Activation::GetActivation(activation)) { assert(numLayers > 0); int dx = inputSize; @@ -235,7 +235,7 @@ void nam::wavenet::Head::set_num_frames_(const long numFrames) void nam::wavenet::Head::ApplyActivation(Eigen::Ref x) { - this->_activation->Apply(x); + this->mActivation->Apply(x); } // WaveNet ==================================================================== diff --git a/NAM/wavenet.h b/NAM/wavenet.h index c19c435..1d24426 100644 --- a/NAM/wavenet.h +++ b/NAM/wavenet.h @@ -154,7 +154,7 @@ class Head int _channels; std::vector _layers; Conv1x1 _head; - activations::Activation* _activation; + activations::Activation* mActivation; // Stores the outputs of the convs *except* the last one, which goes in // The array `outputs` provided to .Process() From f34aca9ab88431845fa4ffb253fdc4002d792b99 Mon Sep 17 00:00:00 2001 From: Oli Larkin Date: Sat, 20 Jan 2024 00:45:47 +0100 Subject: [PATCH 092/133] mHead --- NAM/wavenet.cpp | 2 +- NAM/wavenet.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/NAM/wavenet.cpp b/NAM/wavenet.cpp index 5b674b3..0c08d12 100644 --- a/NAM/wavenet.cpp +++ b/NAM/wavenet.cpp @@ -182,7 +182,7 @@ void nam::wavenet::LayerArray::RewindBuffers() nam::wavenet::Head::Head(const int inputSize, const int numLayers, const int channels, const std::string activation) : _channels(channels) -, _head(numLayers > 0 ? channels : inputSize, 1, true) +, mHead(numLayers > 0 ? channels : inputSize, 1, true) , mActivation(activations::Activation::GetActivation(activation)) { assert(numLayers > 0); diff --git a/NAM/wavenet.h b/NAM/wavenet.h index 1d24426..aa525cd 100644 --- a/NAM/wavenet.h +++ b/NAM/wavenet.h @@ -153,7 +153,7 @@ class Head private: int _channels; std::vector _layers; - Conv1x1 _head; + Conv1x1 mHead; activations::Activation* mActivation; // Stores the outputs of the convs *except* the last one, which goes in From 6949bd8c10866bfddfe336083d2dc3fd2c6320d1 Mon Sep 17 00:00:00 2001 From: Oli Larkin Date: Sat, 20 Jan 2024 00:46:02 +0100 Subject: [PATCH 093/133] mLayers --- NAM/wavenet.cpp | 16 ++++++++-------- NAM/wavenet.h | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/NAM/wavenet.cpp b/NAM/wavenet.cpp index 0c08d12..c086aac 100644 --- a/NAM/wavenet.cpp +++ b/NAM/wavenet.cpp @@ -189,7 +189,7 @@ nam::wavenet::Head::Head(const int inputSize, const int numLayers, const int cha int dx = inputSize; for (int i = 0; i < numLayers; i++) { - this->_layers.push_back(Conv1x1(dx, i == numLayers - 1 ? 1 : channels, true)); + this->mLayers.push_back(Conv1x1(dx, i == numLayers - 1 ? 1 : channels, true)); dx = channels; if (i < numLayers - 1) this->mBuffers.push_back(Eigen::MatrixXf()); @@ -198,26 +198,26 @@ nam::wavenet::Head::Head(const int inputSize, const int numLayers, const int cha void nam::wavenet::Head::SetWeights(weights_it& weights) { - for (size_t i = 0; i < this->_layers.size(); i++) - this->_layers[i].SetWeights(weights); + for (size_t i = 0; i < this->mLayers.size(); i++) + this->mLayers[i].SetWeights(weights); } void nam::wavenet::Head::Process(Eigen::Ref inputs, Eigen::Ref outputs) { - const size_t numLayers = this->_layers.size(); + const size_t numLayers = this->mLayers.size(); this->ApplyActivation(inputs); if (numLayers == 1) - outputs = this->_layers[0].Process(inputs); + outputs = this->mLayers[0].Process(inputs); else { - this->mBuffers[0] = this->_layers[0].Process(inputs); + this->mBuffers[0] = this->mLayers[0].Process(inputs); for (size_t i = 1; i < numLayers; i++) { // Asserted > 0 layers this->ApplyActivation(this->mBuffers[i - 1]); if (i < numLayers - 1) - this->mBuffers[i] = this->_layers[i].Process(this->mBuffers[i - 1]); + this->mBuffers[i] = this->mLayers[i].Process(this->mBuffers[i - 1]); else - outputs = this->_layers[i].Process(this->mBuffers[i - 1]); + outputs = this->mLayers[i].Process(this->mBuffers[i - 1]); } } } diff --git a/NAM/wavenet.h b/NAM/wavenet.h index aa525cd..7d77468 100644 --- a/NAM/wavenet.h +++ b/NAM/wavenet.h @@ -152,7 +152,7 @@ class Head private: int _channels; - std::vector _layers; + std::vector mLayers; Conv1x1 mHead; activations::Activation* mActivation; From fea45ece9fb39e1fce4e2eefc14c7ece3223e9dd Mon Sep 17 00:00:00 2001 From: Oli Larkin Date: Sat, 20 Jan 2024 00:46:28 +0100 Subject: [PATCH 094/133] _channels --- NAM/wavenet.cpp | 6 +++--- NAM/wavenet.h | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/NAM/wavenet.cpp b/NAM/wavenet.cpp index c086aac..66739b7 100644 --- a/NAM/wavenet.cpp +++ b/NAM/wavenet.cpp @@ -181,7 +181,7 @@ void nam::wavenet::LayerArray::RewindBuffers() // Head ======================================================================= nam::wavenet::Head::Head(const int inputSize, const int numLayers, const int channels, const std::string activation) -: _channels(channels) +: mChannels(channels) , mHead(numLayers > 0 ? channels : inputSize, 1, true) , mActivation(activations::Activation::GetActivation(activation)) { @@ -226,9 +226,9 @@ void nam::wavenet::Head::set_num_frames_(const long numFrames) { for (size_t i = 0; i < this->mBuffers.size(); i++) { - if (this->mBuffers[i].rows() == this->_channels && this->mBuffers[i].cols() == numFrames) + if (this->mBuffers[i].rows() == this->mChannels && this->mBuffers[i].cols() == numFrames) continue; // Already has correct size - this->mBuffers[i].resize(this->_channels, numFrames); + this->mBuffers[i].resize(this->mChannels, numFrames); this->mBuffers[i].setZero(); } } diff --git a/NAM/wavenet.h b/NAM/wavenet.h index 7d77468..91c8c71 100644 --- a/NAM/wavenet.h +++ b/NAM/wavenet.h @@ -151,7 +151,7 @@ class Head void set_num_frames_(const long numFrames); private: - int _channels; + int mChannels; std::vector mLayers; Conv1x1 mHead; activations::Activation* mActivation; From 2e9f0f1d32c30ec943ff5048af311b9ebc9d8562 Mon Sep 17 00:00:00 2001 From: Oli Larkin Date: Sat, 20 Jan 2024 00:46:59 +0100 Subject: [PATCH 095/133] set_num_frames_ --- NAM/wavenet.cpp | 12 ++++++------ NAM/wavenet.h | 6 +++--- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/NAM/wavenet.cpp b/NAM/wavenet.cpp index 66739b7..99db632 100644 --- a/NAM/wavenet.cpp +++ b/NAM/wavenet.cpp @@ -46,7 +46,7 @@ void nam::wavenet::_Layer::Process(const Eigen::Ref input output.middleCols(j_start, ncols) = input.middleCols(i_start, ncols) + this->_1x1.Process(this->_z.topRows(channels)); } -void nam::wavenet::_Layer::set_num_frames_(const long numFrames) +void nam::wavenet::_Layer::SetNumFrames(const long numFrames) { if (this->_z.rows() == this->_conv.GetOutChannels() && this->_z.cols() == numFrames) return; // Already has correct size @@ -127,7 +127,7 @@ void nam::wavenet::LayerArray::Process(const Eigen::Ref l head_outputs = this->_head_rechannel.Process(head_inputs); } -void nam::wavenet::LayerArray::set_num_frames_(const long numFrames) +void nam::wavenet::LayerArray::SetNumFrames(const long numFrames) { // Wavenet checks for unchanged numFrames; if we made it here, there's // something to do. @@ -140,7 +140,7 @@ void nam::wavenet::LayerArray::set_num_frames_(const long numFrames) throw std::runtime_error(ss.str().c_str()); } for (size_t i = 0; i < this->_layers.size(); i++) - this->_layers[i].set_num_frames_(numFrames); + this->_layers[i].SetNumFrames(numFrames); } void nam::wavenet::LayerArray::SetWeights(weights_it& weights) @@ -222,7 +222,7 @@ void nam::wavenet::Head::Process(Eigen::Ref inputs, Eigen::Ref< } } -void nam::wavenet::Head::set_num_frames_(const long numFrames) +void nam::wavenet::Head::SetNumFrames(const long numFrames) { for (size_t i = 0; i < this->mBuffers.size(); i++) { @@ -367,7 +367,7 @@ void nam::wavenet::WaveNet::SetNumFrames(const long numFrames) this->mHeadOutput.setZero(); for (size_t i = 0; i < this->mLayerArrays.size(); i++) - this->mLayerArrays[i].set_num_frames_(numFrames); - // this->_head.set_num_frames_(numFrames); + this->mLayerArrays[i].SetNumFrames(numFrames); + // this->_head.SetNumFrames(numFrames); this->mNumFrames = numFrames; } diff --git a/NAM/wavenet.h b/NAM/wavenet.h index 91c8c71..1eca242 100644 --- a/NAM/wavenet.h +++ b/NAM/wavenet.h @@ -35,7 +35,7 @@ class _Layer // :param `output`: to next layer void Process(const Eigen::Ref input, const Eigen::Ref condition, Eigen::Ref head_input, Eigen::Ref output, const long i_start, const long j_start); - void set_num_frames_(const long numFrames); + void SetNumFrames(const long numFrames); long get_channels() const { return this->_conv.GetInChannels(); }; int GetDilation() const { return this->_conv.GetDilation(); }; long GetKernelSize() const { return this->_conv.GetKernelSize(); }; @@ -107,7 +107,7 @@ class LayerArray Eigen::Ref head_inputs, // Sum up on this. Eigen::Ref head_outputs // post head-rechannel ); - void set_num_frames_(const long numFrames); + void SetNumFrames(const long numFrames); void SetWeights(weights_it& it); // "Zero-indexed" receptive field. @@ -148,7 +148,7 @@ class Head // NOTE: the head transforms the provided input by applying a nonlinearity // to it in-place! void Process(Eigen::Ref inputs, Eigen::Ref outputs); - void set_num_frames_(const long numFrames); + void SetNumFrames(const long numFrames); private: int mChannels; From 658fe38bc61c3c90e31bcbb866a66ce8f26756d7 Mon Sep 17 00:00:00 2001 From: Oli Larkin Date: Sat, 20 Jan 2024 00:48:53 +0100 Subject: [PATCH 096/133] GetReceptiveField --- NAM/wavenet.cpp | 12 ++++++------ NAM/wavenet.h | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/NAM/wavenet.cpp b/NAM/wavenet.cpp index 99db632..bc5c12f 100644 --- a/NAM/wavenet.cpp +++ b/NAM/wavenet.cpp @@ -67,13 +67,13 @@ nam::wavenet::LayerArray::LayerArray(const int inputSize, const int condition_si { for (size_t i = 0; i < dilations.size(); i++) this->_layers.push_back(_Layer(condition_size, channels, kernelSize, dilations[i], activation, gated)); - const long receptiveField = this->_get_receptive_field(); + const long receptiveField = this->GetReceptiveField(); for (size_t i = 0; i < dilations.size(); i++) { this->_layer_buffers.push_back(Eigen::MatrixXf(channels, LAYER_ARRAY_BUFFER_SIZE + receptiveField - 1)); this->_layer_buffers[i].setZero(); } - this->_buffer_start = this->_get_receptive_field() - 1; + this->_buffer_start = this->GetReceptiveField() - 1; } void nam::wavenet::LayerArray::advance_buffers_(const int numFrames) @@ -131,11 +131,11 @@ void nam::wavenet::LayerArray::SetNumFrames(const long numFrames) { // Wavenet checks for unchanged numFrames; if we made it here, there's // something to do. - if (LAYER_ARRAY_BUFFER_SIZE - numFrames < this->_get_receptive_field()) + if (LAYER_ARRAY_BUFFER_SIZE - numFrames < this->GetReceptiveField()) { std::stringstream ss; ss << "Asked to accept a buffer of " << numFrames << " samples, but the buffer is too short (" - << LAYER_ARRAY_BUFFER_SIZE << ") to get out of the recptive field (" << this->_get_receptive_field() + << LAYER_ARRAY_BUFFER_SIZE << ") to get out of the recptive field (" << this->GetReceptiveField() << "); copy errors could occur!\n"; throw std::runtime_error(ss.str().c_str()); } @@ -156,7 +156,7 @@ long nam::wavenet::LayerArray::_get_channels() const return this->_layers.size() > 0 ? this->_layers[0].get_channels() : 0; } -long nam::wavenet::LayerArray::_get_receptive_field() const +long nam::wavenet::LayerArray::GetReceptiveField() const { // TODO remove this and use get_receptive_field() instead! long res = 1; @@ -169,7 +169,7 @@ void nam::wavenet::LayerArray::RewindBuffers() // Consider wrapping instead... // Can make this smaller--largest dilation, not receptive field! { - const long start = this->_get_receptive_field() - 1; + const long start = this->GetReceptiveField() - 1; for (size_t i = 0; i < this->_layer_buffers.size(); i++) { const long d = (this->_layers[i].GetKernelSize() - 1) * this->_layers[i].GetDilation(); diff --git a/NAM/wavenet.h b/NAM/wavenet.h index 1eca242..04b2cd7 100644 --- a/NAM/wavenet.h +++ b/NAM/wavenet.h @@ -134,7 +134,7 @@ class LayerArray // "One-indexed" receptive field // TODO remove! // E.g. a 1x1 convolution has a o.i.r.f. of one. - long _get_receptive_field() const; + long GetReceptiveField() const; void RewindBuffers(); }; From ce394f87a72c6c1fb6addff1d7102aeb18b1d515 Mon Sep 17 00:00:00 2001 From: Oli Larkin Date: Sat, 20 Jan 2024 00:49:14 +0100 Subject: [PATCH 097/133] _get_channels --- NAM/wavenet.cpp | 2 +- NAM/wavenet.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/NAM/wavenet.cpp b/NAM/wavenet.cpp index bc5c12f..75dcbbf 100644 --- a/NAM/wavenet.cpp +++ b/NAM/wavenet.cpp @@ -151,7 +151,7 @@ void nam::wavenet::LayerArray::SetWeights(weights_it& weights) this->_head_rechannel.SetWeights(weights); } -long nam::wavenet::LayerArray::_get_channels() const +long nam::wavenet::LayerArray::GetChannels() const { return this->_layers.size() > 0 ? this->_layers[0].get_channels() : 0; } diff --git a/NAM/wavenet.h b/NAM/wavenet.h index 04b2cd7..ec022d1 100644 --- a/NAM/wavenet.h +++ b/NAM/wavenet.h @@ -130,7 +130,7 @@ class LayerArray Conv1x1 _head_rechannel; long _get_buffer_size() const { return this->_layer_buffers.size() > 0 ? this->_layer_buffers[0].cols() : 0; }; - long _get_channels() const; + long GetChannels() const; // "One-indexed" receptive field // TODO remove! // E.g. a 1x1 convolution has a o.i.r.f. of one. From 78df9916386eb3cb9f7e9cc351be800b429bde35 Mon Sep 17 00:00:00 2001 From: Oli Larkin Date: Sat, 20 Jan 2024 00:49:31 +0100 Subject: [PATCH 098/133] GetBufferSize --- NAM/wavenet.cpp | 2 +- NAM/wavenet.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/NAM/wavenet.cpp b/NAM/wavenet.cpp index 75dcbbf..265bd6e 100644 --- a/NAM/wavenet.cpp +++ b/NAM/wavenet.cpp @@ -98,7 +98,7 @@ void nam::wavenet::LayerArray::prepare_for_frames_(const long numFrames) // -> this will write on indices 0 through 63, inclusive. // -> No illegal writes. // -> no rewind needed. - if (this->_buffer_start + numFrames > this->_get_buffer_size()) + if (this->_buffer_start + numFrames > this->GetBufferSize()) this->RewindBuffers(); } diff --git a/NAM/wavenet.h b/NAM/wavenet.h index ec022d1..4dbb307 100644 --- a/NAM/wavenet.h +++ b/NAM/wavenet.h @@ -129,7 +129,7 @@ class LayerArray // Rechannel for the head Conv1x1 _head_rechannel; - long _get_buffer_size() const { return this->_layer_buffers.size() > 0 ? this->_layer_buffers[0].cols() : 0; }; + long GetBufferSize() const { return this->_layer_buffers.size() > 0 ? this->_layer_buffers[0].cols() : 0; }; long GetChannels() const; // "One-indexed" receptive field // TODO remove! From 20ff7ef851dcd2955bcdf81c1c12830bd4fcd23d Mon Sep 17 00:00:00 2001 From: Oli Larkin Date: Sat, 20 Jan 2024 00:49:54 +0100 Subject: [PATCH 099/133] _layer_buffers --- NAM/wavenet.cpp | 16 ++++++++-------- NAM/wavenet.h | 4 ++-- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/NAM/wavenet.cpp b/NAM/wavenet.cpp index 265bd6e..a9c17d7 100644 --- a/NAM/wavenet.cpp +++ b/NAM/wavenet.cpp @@ -70,8 +70,8 @@ nam::wavenet::LayerArray::LayerArray(const int inputSize, const int condition_si const long receptiveField = this->GetReceptiveField(); for (size_t i = 0; i < dilations.size(); i++) { - this->_layer_buffers.push_back(Eigen::MatrixXf(channels, LAYER_ARRAY_BUFFER_SIZE + receptiveField - 1)); - this->_layer_buffers[i].setZero(); + this->mLayerBuffers.push_back(Eigen::MatrixXf(channels, LAYER_ARRAY_BUFFER_SIZE + receptiveField - 1)); + this->mLayerBuffers[i].setZero(); } this->_buffer_start = this->GetReceptiveField() - 1; } @@ -106,20 +106,20 @@ void nam::wavenet::LayerArray::Process(const Eigen::Ref l Eigen::Ref head_inputs, Eigen::Ref layer_outputs, Eigen::Ref head_outputs) { - this->_layer_buffers[0].middleCols(this->_buffer_start, layer_inputs.cols()) = this->_rechannel.Process(layer_inputs); + this->mLayerBuffers[0].middleCols(this->_buffer_start, layer_inputs.cols()) = this->_rechannel.Process(layer_inputs); const size_t last_layer = this->_layers.size() - 1; for (size_t i = 0; i < this->_layers.size(); i++) { if (i == last_layer) { - this->_layers[i].Process(this->_layer_buffers[i], condition, head_inputs, + this->_layers[i].Process(this->mLayerBuffers[i], condition, head_inputs, layer_outputs, this->_buffer_start, 0); } else { - this->_layers[i].Process(this->_layer_buffers[i], condition, head_inputs, - this->_layer_buffers[i + 1], this->_buffer_start, + this->_layers[i].Process(this->mLayerBuffers[i], condition, head_inputs, + this->mLayerBuffers[i + 1], this->_buffer_start, this->_buffer_start); } @@ -170,10 +170,10 @@ void nam::wavenet::LayerArray::RewindBuffers() // Can make this smaller--largest dilation, not receptive field! { const long start = this->GetReceptiveField() - 1; - for (size_t i = 0; i < this->_layer_buffers.size(); i++) + for (size_t i = 0; i < this->mLayerBuffers.size(); i++) { const long d = (this->_layers[i].GetKernelSize() - 1) * this->_layers[i].GetDilation(); - this->_layer_buffers[i].middleCols(start - d, d) = this->_layer_buffers[i].middleCols(this->_buffer_start - d, d); + this->mLayerBuffers[i].middleCols(start - d, d) = this->mLayerBuffers[i].middleCols(this->_buffer_start - d, d); } this->_buffer_start = start; } diff --git a/NAM/wavenet.h b/NAM/wavenet.h index 4dbb307..f582985 100644 --- a/NAM/wavenet.h +++ b/NAM/wavenet.h @@ -122,14 +122,14 @@ class LayerArray // Buffers in between layers. // buffer [i] is the input to layer [i]. // the last layer outputs to a short array provided by outside. - std::vector _layer_buffers; + std::vector mLayerBuffers; // The layer objects std::vector<_Layer> _layers; // Rechannel for the head Conv1x1 _head_rechannel; - long GetBufferSize() const { return this->_layer_buffers.size() > 0 ? this->_layer_buffers[0].cols() : 0; }; + long GetBufferSize() const { return this->mLayerBuffers.size() > 0 ? this->mLayerBuffers[0].cols() : 0; }; long GetChannels() const; // "One-indexed" receptive field // TODO remove! From f4188b72d15d9218a3edb30c2291be947153d27f Mon Sep 17 00:00:00 2001 From: Oli Larkin Date: Sat, 20 Jan 2024 00:50:17 +0100 Subject: [PATCH 100/133] _head_rechannel --- NAM/wavenet.cpp | 6 +++--- NAM/wavenet.h | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/NAM/wavenet.cpp b/NAM/wavenet.cpp index a9c17d7..f200db9 100644 --- a/NAM/wavenet.cpp +++ b/NAM/wavenet.cpp @@ -63,7 +63,7 @@ nam::wavenet::LayerArray::LayerArray(const int inputSize, const int condition_si const int channels, const int kernelSize, const std::vector& dilations, const std::string activation, const bool gated, const bool head_bias) : _rechannel(inputSize, channels, false) -, _head_rechannel(channels, head_size, head_bias) +, mHeadRechannel(channels, head_size, head_bias) { for (size_t i = 0; i < dilations.size(); i++) this->_layers.push_back(_Layer(condition_size, channels, kernelSize, dilations[i], activation, gated)); @@ -124,7 +124,7 @@ void nam::wavenet::LayerArray::Process(const Eigen::Ref l } } - head_outputs = this->_head_rechannel.Process(head_inputs); + head_outputs = this->mHeadRechannel.Process(head_inputs); } void nam::wavenet::LayerArray::SetNumFrames(const long numFrames) @@ -148,7 +148,7 @@ void nam::wavenet::LayerArray::SetWeights(weights_it& weights) this->_rechannel.SetWeights(weights); for (size_t i = 0; i < this->_layers.size(); i++) this->_layers[i].SetWeights(weights); - this->_head_rechannel.SetWeights(weights); + this->mHeadRechannel.SetWeights(weights); } long nam::wavenet::LayerArray::GetChannels() const diff --git a/NAM/wavenet.h b/NAM/wavenet.h index f582985..a103453 100644 --- a/NAM/wavenet.h +++ b/NAM/wavenet.h @@ -127,7 +127,7 @@ class LayerArray std::vector<_Layer> _layers; // Rechannel for the head - Conv1x1 _head_rechannel; + Conv1x1 mHeadRechannel; long GetBufferSize() const { return this->mLayerBuffers.size() > 0 ? this->mLayerBuffers[0].cols() : 0; }; long GetChannels() const; From bc5cc640874c09e390d8ab291ab9f56566b254cf Mon Sep 17 00:00:00 2001 From: Oli Larkin Date: Sat, 20 Jan 2024 00:50:31 +0100 Subject: [PATCH 101/133] _layers --- NAM/wavenet.cpp | 30 +++++++++++++++--------------- NAM/wavenet.h | 2 +- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/NAM/wavenet.cpp b/NAM/wavenet.cpp index f200db9..5377be4 100644 --- a/NAM/wavenet.cpp +++ b/NAM/wavenet.cpp @@ -66,7 +66,7 @@ nam::wavenet::LayerArray::LayerArray(const int inputSize, const int condition_si , mHeadRechannel(channels, head_size, head_bias) { for (size_t i = 0; i < dilations.size(); i++) - this->_layers.push_back(_Layer(condition_size, channels, kernelSize, dilations[i], activation, gated)); + this->mLayers.push_back(_Layer(condition_size, channels, kernelSize, dilations[i], activation, gated)); const long receptiveField = this->GetReceptiveField(); for (size_t i = 0; i < dilations.size(); i++) { @@ -84,8 +84,8 @@ void nam::wavenet::LayerArray::advance_buffers_(const int numFrames) long nam::wavenet::LayerArray::get_receptive_field() const { long result = 0; - for (size_t i = 0; i < this->_layers.size(); i++) - result += this->_layers[i].GetDilation() * (this->_layers[i].GetKernelSize() - 1); + for (size_t i = 0; i < this->mLayers.size(); i++) + result += this->mLayers[i].GetDilation() * (this->mLayers[i].GetKernelSize() - 1); return result; } @@ -107,18 +107,18 @@ void nam::wavenet::LayerArray::Process(const Eigen::Ref l Eigen::Ref head_outputs) { this->mLayerBuffers[0].middleCols(this->_buffer_start, layer_inputs.cols()) = this->_rechannel.Process(layer_inputs); - const size_t last_layer = this->_layers.size() - 1; - for (size_t i = 0; i < this->_layers.size(); i++) + const size_t last_layer = this->mLayers.size() - 1; + for (size_t i = 0; i < this->mLayers.size(); i++) { if (i == last_layer) { - this->_layers[i].Process(this->mLayerBuffers[i], condition, head_inputs, + this->mLayers[i].Process(this->mLayerBuffers[i], condition, head_inputs, layer_outputs, this->_buffer_start, 0); } else { - this->_layers[i].Process(this->mLayerBuffers[i], condition, head_inputs, + this->mLayers[i].Process(this->mLayerBuffers[i], condition, head_inputs, this->mLayerBuffers[i + 1], this->_buffer_start, this->_buffer_start); } @@ -139,29 +139,29 @@ void nam::wavenet::LayerArray::SetNumFrames(const long numFrames) << "); copy errors could occur!\n"; throw std::runtime_error(ss.str().c_str()); } - for (size_t i = 0; i < this->_layers.size(); i++) - this->_layers[i].SetNumFrames(numFrames); + for (size_t i = 0; i < this->mLayers.size(); i++) + this->mLayers[i].SetNumFrames(numFrames); } void nam::wavenet::LayerArray::SetWeights(weights_it& weights) { this->_rechannel.SetWeights(weights); - for (size_t i = 0; i < this->_layers.size(); i++) - this->_layers[i].SetWeights(weights); + for (size_t i = 0; i < this->mLayers.size(); i++) + this->mLayers[i].SetWeights(weights); this->mHeadRechannel.SetWeights(weights); } long nam::wavenet::LayerArray::GetChannels() const { - return this->_layers.size() > 0 ? this->_layers[0].get_channels() : 0; + return this->mLayers.size() > 0 ? this->mLayers[0].get_channels() : 0; } long nam::wavenet::LayerArray::GetReceptiveField() const { // TODO remove this and use get_receptive_field() instead! long res = 1; - for (size_t i = 0; i < this->_layers.size(); i++) - res += (this->_layers[i].GetKernelSize() - 1) * this->_layers[i].GetDilation(); + for (size_t i = 0; i < this->mLayers.size(); i++) + res += (this->mLayers[i].GetKernelSize() - 1) * this->mLayers[i].GetDilation(); return res; } @@ -172,7 +172,7 @@ void nam::wavenet::LayerArray::RewindBuffers() const long start = this->GetReceptiveField() - 1; for (size_t i = 0; i < this->mLayerBuffers.size(); i++) { - const long d = (this->_layers[i].GetKernelSize() - 1) * this->_layers[i].GetDilation(); + const long d = (this->mLayers[i].GetKernelSize() - 1) * this->mLayers[i].GetDilation(); this->mLayerBuffers[i].middleCols(start - d, d) = this->mLayerBuffers[i].middleCols(this->_buffer_start - d, d); } this->_buffer_start = start; diff --git a/NAM/wavenet.h b/NAM/wavenet.h index a103453..ce2a618 100644 --- a/NAM/wavenet.h +++ b/NAM/wavenet.h @@ -124,7 +124,7 @@ class LayerArray // the last layer outputs to a short array provided by outside. std::vector mLayerBuffers; // The layer objects - std::vector<_Layer> _layers; + std::vector<_Layer> mLayers; // Rechannel for the head Conv1x1 mHeadRechannel; From 692847e5c231b95f1e7d693f533e5dd76e809629 Mon Sep 17 00:00:00 2001 From: Oli Larkin Date: Sat, 20 Jan 2024 00:51:36 +0100 Subject: [PATCH 102/133] Layer --- NAM/wavenet.cpp | 8 ++++---- NAM/wavenet.h | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/NAM/wavenet.cpp b/NAM/wavenet.cpp index 5377be4..3fb7c2c 100644 --- a/NAM/wavenet.cpp +++ b/NAM/wavenet.cpp @@ -12,14 +12,14 @@ nam::wavenet::_DilatedConv::_DilatedConv(const int inChannels, const int outChan this->SetSize(inChannels, outChannels, kernelSize, bias, dilation); } -void nam::wavenet::_Layer::SetWeights(weights_it& weights) +void nam::wavenet::Layer::SetWeights(weights_it& weights) { this->_conv.SetWeights(weights); this->_input_mixin.SetWeights(weights); this->_1x1.SetWeights(weights); } -void nam::wavenet::_Layer::Process(const Eigen::Ref input, const Eigen::Ref condition, +void nam::wavenet::Layer::Process(const Eigen::Ref input, const Eigen::Ref condition, Eigen::Ref head_input, Eigen::Ref output, const long i_start, const long j_start) { @@ -46,7 +46,7 @@ void nam::wavenet::_Layer::Process(const Eigen::Ref input output.middleCols(j_start, ncols) = input.middleCols(i_start, ncols) + this->_1x1.Process(this->_z.topRows(channels)); } -void nam::wavenet::_Layer::SetNumFrames(const long numFrames) +void nam::wavenet::Layer::SetNumFrames(const long numFrames) { if (this->_z.rows() == this->_conv.GetOutChannels() && this->_z.cols() == numFrames) return; // Already has correct size @@ -66,7 +66,7 @@ nam::wavenet::LayerArray::LayerArray(const int inputSize, const int condition_si , mHeadRechannel(channels, head_size, head_bias) { for (size_t i = 0; i < dilations.size(); i++) - this->mLayers.push_back(_Layer(condition_size, channels, kernelSize, dilations[i], activation, gated)); + this->mLayers.push_back(Layer(condition_size, channels, kernelSize, dilations[i], activation, gated)); const long receptiveField = this->GetReceptiveField(); for (size_t i = 0; i < dilations.size(); i++) { diff --git a/NAM/wavenet.h b/NAM/wavenet.h index ce2a618..72dbbf5 100644 --- a/NAM/wavenet.h +++ b/NAM/wavenet.h @@ -20,10 +20,10 @@ class _DilatedConv : public Conv1D const int dilation); }; -class _Layer +class Layer { public: - _Layer(const int condition_size, const int channels, const int kernelSize, const int dilation, + Layer(const int condition_size, const int channels, const int kernelSize, const int dilation, const std::string activation, const bool gated) : _conv(channels, gated ? 2 * channels : channels, kernelSize, true, dilation) , _input_mixin(condition_size, gated ? 2 * channels : channels, false) @@ -124,7 +124,7 @@ class LayerArray // the last layer outputs to a short array provided by outside. std::vector mLayerBuffers; // The layer objects - std::vector<_Layer> mLayers; + std::vector mLayers; // Rechannel for the head Conv1x1 mHeadRechannel; From 628f1ba903c89589a7b7f42e67e561bfe19eecbf Mon Sep 17 00:00:00 2001 From: Oli Larkin Date: Sat, 20 Jan 2024 00:51:46 +0100 Subject: [PATCH 103/133] mReChannel --- NAM/wavenet.cpp | 6 +++--- NAM/wavenet.h | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/NAM/wavenet.cpp b/NAM/wavenet.cpp index 3fb7c2c..c63b618 100644 --- a/NAM/wavenet.cpp +++ b/NAM/wavenet.cpp @@ -62,7 +62,7 @@ void nam::wavenet::Layer::SetNumFrames(const long numFrames) nam::wavenet::LayerArray::LayerArray(const int inputSize, const int condition_size, const int head_size, const int channels, const int kernelSize, const std::vector& dilations, const std::string activation, const bool gated, const bool head_bias) -: _rechannel(inputSize, channels, false) +: mReChannel(inputSize, channels, false) , mHeadRechannel(channels, head_size, head_bias) { for (size_t i = 0; i < dilations.size(); i++) @@ -106,7 +106,7 @@ void nam::wavenet::LayerArray::Process(const Eigen::Ref l Eigen::Ref head_inputs, Eigen::Ref layer_outputs, Eigen::Ref head_outputs) { - this->mLayerBuffers[0].middleCols(this->_buffer_start, layer_inputs.cols()) = this->_rechannel.Process(layer_inputs); + this->mLayerBuffers[0].middleCols(this->_buffer_start, layer_inputs.cols()) = this->mReChannel.Process(layer_inputs); const size_t last_layer = this->mLayers.size() - 1; for (size_t i = 0; i < this->mLayers.size(); i++) { @@ -145,7 +145,7 @@ void nam::wavenet::LayerArray::SetNumFrames(const long numFrames) void nam::wavenet::LayerArray::SetWeights(weights_it& weights) { - this->_rechannel.SetWeights(weights); + this->mReChannel.SetWeights(weights); for (size_t i = 0; i < this->mLayers.size(); i++) this->mLayers[i].SetWeights(weights); this->mHeadRechannel.SetWeights(weights); diff --git a/NAM/wavenet.h b/NAM/wavenet.h index 72dbbf5..3f25b9a 100644 --- a/NAM/wavenet.h +++ b/NAM/wavenet.h @@ -117,7 +117,7 @@ class LayerArray private: long _buffer_start; // The rechannel before the layers - Conv1x1 _rechannel; + Conv1x1 mReChannel; // Buffers in between layers. // buffer [i] is the input to layer [i]. From 0e6018e05be6770bc9b415f5ac634f74c00611d9 Mon Sep 17 00:00:00 2001 From: Oli Larkin Date: Sat, 20 Jan 2024 00:52:06 +0100 Subject: [PATCH 104/133] mBufferStart --- NAM/wavenet.cpp | 18 +++++++++--------- NAM/wavenet.h | 2 +- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/NAM/wavenet.cpp b/NAM/wavenet.cpp index c63b618..b869069 100644 --- a/NAM/wavenet.cpp +++ b/NAM/wavenet.cpp @@ -73,12 +73,12 @@ nam::wavenet::LayerArray::LayerArray(const int inputSize, const int condition_si this->mLayerBuffers.push_back(Eigen::MatrixXf(channels, LAYER_ARRAY_BUFFER_SIZE + receptiveField - 1)); this->mLayerBuffers[i].setZero(); } - this->_buffer_start = this->GetReceptiveField() - 1; + this->mBufferStart = this->GetReceptiveField() - 1; } void nam::wavenet::LayerArray::advance_buffers_(const int numFrames) { - this->_buffer_start += numFrames; + this->mBufferStart += numFrames; } long nam::wavenet::LayerArray::get_receptive_field() const @@ -98,7 +98,7 @@ void nam::wavenet::LayerArray::prepare_for_frames_(const long numFrames) // -> this will write on indices 0 through 63, inclusive. // -> No illegal writes. // -> no rewind needed. - if (this->_buffer_start + numFrames > this->GetBufferSize()) + if (this->mBufferStart + numFrames > this->GetBufferSize()) this->RewindBuffers(); } @@ -106,21 +106,21 @@ void nam::wavenet::LayerArray::Process(const Eigen::Ref l Eigen::Ref head_inputs, Eigen::Ref layer_outputs, Eigen::Ref head_outputs) { - this->mLayerBuffers[0].middleCols(this->_buffer_start, layer_inputs.cols()) = this->mReChannel.Process(layer_inputs); + this->mLayerBuffers[0].middleCols(this->mBufferStart, layer_inputs.cols()) = this->mReChannel.Process(layer_inputs); const size_t last_layer = this->mLayers.size() - 1; for (size_t i = 0; i < this->mLayers.size(); i++) { if (i == last_layer) { this->mLayers[i].Process(this->mLayerBuffers[i], condition, head_inputs, - layer_outputs, this->_buffer_start, + layer_outputs, this->mBufferStart, 0); } else { this->mLayers[i].Process(this->mLayerBuffers[i], condition, head_inputs, - this->mLayerBuffers[i + 1], this->_buffer_start, - this->_buffer_start); + this->mLayerBuffers[i + 1], this->mBufferStart, + this->mBufferStart); } } @@ -173,9 +173,9 @@ void nam::wavenet::LayerArray::RewindBuffers() for (size_t i = 0; i < this->mLayerBuffers.size(); i++) { const long d = (this->mLayers[i].GetKernelSize() - 1) * this->mLayers[i].GetDilation(); - this->mLayerBuffers[i].middleCols(start - d, d) = this->mLayerBuffers[i].middleCols(this->_buffer_start - d, d); + this->mLayerBuffers[i].middleCols(start - d, d) = this->mLayerBuffers[i].middleCols(this->mBufferStart - d, d); } - this->_buffer_start = start; + this->mBufferStart = start; } // Head ======================================================================= diff --git a/NAM/wavenet.h b/NAM/wavenet.h index 3f25b9a..00c65bd 100644 --- a/NAM/wavenet.h +++ b/NAM/wavenet.h @@ -115,7 +115,7 @@ class LayerArray long get_receptive_field() const; private: - long _buffer_start; + long mBufferStart; // The rechannel before the layers Conv1x1 mReChannel; From 863fa4c693b1f936b474eee527f7b9a8b4ff1be2 Mon Sep 17 00:00:00 2001 From: Oli Larkin Date: Sat, 20 Jan 2024 00:52:22 +0100 Subject: [PATCH 105/133] get_receptive_field --- NAM/wavenet.cpp | 6 +++--- NAM/wavenet.h | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/NAM/wavenet.cpp b/NAM/wavenet.cpp index b869069..fc7b6bc 100644 --- a/NAM/wavenet.cpp +++ b/NAM/wavenet.cpp @@ -81,7 +81,7 @@ void nam::wavenet::LayerArray::advance_buffers_(const int numFrames) this->mBufferStart += numFrames; } -long nam::wavenet::LayerArray::get_receptive_field() const +long nam::wavenet::LayerArray::GetReceptiveField() const { long result = 0; for (size_t i = 0; i < this->mLayers.size(); i++) @@ -158,7 +158,7 @@ long nam::wavenet::LayerArray::GetChannels() const long nam::wavenet::LayerArray::GetReceptiveField() const { - // TODO remove this and use get_receptive_field() instead! + // TODO remove this and use GetReceptiveField() instead! long res = 1; for (size_t i = 0; i < this->mLayers.size(); i++) res += (this->mLayers[i].GetKernelSize() - 1) * this->mLayers[i].GetDilation(); @@ -273,7 +273,7 @@ nam::wavenet::WaveNet::WaveNet(const std::vector mPrewarmSamples = 1; for (size_t i = 0; i < this->mLayerArrays.size(); i++) - mPrewarmSamples += this->mLayerArrays[i].get_receptive_field(); + mPrewarmSamples += this->mLayerArrays[i].GetReceptiveField(); } void nam::wavenet::WaveNet::Finalize(const int numFrames) diff --git a/NAM/wavenet.h b/NAM/wavenet.h index 00c65bd..c930571 100644 --- a/NAM/wavenet.h +++ b/NAM/wavenet.h @@ -112,7 +112,7 @@ class LayerArray // "Zero-indexed" receptive field. // E.g. a 1x1 convolution has a z.i.r.f. of zero. - long get_receptive_field() const; + long GetReceptiveField() const; private: long mBufferStart; From f4b91f14585b07dcfee9128e48a565652decc7e6 Mon Sep 17 00:00:00 2001 From: Oli Larkin Date: Sat, 20 Jan 2024 00:52:46 +0100 Subject: [PATCH 106/133] headOuputs --- NAM/wavenet.cpp | 4 ++-- NAM/wavenet.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/NAM/wavenet.cpp b/NAM/wavenet.cpp index fc7b6bc..94ca3d1 100644 --- a/NAM/wavenet.cpp +++ b/NAM/wavenet.cpp @@ -104,7 +104,7 @@ void nam::wavenet::LayerArray::prepare_for_frames_(const long numFrames) void nam::wavenet::LayerArray::Process(const Eigen::Ref layer_inputs, const Eigen::Ref condition, Eigen::Ref head_inputs, Eigen::Ref layer_outputs, - Eigen::Ref head_outputs) + Eigen::Ref headOutputs) { this->mLayerBuffers[0].middleCols(this->mBufferStart, layer_inputs.cols()) = this->mReChannel.Process(layer_inputs); const size_t last_layer = this->mLayers.size() - 1; @@ -124,7 +124,7 @@ void nam::wavenet::LayerArray::Process(const Eigen::Ref l } } - head_outputs = this->mHeadRechannel.Process(head_inputs); + headOutputs = this->mHeadRechannel.Process(head_inputs); } void nam::wavenet::LayerArray::SetNumFrames(const long numFrames) diff --git a/NAM/wavenet.h b/NAM/wavenet.h index c930571..e3276af 100644 --- a/NAM/wavenet.h +++ b/NAM/wavenet.h @@ -105,7 +105,7 @@ class LayerArray const Eigen::Ref condition, // Short Eigen::Ref layer_outputs, // Short Eigen::Ref head_inputs, // Sum up on this. - Eigen::Ref head_outputs // post head-rechannel + Eigen::Ref headOutputs // post head-rechannel ); void SetNumFrames(const long numFrames); void SetWeights(weights_it& it); From 1bceb170b9be6ae6ee4d1aad53d8f026c48a74ba Mon Sep 17 00:00:00 2001 From: Oli Larkin Date: Sat, 20 Jan 2024 00:53:02 +0100 Subject: [PATCH 107/133] headInputs --- NAM/wavenet.cpp | 8 ++++---- NAM/wavenet.h | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/NAM/wavenet.cpp b/NAM/wavenet.cpp index 94ca3d1..d4da6ca 100644 --- a/NAM/wavenet.cpp +++ b/NAM/wavenet.cpp @@ -103,7 +103,7 @@ void nam::wavenet::LayerArray::prepare_for_frames_(const long numFrames) } void nam::wavenet::LayerArray::Process(const Eigen::Ref layer_inputs, const Eigen::Ref condition, - Eigen::Ref head_inputs, Eigen::Ref layer_outputs, + Eigen::Ref headInputs, Eigen::Ref layer_outputs, Eigen::Ref headOutputs) { this->mLayerBuffers[0].middleCols(this->mBufferStart, layer_inputs.cols()) = this->mReChannel.Process(layer_inputs); @@ -112,19 +112,19 @@ void nam::wavenet::LayerArray::Process(const Eigen::Ref l { if (i == last_layer) { - this->mLayers[i].Process(this->mLayerBuffers[i], condition, head_inputs, + this->mLayers[i].Process(this->mLayerBuffers[i], condition, headInputs, layer_outputs, this->mBufferStart, 0); } else { - this->mLayers[i].Process(this->mLayerBuffers[i], condition, head_inputs, + this->mLayers[i].Process(this->mLayerBuffers[i], condition, headInputs, this->mLayerBuffers[i + 1], this->mBufferStart, this->mBufferStart); } } - headOutputs = this->mHeadRechannel.Process(head_inputs); + headOutputs = this->mHeadRechannel.Process(headInputs); } void nam::wavenet::LayerArray::SetNumFrames(const long numFrames) diff --git a/NAM/wavenet.h b/NAM/wavenet.h index e3276af..7e9bca8 100644 --- a/NAM/wavenet.h +++ b/NAM/wavenet.h @@ -104,7 +104,7 @@ class LayerArray void Process(const Eigen::Ref layer_inputs, // Short const Eigen::Ref condition, // Short Eigen::Ref layer_outputs, // Short - Eigen::Ref head_inputs, // Sum up on this. + Eigen::Ref headInputs, // Sum up on this. Eigen::Ref headOutputs // post head-rechannel ); void SetNumFrames(const long numFrames); From 9c7cdddc9c34d2f5729e0fd833d93e3fc30255d0 Mon Sep 17 00:00:00 2001 From: Oli Larkin Date: Sat, 20 Jan 2024 00:53:17 +0100 Subject: [PATCH 108/133] layerOutputs --- NAM/wavenet.cpp | 4 ++-- NAM/wavenet.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/NAM/wavenet.cpp b/NAM/wavenet.cpp index d4da6ca..582d17e 100644 --- a/NAM/wavenet.cpp +++ b/NAM/wavenet.cpp @@ -103,7 +103,7 @@ void nam::wavenet::LayerArray::prepare_for_frames_(const long numFrames) } void nam::wavenet::LayerArray::Process(const Eigen::Ref layer_inputs, const Eigen::Ref condition, - Eigen::Ref headInputs, Eigen::Ref layer_outputs, + Eigen::Ref headInputs, Eigen::Ref layerOutputs, Eigen::Ref headOutputs) { this->mLayerBuffers[0].middleCols(this->mBufferStart, layer_inputs.cols()) = this->mReChannel.Process(layer_inputs); @@ -113,7 +113,7 @@ void nam::wavenet::LayerArray::Process(const Eigen::Ref l if (i == last_layer) { this->mLayers[i].Process(this->mLayerBuffers[i], condition, headInputs, - layer_outputs, this->mBufferStart, + layerOutputs, this->mBufferStart, 0); } else diff --git a/NAM/wavenet.h b/NAM/wavenet.h index 7e9bca8..0da5208 100644 --- a/NAM/wavenet.h +++ b/NAM/wavenet.h @@ -103,7 +103,7 @@ class LayerArray // All arrays are "short". void Process(const Eigen::Ref layer_inputs, // Short const Eigen::Ref condition, // Short - Eigen::Ref layer_outputs, // Short + Eigen::Ref layerOutputs, // Short Eigen::Ref headInputs, // Sum up on this. Eigen::Ref headOutputs // post head-rechannel ); From 5ac7329390289c3daed7f7eb63f357a7f75edd20 Mon Sep 17 00:00:00 2001 From: Oli Larkin Date: Sat, 20 Jan 2024 00:53:35 +0100 Subject: [PATCH 109/133] layer_inputs --- NAM/wavenet.cpp | 4 ++-- NAM/wavenet.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/NAM/wavenet.cpp b/NAM/wavenet.cpp index 582d17e..54319b3 100644 --- a/NAM/wavenet.cpp +++ b/NAM/wavenet.cpp @@ -102,11 +102,11 @@ void nam::wavenet::LayerArray::prepare_for_frames_(const long numFrames) this->RewindBuffers(); } -void nam::wavenet::LayerArray::Process(const Eigen::Ref layer_inputs, const Eigen::Ref condition, +void nam::wavenet::LayerArray::Process(const Eigen::Ref layerInputs, const Eigen::Ref condition, Eigen::Ref headInputs, Eigen::Ref layerOutputs, Eigen::Ref headOutputs) { - this->mLayerBuffers[0].middleCols(this->mBufferStart, layer_inputs.cols()) = this->mReChannel.Process(layer_inputs); + this->mLayerBuffers[0].middleCols(this->mBufferStart, layerInputs.cols()) = this->mReChannel.Process(layerInputs); const size_t last_layer = this->mLayers.size() - 1; for (size_t i = 0; i < this->mLayers.size(); i++) { diff --git a/NAM/wavenet.h b/NAM/wavenet.h index 0da5208..d1f626d 100644 --- a/NAM/wavenet.h +++ b/NAM/wavenet.h @@ -101,7 +101,7 @@ class LayerArray void prepare_for_frames_(const long numFrames); // All arrays are "short". - void Process(const Eigen::Ref layer_inputs, // Short + void Process(const Eigen::Ref layerInputs, // Short const Eigen::Ref condition, // Short Eigen::Ref layerOutputs, // Short Eigen::Ref headInputs, // Sum up on this. From f0899d9e7b1657fd758a8a89eec3b57caafec523 Mon Sep 17 00:00:00 2001 From: Oli Larkin Date: Sat, 20 Jan 2024 00:53:51 +0100 Subject: [PATCH 110/133] prepareForFrames --- NAM/wavenet.cpp | 4 ++-- NAM/wavenet.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/NAM/wavenet.cpp b/NAM/wavenet.cpp index 54319b3..fc4305e 100644 --- a/NAM/wavenet.cpp +++ b/NAM/wavenet.cpp @@ -89,7 +89,7 @@ long nam::wavenet::LayerArray::GetReceptiveField() const return result; } -void nam::wavenet::LayerArray::prepare_for_frames_(const long numFrames) +void nam::wavenet::LayerArray::PrepareForFrames(const long numFrames) { // Example: // _buffer_start = 0 @@ -312,7 +312,7 @@ void nam::wavenet::WaveNet::AdvanceBuffers(const int numFrames) void nam::wavenet::WaveNet::PrepareForFrames(const long numFrames) { for (size_t i = 0; i < this->mLayerArrays.size(); i++) - this->mLayerArrays[i].prepare_for_frames_(numFrames); + this->mLayerArrays[i].PrepareForFrames(numFrames); } void nam::wavenet::WaveNet::SetConditionArray(float* input, const int numFrames) diff --git a/NAM/wavenet.h b/NAM/wavenet.h index d1f626d..3a26416 100644 --- a/NAM/wavenet.h +++ b/NAM/wavenet.h @@ -98,7 +98,7 @@ class LayerArray // Rewind buffers if needed // Shift index to prepare // - void prepare_for_frames_(const long numFrames); + void PrepareForFrames(const long numFrames); // All arrays are "short". void Process(const Eigen::Ref layerInputs, // Short From a148e7a115b59e325c5fd19b271edd0eae55bade Mon Sep 17 00:00:00 2001 From: Oli Larkin Date: Sat, 20 Jan 2024 00:54:30 +0100 Subject: [PATCH 111/133] advance_buffers_ --- NAM/wavenet.cpp | 4 ++-- NAM/wavenet.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/NAM/wavenet.cpp b/NAM/wavenet.cpp index fc4305e..6ef9100 100644 --- a/NAM/wavenet.cpp +++ b/NAM/wavenet.cpp @@ -76,7 +76,7 @@ nam::wavenet::LayerArray::LayerArray(const int inputSize, const int condition_si this->mBufferStart = this->GetReceptiveField() - 1; } -void nam::wavenet::LayerArray::advance_buffers_(const int numFrames) +void nam::wavenet::LayerArray::AdvanceBuffers(const int numFrames) { this->mBufferStart += numFrames; } @@ -306,7 +306,7 @@ void nam::wavenet::WaveNet::SetWeights(const std::vector& weights) void nam::wavenet::WaveNet::AdvanceBuffers(const int numFrames) { for (size_t i = 0; i < this->mLayerArrays.size(); i++) - this->mLayerArrays[i].advance_buffers_(numFrames); + this->mLayerArrays[i].AdvanceBuffers(numFrames); } void nam::wavenet::WaveNet::PrepareForFrames(const long numFrames) diff --git a/NAM/wavenet.h b/NAM/wavenet.h index 3a26416..168e4db 100644 --- a/NAM/wavenet.h +++ b/NAM/wavenet.h @@ -92,7 +92,7 @@ class LayerArray const int kernelSize, const std::vector& dilations, const std::string activation, const bool gated, const bool head_bias); - void advance_buffers_(const int numFrames); + void AdvanceBuffers(const int numFrames); // Preparing for frames: // Rewind buffers if needed From 70bd3783cd33ae2212894390df2b69a36368b76e Mon Sep 17 00:00:00 2001 From: Oli Larkin Date: Sat, 20 Jan 2024 01:04:21 +0100 Subject: [PATCH 112/133] LayerArrayParams --- NAM/wavenet.cpp | 18 +++++++++--------- NAM/wavenet.h | 44 ++++++++++++++++++++++---------------------- 2 files changed, 31 insertions(+), 31 deletions(-) diff --git a/NAM/wavenet.cpp b/NAM/wavenet.cpp index 6ef9100..610184e 100644 --- a/NAM/wavenet.cpp +++ b/NAM/wavenet.cpp @@ -252,21 +252,21 @@ nam::wavenet::WaveNet::WaveNet(const std::vector for (size_t i = 0; i < layerArrayParams.size(); i++) { this->mLayerArrays.push_back(nam::wavenet::LayerArray( - layerArrayParams[i].inputSize, layerArrayParams[i].condition_size, layerArrayParams[i].head_size, - layerArrayParams[i].channels, layerArrayParams[i].kernelSize, layerArrayParams[i].dilations, - layerArrayParams[i].activation, layerArrayParams[i].gated, layerArrayParams[i].head_bias)); - this->mLayerArrayOutputs.push_back(Eigen::MatrixXf(layerArrayParams[i].channels, 0)); + layerArrayParams[i].mInputSize, layerArrayParams[i].mConditionSize, layerArrayParams[i].mHeadSize, + layerArrayParams[i].mChannels, layerArrayParams[i].mKernelSize, layerArrayParams[i].mDilations, + layerArrayParams[i].mActivation, layerArrayParams[i].mGated, layerArrayParams[i].mHeadBias)); + this->mLayerArrayOutputs.push_back(Eigen::MatrixXf(layerArrayParams[i].mChannels, 0)); if (i == 0) - this->mHeadArrays.push_back(Eigen::MatrixXf(layerArrayParams[i].channels, 0)); + this->mHeadArrays.push_back(Eigen::MatrixXf(layerArrayParams[i].mChannels, 0)); if (i > 0) - if (layerArrayParams[i].channels != layerArrayParams[i - 1].head_size) + if (layerArrayParams[i].mChannels != layerArrayParams[i - 1].mHeadSize) { std::stringstream ss; - ss << "channels of layer " << i << " (" << layerArrayParams[i].channels - << ") doesn't match head_size of preceding layer (" << layerArrayParams[i - 1].head_size << "!\n"; + ss << "channels of layer " << i << " (" << layerArrayParams[i].mChannels + << ") doesn't match head_size of preceding layer (" << layerArrayParams[i - 1].mHeadSize << "!\n"; throw std::runtime_error(ss.str().c_str()); } - this->mHeadArrays.push_back(Eigen::MatrixXf(layerArrayParams[i].head_size, 0)); + this->mHeadArrays.push_back(Eigen::MatrixXf(layerArrayParams[i].mHeadSize, 0)); } this->mHeadOutput.resize(1, 0); // Mono output! this->SetWeights(weights); diff --git a/NAM/wavenet.h b/NAM/wavenet.h index 168e4db..55cbada 100644 --- a/NAM/wavenet.h +++ b/NAM/wavenet.h @@ -57,31 +57,31 @@ class Layer class LayerArrayParams { public: - LayerArrayParams(const int input_size_, const int condition_size_, const int head_size_, const int channels_, - const int kernel_size_, const std::vector& dilations_, const std::string activation_, - const bool gated_, const bool head_bias_) - : inputSize(input_size_) - , condition_size(condition_size_) - , head_size(head_size_) - , channels(channels_) - , kernelSize(kernel_size_) - , activation(activation_) - , gated(gated_) - , head_bias(head_bias_) + LayerArrayParams(const int inputSize, const int conditionSize, const int headSize, const int channels, + const int kernelSize, const std::vector& dilations, const std::string activation, + const bool gated, const bool headBias) + : mInputSize(inputSize) + , mConditionSize(conditionSize) + , mHeadSize(headSize) + , mChannels(channels) + , mKernelSize(kernelSize) + , mActivation(activation) + , mGated(gated) + , mHeadBias(headBias) { - for (size_t i = 0; i < dilations_.size(); i++) - this->dilations.push_back(dilations_[i]); + for (size_t i = 0; i < dilations.size(); i++) + this->mDilations.push_back(dilations[i]); }; - const int inputSize; - const int condition_size; - const int head_size; - const int channels; - const int kernelSize; - std::vector dilations; - const std::string activation; - const bool gated; - const bool head_bias; + const int mInputSize; + const int mConditionSize; + const int mHeadSize; + const int mChannels; + const int mKernelSize; + std::vector mDilations; + const std::string mActivation; + const bool mGated; + const bool mHeadBias; }; // An array of layers with the same channels, kernel sizes, activations. From 018c7d14c3297cffe82718ab05aee8062af4ccb3 Mon Sep 17 00:00:00 2001 From: Oli Larkin Date: Sat, 20 Jan 2024 01:04:34 +0100 Subject: [PATCH 113/133] _GetReceptiveField duplicate?? TODO --- NAM/wavenet.cpp | 2 +- NAM/wavenet.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/NAM/wavenet.cpp b/NAM/wavenet.cpp index 610184e..68b9209 100644 --- a/NAM/wavenet.cpp +++ b/NAM/wavenet.cpp @@ -156,7 +156,7 @@ long nam::wavenet::LayerArray::GetChannels() const return this->mLayers.size() > 0 ? this->mLayers[0].get_channels() : 0; } -long nam::wavenet::LayerArray::GetReceptiveField() const +long nam::wavenet::LayerArray::_GetReceptiveField() const // TODO: why two? { // TODO remove this and use GetReceptiveField() instead! long res = 1; diff --git a/NAM/wavenet.h b/NAM/wavenet.h index 55cbada..6583b0c 100644 --- a/NAM/wavenet.h +++ b/NAM/wavenet.h @@ -134,7 +134,7 @@ class LayerArray // "One-indexed" receptive field // TODO remove! // E.g. a 1x1 convolution has a o.i.r.f. of one. - long GetReceptiveField() const; + long _GetReceptiveField() const; // TODO: why two! void RewindBuffers(); }; From fb3b52c907a454cc4a3d87a991064f7b2417a1e4 Mon Sep 17 00:00:00 2001 From: Oli Larkin Date: Sat, 20 Jan 2024 01:05:25 +0100 Subject: [PATCH 114/133] mGated --- NAM/wavenet.cpp | 2 +- NAM/wavenet.h | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/NAM/wavenet.cpp b/NAM/wavenet.cpp index 68b9209..44dd714 100644 --- a/NAM/wavenet.cpp +++ b/NAM/wavenet.cpp @@ -32,7 +32,7 @@ void nam::wavenet::Layer::Process(const Eigen::Ref input, this->_activation->Apply(this->_z); - if (this->_gated) + if (this->mGated) { activations::Activation::GetActivation("Sigmoid")->Apply(this->_z.block(channels, 0, channels, this->_z.cols())); diff --git a/NAM/wavenet.h b/NAM/wavenet.h index 6583b0c..696ced4 100644 --- a/NAM/wavenet.h +++ b/NAM/wavenet.h @@ -29,7 +29,7 @@ class Layer , _input_mixin(condition_size, gated ? 2 * channels : channels, false) , _1x1(channels, channels, true) , _activation(activations::Activation::GetActivation(activation)) - , _gated(gated){}; + , mGated(gated){}; void SetWeights(weights_it& weights); // :param `input`: from previous layer // :param `output`: to next layer @@ -51,7 +51,7 @@ class Layer Eigen::MatrixXf _z; activations::Activation* _activation; - const bool _gated; + const bool mGated; }; class LayerArrayParams From c04902c147813531e6e4e14eae72dc0e53fecfc2 Mon Sep 17 00:00:00 2001 From: Oli Larkin Date: Sat, 20 Jan 2024 01:05:42 +0100 Subject: [PATCH 115/133] mActivation --- NAM/wavenet.cpp | 2 +- NAM/wavenet.h | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/NAM/wavenet.cpp b/NAM/wavenet.cpp index 44dd714..4798186 100644 --- a/NAM/wavenet.cpp +++ b/NAM/wavenet.cpp @@ -30,7 +30,7 @@ void nam::wavenet::Layer::Process(const Eigen::Ref input, // Mix-in condition this->_z += this->_input_mixin.Process(condition); - this->_activation->Apply(this->_z); + this->mActivation->Apply(this->_z); if (this->mGated) { diff --git a/NAM/wavenet.h b/NAM/wavenet.h index 696ced4..b239f68 100644 --- a/NAM/wavenet.h +++ b/NAM/wavenet.h @@ -28,7 +28,7 @@ class Layer : _conv(channels, gated ? 2 * channels : channels, kernelSize, true, dilation) , _input_mixin(condition_size, gated ? 2 * channels : channels, false) , _1x1(channels, channels, true) - , _activation(activations::Activation::GetActivation(activation)) + , mActivation(activations::Activation::GetActivation(activation)) , mGated(gated){}; void SetWeights(weights_it& weights); // :param `input`: from previous layer @@ -50,7 +50,7 @@ class Layer // The internal state Eigen::MatrixXf _z; - activations::Activation* _activation; + activations::Activation* mActivation; const bool mGated; }; From 4b5c05b18ec5cfe9070a97f89691dfbe1c1579e6 Mon Sep 17 00:00:00 2001 From: Oli Larkin Date: Sat, 20 Jan 2024 01:06:00 +0100 Subject: [PATCH 116/133] mConv --- NAM/wavenet.cpp | 8 ++++---- NAM/wavenet.h | 10 +++++----- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/NAM/wavenet.cpp b/NAM/wavenet.cpp index 4798186..13ad690 100644 --- a/NAM/wavenet.cpp +++ b/NAM/wavenet.cpp @@ -14,7 +14,7 @@ nam::wavenet::_DilatedConv::_DilatedConv(const int inChannels, const int outChan void nam::wavenet::Layer::SetWeights(weights_it& weights) { - this->_conv.SetWeights(weights); + this->mConv.SetWeights(weights); this->_input_mixin.SetWeights(weights); this->_1x1.SetWeights(weights); } @@ -26,7 +26,7 @@ void nam::wavenet::Layer::Process(const Eigen::Ref input, const long ncols = condition.cols(); const long channels = this->get_channels(); // Input dilated conv - this->_conv.Process(input, this->_z, i_start, ncols, 0); + this->mConv.Process(input, this->_z, i_start, ncols, 0); // Mix-in condition this->_z += this->_input_mixin.Process(condition); @@ -48,10 +48,10 @@ void nam::wavenet::Layer::Process(const Eigen::Ref input, void nam::wavenet::Layer::SetNumFrames(const long numFrames) { - if (this->_z.rows() == this->_conv.GetOutChannels() && this->_z.cols() == numFrames) + if (this->_z.rows() == this->mConv.GetOutChannels() && this->_z.cols() == numFrames) return; // Already has correct size - this->_z.resize(this->_conv.GetOutChannels(), numFrames); + this->_z.resize(this->mConv.GetOutChannels(), numFrames); this->_z.setZero(); } diff --git a/NAM/wavenet.h b/NAM/wavenet.h index b239f68..542ee34 100644 --- a/NAM/wavenet.h +++ b/NAM/wavenet.h @@ -25,7 +25,7 @@ class Layer public: Layer(const int condition_size, const int channels, const int kernelSize, const int dilation, const std::string activation, const bool gated) - : _conv(channels, gated ? 2 * channels : channels, kernelSize, true, dilation) + : mConv(channels, gated ? 2 * channels : channels, kernelSize, true, dilation) , _input_mixin(condition_size, gated ? 2 * channels : channels, false) , _1x1(channels, channels, true) , mActivation(activations::Activation::GetActivation(activation)) @@ -36,13 +36,13 @@ class Layer void Process(const Eigen::Ref input, const Eigen::Ref condition, Eigen::Ref head_input, Eigen::Ref output, const long i_start, const long j_start); void SetNumFrames(const long numFrames); - long get_channels() const { return this->_conv.GetInChannels(); }; - int GetDilation() const { return this->_conv.GetDilation(); }; - long GetKernelSize() const { return this->_conv.GetKernelSize(); }; + long get_channels() const { return this->mConv.GetInChannels(); }; + int GetDilation() const { return this->mConv.GetDilation(); }; + long GetKernelSize() const { return this->mConv.GetKernelSize(); }; private: // The dilated convolution at the front of the block - _DilatedConv _conv; + _DilatedConv mConv; // Input mixin Conv1x1 _input_mixin; // The post-activation 1x1 convolution From ebb212cd21f49e9ebe128b8135e5dec1de6d9713 Mon Sep 17 00:00:00 2001 From: Oli Larkin Date: Sat, 20 Jan 2024 01:06:21 +0100 Subject: [PATCH 117/133] mInputMixin --- NAM/wavenet.cpp | 4 ++-- NAM/wavenet.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/NAM/wavenet.cpp b/NAM/wavenet.cpp index 13ad690..27bf4c7 100644 --- a/NAM/wavenet.cpp +++ b/NAM/wavenet.cpp @@ -15,7 +15,7 @@ nam::wavenet::_DilatedConv::_DilatedConv(const int inChannels, const int outChan void nam::wavenet::Layer::SetWeights(weights_it& weights) { this->mConv.SetWeights(weights); - this->_input_mixin.SetWeights(weights); + this->mInputMixin.SetWeights(weights); this->_1x1.SetWeights(weights); } @@ -28,7 +28,7 @@ void nam::wavenet::Layer::Process(const Eigen::Ref input, // Input dilated conv this->mConv.Process(input, this->_z, i_start, ncols, 0); // Mix-in condition - this->_z += this->_input_mixin.Process(condition); + this->_z += this->mInputMixin.Process(condition); this->mActivation->Apply(this->_z); diff --git a/NAM/wavenet.h b/NAM/wavenet.h index 542ee34..27a833d 100644 --- a/NAM/wavenet.h +++ b/NAM/wavenet.h @@ -26,7 +26,7 @@ class Layer Layer(const int condition_size, const int channels, const int kernelSize, const int dilation, const std::string activation, const bool gated) : mConv(channels, gated ? 2 * channels : channels, kernelSize, true, dilation) - , _input_mixin(condition_size, gated ? 2 * channels : channels, false) + , mInputMixin(condition_size, gated ? 2 * channels : channels, false) , _1x1(channels, channels, true) , mActivation(activations::Activation::GetActivation(activation)) , mGated(gated){}; @@ -44,7 +44,7 @@ class Layer // The dilated convolution at the front of the block _DilatedConv mConv; // Input mixin - Conv1x1 _input_mixin; + Conv1x1 mInputMixin; // The post-activation 1x1 convolution Conv1x1 _1x1; // The internal state From a0cfdeff44e7beaad9ccde95a74a5d4a146b0ed4 Mon Sep 17 00:00:00 2001 From: Oli Larkin Date: Sat, 20 Jan 2024 01:06:56 +0100 Subject: [PATCH 118/133] DilatedConv --- NAM/wavenet.cpp | 2 +- NAM/wavenet.h | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/NAM/wavenet.cpp b/NAM/wavenet.cpp index 27bf4c7..e8c06da 100644 --- a/NAM/wavenet.cpp +++ b/NAM/wavenet.cpp @@ -6,7 +6,7 @@ #include "wavenet.h" -nam::wavenet::_DilatedConv::_DilatedConv(const int inChannels, const int outChannels, const int kernelSize, +nam::wavenet::DilatedConv::DilatedConv(const int inChannels, const int outChannels, const int kernelSize, const int bias, const int dilation) { this->SetSize(inChannels, outChannels, kernelSize, bias, dilation); diff --git a/NAM/wavenet.h b/NAM/wavenet.h index 27a833d..a51158e 100644 --- a/NAM/wavenet.h +++ b/NAM/wavenet.h @@ -13,10 +13,10 @@ namespace nam namespace wavenet { // Rework the initialization API slightly. Merge w/ dsp.h later. -class _DilatedConv : public Conv1D +class DilatedConv : public Conv1D { public: - _DilatedConv(const int inChannels, const int outChannels, const int kernelSize, const int bias, + DilatedConv(const int inChannels, const int outChannels, const int kernelSize, const int bias, const int dilation); }; @@ -42,7 +42,7 @@ class Layer private: // The dilated convolution at the front of the block - _DilatedConv mConv; + DilatedConv mConv; // Input mixin Conv1x1 mInputMixin; // The post-activation 1x1 convolution From 7f94ff6bb64a383552bfb988e13fd11f160b91b2 Mon Sep 17 00:00:00 2001 From: Oli Larkin Date: Sat, 20 Jan 2024 01:07:27 +0100 Subject: [PATCH 119/133] getchannels --- NAM/wavenet.cpp | 4 ++-- NAM/wavenet.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/NAM/wavenet.cpp b/NAM/wavenet.cpp index e8c06da..4a80c5b 100644 --- a/NAM/wavenet.cpp +++ b/NAM/wavenet.cpp @@ -24,7 +24,7 @@ void nam::wavenet::Layer::Process(const Eigen::Ref input, const long j_start) { const long ncols = condition.cols(); - const long channels = this->get_channels(); + const long channels = this->GetChannels(); // Input dilated conv this->mConv.Process(input, this->_z, i_start, ncols, 0); // Mix-in condition @@ -153,7 +153,7 @@ void nam::wavenet::LayerArray::SetWeights(weights_it& weights) long nam::wavenet::LayerArray::GetChannels() const { - return this->mLayers.size() > 0 ? this->mLayers[0].get_channels() : 0; + return this->mLayers.size() > 0 ? this->mLayers[0].GetChannels() : 0; } long nam::wavenet::LayerArray::_GetReceptiveField() const // TODO: why two? diff --git a/NAM/wavenet.h b/NAM/wavenet.h index a51158e..afc9843 100644 --- a/NAM/wavenet.h +++ b/NAM/wavenet.h @@ -36,7 +36,7 @@ class Layer void Process(const Eigen::Ref input, const Eigen::Ref condition, Eigen::Ref head_input, Eigen::Ref output, const long i_start, const long j_start); void SetNumFrames(const long numFrames); - long get_channels() const { return this->mConv.GetInChannels(); }; + long GetChannels() const { return this->mConv.GetInChannels(); }; int GetDilation() const { return this->mConv.GetDilation(); }; long GetKernelSize() const { return this->mConv.GetKernelSize(); }; From 110bb40172763a85e86137c93b09cd27fdd99136 Mon Sep 17 00:00:00 2001 From: Oli Larkin Date: Sat, 20 Jan 2024 01:08:24 +0100 Subject: [PATCH 120/133] condition_size --- NAM/wavenet.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/NAM/wavenet.h b/NAM/wavenet.h index afc9843..a61a16b 100644 --- a/NAM/wavenet.h +++ b/NAM/wavenet.h @@ -23,10 +23,10 @@ class DilatedConv : public Conv1D class Layer { public: - Layer(const int condition_size, const int channels, const int kernelSize, const int dilation, + Layer(const int conditionSize, const int channels, const int kernelSize, const int dilation, const std::string activation, const bool gated) : mConv(channels, gated ? 2 * channels : channels, kernelSize, true, dilation) - , mInputMixin(condition_size, gated ? 2 * channels : channels, false) + , mInputMixin(conditionSize, gated ? 2 * channels : channels, false) , _1x1(channels, channels, true) , mActivation(activations::Activation::GetActivation(activation)) , mGated(gated){}; From 53107840a1a71403f5441535d782c6aa77db6f42 Mon Sep 17 00:00:00 2001 From: Oli Larkin Date: Sat, 20 Jan 2024 01:09:56 +0100 Subject: [PATCH 121/133] mActivation --- NAM/convnet.cpp | 4 ++-- NAM/convnet.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/NAM/convnet.cpp b/NAM/convnet.cpp index 4b52aee..9bc15ba 100644 --- a/NAM/convnet.cpp +++ b/NAM/convnet.cpp @@ -55,7 +55,7 @@ void nam::convnet::ConvNetBlock::SetWeights(const int inChannels, const int outC this->conv.SetSizeAndWeights(inChannels, outChannels, 2, dilation, !doBatchNorm, weights); if (this->mDoBatchNorm) this->mBatchnorm = BatchNorm(outChannels, weights); - this->activation = activations::Activation::GetActivation(activation); + this->mActivation = activations::Activation::GetActivation(activation); } void nam::convnet::ConvNetBlock::Process(const Eigen::Ref input, Eigen::Ref output, const long i_start, @@ -66,7 +66,7 @@ void nam::convnet::ConvNetBlock::Process(const Eigen::Ref if (this->mDoBatchNorm) this->mBatchnorm.Process(output, i_start, i_end); - this->activation->Apply(output.middleCols(i_start, ncols)); + this->mActivation->Apply(output.middleCols(i_start, ncols)); } long nam::convnet::ConvNetBlock::GetOutChannels() const diff --git a/NAM/convnet.h b/NAM/convnet.h index 175e2cc..effc701 100644 --- a/NAM/convnet.h +++ b/NAM/convnet.h @@ -49,7 +49,7 @@ class ConvNetBlock private: BatchNorm mBatchnorm; bool mDoBatchNorm = false; - activations::Activation* activation = nullptr; + activations::Activation* mActivation = nullptr; }; class Head From 7157123170f996480c823217f8307c6746b7f6f3 Mon Sep 17 00:00:00 2001 From: Oli Larkin Date: Sat, 20 Jan 2024 01:11:01 +0100 Subject: [PATCH 122/133] remove all instances of this-> --- NAM/convnet.cpp | 102 ++++++++++----------- NAM/dsp.cpp | 136 ++++++++++++++-------------- NAM/dsp.h | 14 +-- NAM/lstm.cpp | 72 +++++++-------- NAM/lstm.h | 6 +- NAM/wavenet.cpp | 230 ++++++++++++++++++++++++------------------------ NAM/wavenet.h | 10 +-- 7 files changed, 285 insertions(+), 285 deletions(-) diff --git a/NAM/convnet.cpp b/NAM/convnet.cpp index 9bc15ba..a9817df 100644 --- a/NAM/convnet.cpp +++ b/NAM/convnet.cpp @@ -28,11 +28,11 @@ nam::convnet::BatchNorm::BatchNorm(const int dim, weights_it& weights) float eps = *(weights++); // Convert to scale & loc - this->mScale.resize(dim); - this->mLoc.resize(dim); + mScale.resize(dim); + mLoc.resize(dim); for (int i = 0; i < dim; i++) - this->mScale(i) = weight(i) / sqrt(eps + running_var(i)); - this->mLoc = bias - this->mScale.cwiseProduct(running_mean); + mScale(i) = weight(i) / sqrt(eps + running_var(i)); + mLoc = bias - mScale.cwiseProduct(running_mean); } void nam::convnet::BatchNorm::Process(Eigen::Ref x, const long i_start, const long i_end) const @@ -41,8 +41,8 @@ void nam::convnet::BatchNorm::Process(Eigen::Ref x, const long // #speed but conv probably dominates for (auto i = i_start; i < i_end; i++) { - x.col(i) = x.col(i).cwiseProduct(this->mScale); - x.col(i) += this->mLoc; + x.col(i) = x.col(i).cwiseProduct(mScale); + x.col(i) += mLoc; } } @@ -50,36 +50,36 @@ void nam::convnet::ConvNetBlock::SetWeights(const int inChannels, const int outC const bool doBatchNorm, const std::string activation, weights_it& weights) { - this->mDoBatchNorm = doBatchNorm; + mDoBatchNorm = doBatchNorm; // HACK 2 kernel - this->conv.SetSizeAndWeights(inChannels, outChannels, 2, dilation, !doBatchNorm, weights); - if (this->mDoBatchNorm) - this->mBatchnorm = BatchNorm(outChannels, weights); - this->mActivation = activations::Activation::GetActivation(activation); + conv.SetSizeAndWeights(inChannels, outChannels, 2, dilation, !doBatchNorm, weights); + if (mDoBatchNorm) + mBatchnorm = BatchNorm(outChannels, weights); + mActivation = activations::Activation::GetActivation(activation); } void nam::convnet::ConvNetBlock::Process(const Eigen::Ref input, Eigen::Ref output, const long i_start, const long i_end) const { const long ncols = i_end - i_start; - this->conv.Process(input, output, i_start, ncols, i_start); - if (this->mDoBatchNorm) - this->mBatchnorm.Process(output, i_start, i_end); + conv.Process(input, output, i_start, ncols, i_start); + if (mDoBatchNorm) + mBatchnorm.Process(output, i_start, i_end); - this->mActivation->Apply(output.middleCols(i_start, ncols)); + mActivation->Apply(output.middleCols(i_start, ncols)); } long nam::convnet::ConvNetBlock::GetOutChannels() const { - return this->conv.GetOutChannels(); + return conv.GetOutChannels(); } nam::convnet::Head::Head(const int channels, weights_it& weights) { - this->mWeight.resize(channels); + mWeight.resize(channels); for (int i = 0; i < channels; i++) - this->mWeight[i] = *(weights++); - this->mBias = *(weights++); + mWeight[i] = *(weights++); + mBias = *(weights++); } void nam::convnet::Head::Process(const Eigen::Ref input, Eigen::VectorXf& output, const long i_start, @@ -88,7 +88,7 @@ void nam::convnet::Head::Process(const Eigen::Ref input, const long length = i_end - i_start; output.resize(length); for (long i = 0, j = i_start; i < length; i++, j++) - output(i) = this->mBias + input.col(j).dot(this->mWeight); + output(i) = mBias + input.col(j).dot(mWeight); } nam::convnet::ConvNet::ConvNet(const int channels, const std::vector& dilations, const bool batchnorm, @@ -96,16 +96,16 @@ nam::convnet::ConvNet::ConvNet(const int channels, const std::vector& dilat const double expectedSampleRate) : Buffer(*std::max_element(dilations.begin(), dilations.end()), expectedSampleRate) { - this->VerifyWeights(channels, dilations, batchnorm, weights.size()); - this->mBlocks.resize(dilations.size()); + VerifyWeights(channels, dilations, batchnorm, weights.size()); + mBlocks.resize(dilations.size()); weights_it it = weights.begin(); for (size_t i = 0; i < dilations.size(); i++) - this->mBlocks[i].SetWeights(i == 0 ? 1 : channels, channels, dilations[i], batchnorm, activation, it); - this->mBlockVals.resize(this->mBlocks.size() + 1); - for (auto& matrix : this->mBlockVals) + mBlocks[i].SetWeights(i == 0 ? 1 : channels, channels, dilations[i], batchnorm, activation, it); + mBlockVals.resize(mBlocks.size() + 1); + for (auto& matrix : mBlockVals) matrix.setZero(); - std::fill(this->mInputBuffer.begin(), this->mInputBuffer.end(), 0.0f); - this->mHead = Head(channels, it); + std::fill(mInputBuffer.begin(), mInputBuffer.end(), 0.0f); + mHead = Head(channels, it); if (it != weights.end()) throw std::runtime_error("Didn't touch all the weights when initializing ConvNet"); @@ -118,20 +118,20 @@ nam::convnet::ConvNet::ConvNet(const int channels, const std::vector& dilat void nam::convnet::ConvNet::Process(float* input, float* output, const int numFrames) { - this->UpdateBuffers(input, numFrames); + UpdateBuffers(input, numFrames); // Main computation! - const long i_start = this->mInputBufferOffset; + const long i_start = mInputBufferOffset; const long i_end = i_start + numFrames; // TODO one unnecessary copy :/ #speed for (auto i = i_start; i < i_end; i++) - this->mBlockVals[0](0, i) = this->mInputBuffer[i]; - for (size_t i = 0; i < this->mBlocks.size(); i++) - this->mBlocks[i].Process(this->mBlockVals[i], this->mBlockVals[i + 1], i_start, i_end); + mBlockVals[0](0, i) = mInputBuffer[i]; + for (size_t i = 0; i < mBlocks.size(); i++) + mBlocks[i].Process(mBlockVals[i], mBlockVals[i + 1], i_start, i_end); // TODO clean up this allocation - this->mHead.Process(this->mBlockVals[this->mBlocks.size()], this->mHeadOutput, i_start, i_end); + mHead.Process(mBlockVals[mBlocks.size()], mHeadOutput, i_start, i_end); // Copy to required output array (TODO tighten this up) for (int s = 0; s < numFrames; s++) - output[s] = this->mHeadOutput(s); + output[s] = mHeadOutput(s); } void nam::convnet::ConvNet::VerifyWeights(const int channels, const std::vector& dilations, const bool batchnorm, @@ -142,23 +142,23 @@ void nam::convnet::ConvNet::VerifyWeights(const int channels, const std::vector< void nam::convnet::ConvNet::UpdateBuffers(float* input, const int numFrames) { - this->Buffer::UpdateBuffers(input, numFrames); + Buffer::UpdateBuffers(input, numFrames); - const size_t buffer_size = this->mInputBuffer.size(); + const size_t buffer_size = mInputBuffer.size(); - if (this->mBlockVals[0].rows() != Eigen::Index(1) || this->mBlockVals[0].cols() != Eigen::Index(buffer_size)) + if (mBlockVals[0].rows() != Eigen::Index(1) || mBlockVals[0].cols() != Eigen::Index(buffer_size)) { - this->mBlockVals[0].resize(1, buffer_size); - this->mBlockVals[0].setZero(); + mBlockVals[0].resize(1, buffer_size); + mBlockVals[0].setZero(); } - for (size_t i = 1; i < this->mBlockVals.size(); i++) + for (size_t i = 1; i < mBlockVals.size(); i++) { - if (this->mBlockVals[i].rows() == this->mBlocks[i - 1].GetOutChannels() - && this->mBlockVals[i].cols() == Eigen::Index(buffer_size)) + if (mBlockVals[i].rows() == mBlocks[i - 1].GetOutChannels() + && mBlockVals[i].cols() == Eigen::Index(buffer_size)) continue; // Already has correct size - this->mBlockVals[i].resize(this->mBlocks[i - 1].GetOutChannels(), buffer_size); - this->mBlockVals[i].setZero(); + mBlockVals[i].resize(mBlocks[i - 1].GetOutChannels(), buffer_size); + mBlockVals[i].setZero(); } } @@ -168,16 +168,16 @@ void nam::convnet::ConvNet::RewindBuffers() // resets the offset index // The last _block_vals is the output of the last block and doesn't need to be // rewound. - for (size_t k = 0; k < this->mBlockVals.size() - 1; k++) + for (size_t k = 0; k < mBlockVals.size() - 1; k++) { // We actually don't need to pull back a lot...just as far as the first // input sample would grab from dilation - const long dilation = this->mBlocks[k].conv.GetDilation(); - for (long i = this->mReceptiveField - dilation, j = this->mInputBufferOffset - dilation; - j < this->mInputBufferOffset; i++, j++) - for (long r = 0; r < this->mBlockVals[k].rows(); r++) - this->mBlockVals[k](r, i) = this->mBlockVals[k](r, j); + const long dilation = mBlocks[k].conv.GetDilation(); + for (long i = mReceptiveField - dilation, j = mInputBufferOffset - dilation; + j < mInputBufferOffset; i++, j++) + for (long r = 0; r < mBlockVals[k].rows(); r++) + mBlockVals[k](r, i) = mBlockVals[k](r, j); } // Now we can do the rest of the rewind - this->Buffer::RewindBuffers(); + Buffer::RewindBuffers(); } diff --git a/NAM/dsp.cpp b/NAM/dsp.cpp index 9f1838c..db22fe6 100644 --- a/NAM/dsp.cpp +++ b/NAM/dsp.cpp @@ -30,8 +30,8 @@ void nam::DSP::Prewarm() // pre-warm the model for a model-specific number of samples for (long i = 0; i < mPrewarmSamples; i++) { - this->Process(sample_ptr, sample_ptr, 1); - this->Finalize(1); + Process(sample_ptr, sample_ptr, 1); + Finalize(1); sample = 0; } } @@ -65,20 +65,20 @@ void nam::DSP::Finalize(const int numFrames) {} nam::Buffer::Buffer(const int receptiveField, const double expectedSampleRate) : nam::DSP(expectedSampleRate) { - this->SetReceptiveField(receptiveField); + SetReceptiveField(receptiveField); } void nam::Buffer::SetReceptiveField(const int newReceptiveField) { - this->SetReceptiveField(newReceptiveField, _INPUT_BUFFER_SAFETY_FACTOR * newReceptiveField); + SetReceptiveField(newReceptiveField, _INPUT_BUFFER_SAFETY_FACTOR * newReceptiveField); }; void nam::Buffer::SetReceptiveField(const int newReceptiveField, const int inputBufferSize) { - this->mReceptiveField = newReceptiveField; - this->mInputBuffer.resize(inputBufferSize); - std::fill(this->mInputBuffer.begin(), this->mInputBuffer.end(), 0.0f); - this->ResetInputBuffer(); + mReceptiveField = newReceptiveField; + mInputBuffer.resize(inputBufferSize); + std::fill(mInputBuffer.begin(), mInputBuffer.end(), 0.0f); + ResetInputBuffer(); } void nam::Buffer::UpdateBuffers(float* input, const int numFrames) @@ -86,52 +86,52 @@ void nam::Buffer::UpdateBuffers(float* input, const int numFrames) // Make sure that the buffer is big enough for the receptive field and the // frames needed! { - const long minimum_input_buffer_size = (long)this->mReceptiveField + _INPUT_BUFFER_SAFETY_FACTOR * numFrames; - if ((long)this->mInputBuffer.size() < minimum_input_buffer_size) + const long minimum_input_buffer_size = (long)mReceptiveField + _INPUT_BUFFER_SAFETY_FACTOR * numFrames; + if ((long)mInputBuffer.size() < minimum_input_buffer_size) { long new_buffer_size = 2; while (new_buffer_size < minimum_input_buffer_size) new_buffer_size *= 2; - this->mInputBuffer.resize(new_buffer_size); - std::fill(this->mInputBuffer.begin(), this->mInputBuffer.end(), 0.0f); + mInputBuffer.resize(new_buffer_size); + std::fill(mInputBuffer.begin(), mInputBuffer.end(), 0.0f); } } // If we'd run off the end of the input buffer, then we need to move the data // back to the start of the buffer and start again. - if (this->mInputBufferOffset + numFrames > (long)this->mInputBuffer.size()) - this->RewindBuffers(); + if (mInputBufferOffset + numFrames > (long)mInputBuffer.size()) + RewindBuffers(); // Put the new samples into the input buffer - for (long i = this->mInputBufferOffset, j = 0; j < numFrames; i++, j++) - this->mInputBuffer[i] = input[j]; + for (long i = mInputBufferOffset, j = 0; j < numFrames; i++, j++) + mInputBuffer[i] = input[j]; // And resize the output buffer: - this->mOutputBuffer.resize(numFrames); - std::fill(this->mOutputBuffer.begin(), this->mOutputBuffer.end(), 0.0f); + mOutputBuffer.resize(numFrames); + std::fill(mOutputBuffer.begin(), mOutputBuffer.end(), 0.0f); } void nam::Buffer::RewindBuffers() { // Copy the input buffer back // RF-1 samples because we've got at least one new one inbound. - for (long i = 0, j = this->mInputBufferOffset - this->mReceptiveField; i < this->mReceptiveField; i++, j++) - this->mInputBuffer[i] = this->mInputBuffer[j]; + for (long i = 0, j = mInputBufferOffset - mReceptiveField; i < mReceptiveField; i++, j++) + mInputBuffer[i] = mInputBuffer[j]; // And reset the offset. // Even though we could be stingy about that one sample that we won't be using // (because a new set is incoming) it's probably not worth the // hyper-optimization and liable for bugs. And the code looks way tidier this // way. - this->mInputBufferOffset = this->mReceptiveField; + mInputBufferOffset = mReceptiveField; } void nam::Buffer::ResetInputBuffer() { - this->mInputBufferOffset = this->mReceptiveField; + mInputBufferOffset = mReceptiveField; } void nam::Buffer::Finalize(const int numFrames) { - this->nam::DSP::Finalize(numFrames); - this->mInputBufferOffset += numFrames; + nam::DSP::Finalize(numFrames); + mInputBufferOffset += numFrames; } // Linear ===================================================================== @@ -145,23 +145,23 @@ nam::Linear::Linear(const int receptiveField, const bool bias, const std::vector "Params vector does not match expected size based " "on architecture parameters"); - this->mWeight.resize(this->mReceptiveField); + mWeight.resize(mReceptiveField); // Pass in in reverse order so that dot products work out of the box. - for (int i = 0; i < this->mReceptiveField; i++) - this->mWeight(i) = weights[receptiveField - 1 - i]; - this->mBias = bias ? weights[receptiveField] : (float)0.0; + for (int i = 0; i < mReceptiveField; i++) + mWeight(i) = weights[receptiveField - 1 - i]; + mBias = bias ? weights[receptiveField] : (float)0.0; } void nam::Linear::Process(float* input, float* output, const int numFrames) { - this->nam::Buffer::UpdateBuffers(input, numFrames); + nam::Buffer::UpdateBuffers(input, numFrames); // Main computation! for (auto i = 0; i < numFrames; i++) { - const size_t offset = this->mInputBufferOffset - this->mWeight.size() + i + 1; - auto input = Eigen::Map(&this->mInputBuffer[offset], this->mReceptiveField); - output[i] = this->mBias + this->mWeight.dot(input); + const size_t offset = mInputBufferOffset - mWeight.size() + i + 1; + auto input = Eigen::Map(&mInputBuffer[offset], mReceptiveField); + output[i] = mBias + mWeight.dot(input); } } @@ -169,87 +169,87 @@ void nam::Linear::Process(float* input, float* output, const int numFrames) void nam::Conv1D::SetWeights(weights_it& weights) { - if (this->mWeight.size() > 0) + if (mWeight.size() > 0) { - const long outChannels = this->mWeight[0].rows(); - const long inChannels = this->mWeight[0].cols(); + const long outChannels = mWeight[0].rows(); + const long inChannels = mWeight[0].cols(); // Crazy ordering because that's how it gets flattened. for (auto i = 0; i < outChannels; i++) for (auto j = 0; j < inChannels; j++) - for (size_t k = 0; k < this->mWeight.size(); k++) - this->mWeight[k](i, j) = *(weights++); + for (size_t k = 0; k < mWeight.size(); k++) + mWeight[k](i, j) = *(weights++); } - for (long i = 0; i < this->mBias.size(); i++) - this->mBias(i) = *(weights++); + for (long i = 0; i < mBias.size(); i++) + mBias(i) = *(weights++); } void nam::Conv1D::SetSize(const int inChannels, const int outChannels, const int kernelSize, const bool doBias, const int dilation) { - this->mWeight.resize(kernelSize); - for (size_t i = 0; i < this->mWeight.size(); i++) - this->mWeight[i].resize(outChannels, + mWeight.resize(kernelSize); + for (size_t i = 0; i < mWeight.size(); i++) + mWeight[i].resize(outChannels, inChannels); // y = Ax, input array (C,L) if (doBias) - this->mBias.resize(outChannels); + mBias.resize(outChannels); else - this->mBias.resize(0); - this->mDilation = dilation; + mBias.resize(0); + mDilation = dilation; } void nam::Conv1D::SetSizeAndWeights(const int inChannels, const int outChannels, const int kernelSize, const int dilation, const bool doBias, weights_it& weights) { - this->SetSize(inChannels, outChannels, kernelSize, doBias, dilation); - this->SetWeights(weights); + SetSize(inChannels, outChannels, kernelSize, doBias, dilation); + SetWeights(weights); } void nam::Conv1D::Process(const Eigen::Ref input, Eigen::Ref output, const long i_start, const long ncols, const long j_start) const { // This is the clever part ;) - for (size_t k = 0; k < this->mWeight.size(); k++) + for (size_t k = 0; k < mWeight.size(); k++) { - const long offset = this->mDilation * (k + 1 - this->mWeight.size()); + const long offset = mDilation * (k + 1 - mWeight.size()); if (k == 0) - output.middleCols(j_start, ncols) = this->mWeight[k] * input.middleCols(i_start + offset, ncols); + output.middleCols(j_start, ncols) = mWeight[k] * input.middleCols(i_start + offset, ncols); else - output.middleCols(j_start, ncols) += this->mWeight[k] * input.middleCols(i_start + offset, ncols); + output.middleCols(j_start, ncols) += mWeight[k] * input.middleCols(i_start + offset, ncols); } - if (this->mBias.size() > 0) - output.middleCols(j_start, ncols).colwise() += this->mBias; + if (mBias.size() > 0) + output.middleCols(j_start, ncols).colwise() += mBias; } long nam::Conv1D::GetNumWeights() const { - long num_weights = this->mBias.size(); - for (size_t i = 0; i < this->mWeight.size(); i++) - num_weights += this->mWeight[i].size(); + long num_weights = mBias.size(); + for (size_t i = 0; i < mWeight.size(); i++) + num_weights += mWeight[i].size(); return num_weights; } nam::Conv1x1::Conv1x1(const int inChannels, const int outChannels, const bool bias) { - this->mWeight.resize(outChannels, inChannels); - this->mDoBias = bias; + mWeight.resize(outChannels, inChannels); + mDoBias = bias; if (bias) - this->mBias.resize(outChannels); + mBias.resize(outChannels); } void nam::Conv1x1::SetWeights(weights_it& weights) { - for (int i = 0; i < this->mWeight.rows(); i++) - for (int j = 0; j < this->mWeight.cols(); j++) - this->mWeight(i, j) = *(weights++); - if (this->mDoBias) - for (int i = 0; i < this->mBias.size(); i++) - this->mBias(i) = *(weights++); + for (int i = 0; i < mWeight.rows(); i++) + for (int j = 0; j < mWeight.cols(); j++) + mWeight(i, j) = *(weights++); + if (mDoBias) + for (int i = 0; i < mBias.size(); i++) + mBias(i) = *(weights++); } Eigen::MatrixXf nam::Conv1x1::Process(const Eigen::Ref input) const { - if (this->mDoBias) - return (this->mWeight * input).colwise() + this->mBias; + if (mDoBias) + return (mWeight * input).colwise() + mBias; else - return this->mWeight * input; + return mWeight * input; } diff --git a/NAM/dsp.h b/NAM/dsp.h index 8f9fa36..b1ce395 100644 --- a/NAM/dsp.h +++ b/NAM/dsp.h @@ -95,7 +95,7 @@ class Buffer : public DSP void SetReceptiveField(const int newReceptiveField, const int inputBufferSize); void SetReceptiveField(const int newReceptiveField); void ResetInputBuffer(); - // Use this->_input_post_gain + // Use _input_post_gain virtual void UpdateBuffers(float* input, int numFrames); virtual void RewindBuffers(); }; @@ -118,7 +118,7 @@ class Linear : public Buffer class Conv1D { public: - Conv1D() { this->mDilation = 1; }; + Conv1D() { mDilation = 1; }; void SetWeights(weights_it& weights); void SetSize(const int inChannels, const int outChannels, const int kernelSize, const bool doBias, const int dilation); @@ -129,11 +129,11 @@ class Conv1D // Indices on output for from j_start (to j_start + i_end - i_start) void Process(const Eigen::Ref input, Eigen::Ref output, const long i_start, const long i_end, const long j_start) const; - long GetInChannels() const { return this->mWeight.size() > 0 ? this->mWeight[0].cols() : 0; }; - long GetKernelSize() const { return this->mWeight.size(); }; + long GetInChannels() const { return mWeight.size() > 0 ? mWeight[0].cols() : 0; }; + long GetKernelSize() const { return mWeight.size(); }; long GetNumWeights() const; - long GetOutChannels() const { return this->mWeight.size() > 0 ? this->mWeight[0].rows() : 0; }; - int GetDilation() const { return this->mDilation; }; + long GetOutChannels() const { return mWeight.size() > 0 ? mWeight[0].rows() : 0; }; + int GetDilation() const { return mDilation; }; private: // Gonna wing this... @@ -153,7 +153,7 @@ class Conv1x1 // :return: (N,Cout) or (Cout,), respectively Eigen::MatrixXf Process(const Eigen::Ref input) const; - long GetOutChannels() const { return this->mWeight.rows(); }; + long GetOutChannels() const { return mWeight.rows(); }; private: Eigen::MatrixXf mWeight; diff --git a/NAM/lstm.cpp b/NAM/lstm.cpp index ac90c8e..4d72efb 100644 --- a/NAM/lstm.cpp +++ b/NAM/lstm.cpp @@ -8,33 +8,33 @@ nam::lstm::LSTMCell::LSTMCell(const int inputSize, const int hiddenSize, weights_it& weights) { // Resize arrays - this->_w.resize(4 * hiddenSize, inputSize + hiddenSize); - this->_b.resize(4 * hiddenSize); - this->_xh.resize(inputSize + hiddenSize); - this->_ifgo.resize(4 * hiddenSize); - this->_c.resize(hiddenSize); + _w.resize(4 * hiddenSize, inputSize + hiddenSize); + _b.resize(4 * hiddenSize); + _xh.resize(inputSize + hiddenSize); + _ifgo.resize(4 * hiddenSize); + _c.resize(hiddenSize); // Assign in row-major because that's how PyTorch goes. - for (int i = 0; i < this->_w.rows(); i++) - for (int j = 0; j < this->_w.cols(); j++) - this->_w(i, j) = *(weights++); - for (int i = 0; i < this->_b.size(); i++) - this->_b[i] = *(weights++); + for (int i = 0; i < _w.rows(); i++) + for (int j = 0; j < _w.cols(); j++) + _w(i, j) = *(weights++); + for (int i = 0; i < _b.size(); i++) + _b[i] = *(weights++); const int h_offset = inputSize; for (int i = 0; i < hiddenSize; i++) - this->_xh[i + h_offset] = *(weights++); + _xh[i + h_offset] = *(weights++); for (int i = 0; i < hiddenSize; i++) - this->_c[i] = *(weights++); + _c[i] = *(weights++); } void nam::lstm::LSTMCell::Process(const Eigen::VectorXf& x) { - const long hiddenSize = this->GetHiddenSize(); - const long inputSize = this->GetInputSize(); + const long hiddenSize = GetHiddenSize(); + const long inputSize = GetInputSize(); // Assign inputs - this->_xh(Eigen::seq(0, inputSize - 1)) = x; + _xh(Eigen::seq(0, inputSize - 1)) = x; // The matmul - this->_ifgo = this->_w * this->_xh + this->_b; + _ifgo = _w * _xh + _b; // Elementwise updates (apply nonlinearities here) const long i_offset = 0; const long f_offset = hiddenSize; @@ -45,22 +45,22 @@ void nam::lstm::LSTMCell::Process(const Eigen::VectorXf& x) if (activations::Activation::sUsingFastTanh) { for (auto i = 0; i < hiddenSize; i++) - this->_c[i] = - activations::fast_sigmoid(this->_ifgo[i + f_offset]) * this->_c[i] - + activations::fast_sigmoid(this->_ifgo[i + i_offset]) * activations::fast_tanh(this->_ifgo[i + g_offset]); + _c[i] = + activations::fast_sigmoid(_ifgo[i + f_offset]) * _c[i] + + activations::fast_sigmoid(_ifgo[i + i_offset]) * activations::fast_tanh(_ifgo[i + g_offset]); for (int i = 0; i < hiddenSize; i++) - this->_xh[i + h_offset] = - activations::fast_sigmoid(this->_ifgo[i + o_offset]) * activations::fast_tanh(this->_c[i]); + _xh[i + h_offset] = + activations::fast_sigmoid(_ifgo[i + o_offset]) * activations::fast_tanh(_c[i]); } else { for (auto i = 0; i < hiddenSize; i++) - this->_c[i] = activations::sigmoid(this->_ifgo[i + f_offset]) * this->_c[i] - + activations::sigmoid(this->_ifgo[i + i_offset]) * tanhf(this->_ifgo[i + g_offset]); + _c[i] = activations::sigmoid(_ifgo[i + f_offset]) * _c[i] + + activations::sigmoid(_ifgo[i + i_offset]) * tanhf(_ifgo[i + g_offset]); for (int i = 0; i < hiddenSize; i++) - this->_xh[i + h_offset] = activations::sigmoid(this->_ifgo[i + o_offset]) * tanhf(this->_c[i]); + _xh[i + h_offset] = activations::sigmoid(_ifgo[i + o_offset]) * tanhf(_c[i]); } } @@ -68,30 +68,30 @@ nam::lstm::LSTM::LSTM(const int numLayers, const int inputSize, const int hidden const double expectedSampleRate) : DSP(expectedSampleRate) { - this->mInput.resize(1); + mInput.resize(1); auto it = weights.begin(); for (int i = 0; i < numLayers; i++) - this->mLayers.push_back(LSTMCell(i == 0 ? inputSize : hiddenSize, hiddenSize, it)); - this->mHeadWeight.resize(hiddenSize); + mLayers.push_back(LSTMCell(i == 0 ? inputSize : hiddenSize, hiddenSize, it)); + mHeadWeight.resize(hiddenSize); for (int i = 0; i < hiddenSize; i++) - this->mHeadWeight[i] = *(it++); - this->mHeadBias = *(it++); + mHeadWeight[i] = *(it++); + mHeadBias = *(it++); assert(it == weights.end()); } void nam::lstm::LSTM::Process(float* input, float* output, const int numFrames) { for (auto i = 0; i < numFrames; i++) - output[i] = this->ProcessSample(input[i]); + output[i] = ProcessSample(input[i]); } float nam::lstm::LSTM::ProcessSample(const float x) { - if (this->mLayers.size() == 0) + if (mLayers.size() == 0) return x; - this->mInput(0) = x; - this->mLayers[0].Process(this->mInput); - for (size_t i = 1; i < this->mLayers.size(); i++) - this->mLayers[i].Process(this->mLayers[i - 1].GetHiddenState()); - return this->mHeadWeight.dot(this->mLayers[this->mLayers.size() - 1].GetHiddenState()) + this->mHeadBias; + mInput(0) = x; + mLayers[0].Process(mInput); + for (size_t i = 1; i < mLayers.size(); i++) + mLayers[i].Process(mLayers[i - 1].GetHiddenState()); + return mHeadWeight.dot(mLayers[mLayers.size() - 1].GetHiddenState()) + mHeadBias; } diff --git a/NAM/lstm.h b/NAM/lstm.h index 100894a..6f25ab3 100644 --- a/NAM/lstm.h +++ b/NAM/lstm.h @@ -23,7 +23,7 @@ class LSTMCell { public: LSTMCell(const int inputSize, const int hiddenSize, weights_it& weights); - Eigen::VectorXf GetHiddenState() const { return this->_xh(Eigen::placeholders::lastN(this->GetHiddenSize())); }; + Eigen::VectorXf GetHiddenState() const { return _xh(Eigen::placeholders::lastN(GetHiddenSize())); }; void Process(const Eigen::VectorXf& x); private: @@ -42,8 +42,8 @@ class LSTMCell // Cell state Eigen::VectorXf _c; - long GetHiddenSize() const { return this->_b.size() / 4; }; - long GetInputSize() const { return this->_xh.size() - this->GetHiddenSize(); }; + long GetHiddenSize() const { return _b.size() / 4; }; + long GetInputSize() const { return _xh.size() - GetHiddenSize(); }; }; // The multi-layer LSTM model diff --git a/NAM/wavenet.cpp b/NAM/wavenet.cpp index 4a80c5b..f5c1a4f 100644 --- a/NAM/wavenet.cpp +++ b/NAM/wavenet.cpp @@ -9,14 +9,14 @@ nam::wavenet::DilatedConv::DilatedConv(const int inChannels, const int outChannels, const int kernelSize, const int bias, const int dilation) { - this->SetSize(inChannels, outChannels, kernelSize, bias, dilation); + SetSize(inChannels, outChannels, kernelSize, bias, dilation); } void nam::wavenet::Layer::SetWeights(weights_it& weights) { - this->mConv.SetWeights(weights); - this->mInputMixin.SetWeights(weights); - this->_1x1.SetWeights(weights); + mConv.SetWeights(weights); + mInputMixin.SetWeights(weights); + _1x1.SetWeights(weights); } void nam::wavenet::Layer::Process(const Eigen::Ref input, const Eigen::Ref condition, @@ -24,35 +24,35 @@ void nam::wavenet::Layer::Process(const Eigen::Ref input, const long j_start) { const long ncols = condition.cols(); - const long channels = this->GetChannels(); + const long channels = GetChannels(); // Input dilated conv - this->mConv.Process(input, this->_z, i_start, ncols, 0); + mConv.Process(input, _z, i_start, ncols, 0); // Mix-in condition - this->_z += this->mInputMixin.Process(condition); + _z += mInputMixin.Process(condition); - this->mActivation->Apply(this->_z); + mActivation->Apply(_z); - if (this->mGated) + if (mGated) { - activations::Activation::GetActivation("Sigmoid")->Apply(this->_z.block(channels, 0, channels, this->_z.cols())); + activations::Activation::GetActivation("Sigmoid")->Apply(_z.block(channels, 0, channels, _z.cols())); - this->_z.topRows(channels).array() *= this->_z.bottomRows(channels).array(); - // this->_z.topRows(channels) = this->_z.topRows(channels).cwiseProduct( - // this->_z.bottomRows(channels) + _z.topRows(channels).array() *= _z.bottomRows(channels).array(); + // _z.topRows(channels) = _z.topRows(channels).cwiseProduct( + // _z.bottomRows(channels) // ); } - head_input += this->_z.topRows(channels); - output.middleCols(j_start, ncols) = input.middleCols(i_start, ncols) + this->_1x1.Process(this->_z.topRows(channels)); + head_input += _z.topRows(channels); + output.middleCols(j_start, ncols) = input.middleCols(i_start, ncols) + _1x1.Process(_z.topRows(channels)); } void nam::wavenet::Layer::SetNumFrames(const long numFrames) { - if (this->_z.rows() == this->mConv.GetOutChannels() && this->_z.cols() == numFrames) + if (_z.rows() == mConv.GetOutChannels() && _z.cols() == numFrames) return; // Already has correct size - this->_z.resize(this->mConv.GetOutChannels(), numFrames); - this->_z.setZero(); + _z.resize(mConv.GetOutChannels(), numFrames); + _z.setZero(); } // LayerArray ================================================================= @@ -66,26 +66,26 @@ nam::wavenet::LayerArray::LayerArray(const int inputSize, const int condition_si , mHeadRechannel(channels, head_size, head_bias) { for (size_t i = 0; i < dilations.size(); i++) - this->mLayers.push_back(Layer(condition_size, channels, kernelSize, dilations[i], activation, gated)); - const long receptiveField = this->GetReceptiveField(); + mLayers.push_back(Layer(condition_size, channels, kernelSize, dilations[i], activation, gated)); + const long receptiveField = GetReceptiveField(); for (size_t i = 0; i < dilations.size(); i++) { - this->mLayerBuffers.push_back(Eigen::MatrixXf(channels, LAYER_ARRAY_BUFFER_SIZE + receptiveField - 1)); - this->mLayerBuffers[i].setZero(); + mLayerBuffers.push_back(Eigen::MatrixXf(channels, LAYER_ARRAY_BUFFER_SIZE + receptiveField - 1)); + mLayerBuffers[i].setZero(); } - this->mBufferStart = this->GetReceptiveField() - 1; + mBufferStart = GetReceptiveField() - 1; } void nam::wavenet::LayerArray::AdvanceBuffers(const int numFrames) { - this->mBufferStart += numFrames; + mBufferStart += numFrames; } long nam::wavenet::LayerArray::GetReceptiveField() const { long result = 0; - for (size_t i = 0; i < this->mLayers.size(); i++) - result += this->mLayers[i].GetDilation() * (this->mLayers[i].GetKernelSize() - 1); + for (size_t i = 0; i < mLayers.size(); i++) + result += mLayers[i].GetDilation() * (mLayers[i].GetKernelSize() - 1); return result; } @@ -98,70 +98,70 @@ void nam::wavenet::LayerArray::PrepareForFrames(const long numFrames) // -> this will write on indices 0 through 63, inclusive. // -> No illegal writes. // -> no rewind needed. - if (this->mBufferStart + numFrames > this->GetBufferSize()) - this->RewindBuffers(); + if (mBufferStart + numFrames > GetBufferSize()) + RewindBuffers(); } void nam::wavenet::LayerArray::Process(const Eigen::Ref layerInputs, const Eigen::Ref condition, Eigen::Ref headInputs, Eigen::Ref layerOutputs, Eigen::Ref headOutputs) { - this->mLayerBuffers[0].middleCols(this->mBufferStart, layerInputs.cols()) = this->mReChannel.Process(layerInputs); - const size_t last_layer = this->mLayers.size() - 1; - for (size_t i = 0; i < this->mLayers.size(); i++) + mLayerBuffers[0].middleCols(mBufferStart, layerInputs.cols()) = mReChannel.Process(layerInputs); + const size_t last_layer = mLayers.size() - 1; + for (size_t i = 0; i < mLayers.size(); i++) { if (i == last_layer) { - this->mLayers[i].Process(this->mLayerBuffers[i], condition, headInputs, - layerOutputs, this->mBufferStart, + mLayers[i].Process(mLayerBuffers[i], condition, headInputs, + layerOutputs, mBufferStart, 0); } else { - this->mLayers[i].Process(this->mLayerBuffers[i], condition, headInputs, - this->mLayerBuffers[i + 1], this->mBufferStart, - this->mBufferStart); + mLayers[i].Process(mLayerBuffers[i], condition, headInputs, + mLayerBuffers[i + 1], mBufferStart, + mBufferStart); } } - headOutputs = this->mHeadRechannel.Process(headInputs); + headOutputs = mHeadRechannel.Process(headInputs); } void nam::wavenet::LayerArray::SetNumFrames(const long numFrames) { // Wavenet checks for unchanged numFrames; if we made it here, there's // something to do. - if (LAYER_ARRAY_BUFFER_SIZE - numFrames < this->GetReceptiveField()) + if (LAYER_ARRAY_BUFFER_SIZE - numFrames < GetReceptiveField()) { std::stringstream ss; ss << "Asked to accept a buffer of " << numFrames << " samples, but the buffer is too short (" - << LAYER_ARRAY_BUFFER_SIZE << ") to get out of the recptive field (" << this->GetReceptiveField() + << LAYER_ARRAY_BUFFER_SIZE << ") to get out of the recptive field (" << GetReceptiveField() << "); copy errors could occur!\n"; throw std::runtime_error(ss.str().c_str()); } - for (size_t i = 0; i < this->mLayers.size(); i++) - this->mLayers[i].SetNumFrames(numFrames); + for (size_t i = 0; i < mLayers.size(); i++) + mLayers[i].SetNumFrames(numFrames); } void nam::wavenet::LayerArray::SetWeights(weights_it& weights) { - this->mReChannel.SetWeights(weights); - for (size_t i = 0; i < this->mLayers.size(); i++) - this->mLayers[i].SetWeights(weights); - this->mHeadRechannel.SetWeights(weights); + mReChannel.SetWeights(weights); + for (size_t i = 0; i < mLayers.size(); i++) + mLayers[i].SetWeights(weights); + mHeadRechannel.SetWeights(weights); } long nam::wavenet::LayerArray::GetChannels() const { - return this->mLayers.size() > 0 ? this->mLayers[0].GetChannels() : 0; + return mLayers.size() > 0 ? mLayers[0].GetChannels() : 0; } long nam::wavenet::LayerArray::_GetReceptiveField() const // TODO: why two? { // TODO remove this and use GetReceptiveField() instead! long res = 1; - for (size_t i = 0; i < this->mLayers.size(); i++) - res += (this->mLayers[i].GetKernelSize() - 1) * this->mLayers[i].GetDilation(); + for (size_t i = 0; i < mLayers.size(); i++) + res += (mLayers[i].GetKernelSize() - 1) * mLayers[i].GetDilation(); return res; } @@ -169,13 +169,13 @@ void nam::wavenet::LayerArray::RewindBuffers() // Consider wrapping instead... // Can make this smaller--largest dilation, not receptive field! { - const long start = this->GetReceptiveField() - 1; - for (size_t i = 0; i < this->mLayerBuffers.size(); i++) + const long start = GetReceptiveField() - 1; + for (size_t i = 0; i < mLayerBuffers.size(); i++) { - const long d = (this->mLayers[i].GetKernelSize() - 1) * this->mLayers[i].GetDilation(); - this->mLayerBuffers[i].middleCols(start - d, d) = this->mLayerBuffers[i].middleCols(this->mBufferStart - d, d); + const long d = (mLayers[i].GetKernelSize() - 1) * mLayers[i].GetDilation(); + mLayerBuffers[i].middleCols(start - d, d) = mLayerBuffers[i].middleCols(mBufferStart - d, d); } - this->mBufferStart = start; + mBufferStart = start; } // Head ======================================================================= @@ -189,53 +189,53 @@ nam::wavenet::Head::Head(const int inputSize, const int numLayers, const int cha int dx = inputSize; for (int i = 0; i < numLayers; i++) { - this->mLayers.push_back(Conv1x1(dx, i == numLayers - 1 ? 1 : channels, true)); + mLayers.push_back(Conv1x1(dx, i == numLayers - 1 ? 1 : channels, true)); dx = channels; if (i < numLayers - 1) - this->mBuffers.push_back(Eigen::MatrixXf()); + mBuffers.push_back(Eigen::MatrixXf()); } } void nam::wavenet::Head::SetWeights(weights_it& weights) { - for (size_t i = 0; i < this->mLayers.size(); i++) - this->mLayers[i].SetWeights(weights); + for (size_t i = 0; i < mLayers.size(); i++) + mLayers[i].SetWeights(weights); } void nam::wavenet::Head::Process(Eigen::Ref inputs, Eigen::Ref outputs) { - const size_t numLayers = this->mLayers.size(); - this->ApplyActivation(inputs); + const size_t numLayers = mLayers.size(); + ApplyActivation(inputs); if (numLayers == 1) - outputs = this->mLayers[0].Process(inputs); + outputs = mLayers[0].Process(inputs); else { - this->mBuffers[0] = this->mLayers[0].Process(inputs); + mBuffers[0] = mLayers[0].Process(inputs); for (size_t i = 1; i < numLayers; i++) { // Asserted > 0 layers - this->ApplyActivation(this->mBuffers[i - 1]); + ApplyActivation(mBuffers[i - 1]); if (i < numLayers - 1) - this->mBuffers[i] = this->mLayers[i].Process(this->mBuffers[i - 1]); + mBuffers[i] = mLayers[i].Process(mBuffers[i - 1]); else - outputs = this->mLayers[i].Process(this->mBuffers[i - 1]); + outputs = mLayers[i].Process(mBuffers[i - 1]); } } } void nam::wavenet::Head::SetNumFrames(const long numFrames) { - for (size_t i = 0; i < this->mBuffers.size(); i++) + for (size_t i = 0; i < mBuffers.size(); i++) { - if (this->mBuffers[i].rows() == this->mChannels && this->mBuffers[i].cols() == numFrames) + if (mBuffers[i].rows() == mChannels && mBuffers[i].cols() == numFrames) continue; // Already has correct size - this->mBuffers[i].resize(this->mChannels, numFrames); - this->mBuffers[i].setZero(); + mBuffers[i].resize(mChannels, numFrames); + mBuffers[i].setZero(); } } void nam::wavenet::Head::ApplyActivation(Eigen::Ref x) { - this->mActivation->Apply(x); + mActivation->Apply(x); } // WaveNet ==================================================================== @@ -251,13 +251,13 @@ nam::wavenet::WaveNet::WaveNet(const std::vector throw std::runtime_error("Head not implemented!"); for (size_t i = 0; i < layerArrayParams.size(); i++) { - this->mLayerArrays.push_back(nam::wavenet::LayerArray( + mLayerArrays.push_back(nam::wavenet::LayerArray( layerArrayParams[i].mInputSize, layerArrayParams[i].mConditionSize, layerArrayParams[i].mHeadSize, layerArrayParams[i].mChannels, layerArrayParams[i].mKernelSize, layerArrayParams[i].mDilations, layerArrayParams[i].mActivation, layerArrayParams[i].mGated, layerArrayParams[i].mHeadBias)); - this->mLayerArrayOutputs.push_back(Eigen::MatrixXf(layerArrayParams[i].mChannels, 0)); + mLayerArrayOutputs.push_back(Eigen::MatrixXf(layerArrayParams[i].mChannels, 0)); if (i == 0) - this->mHeadArrays.push_back(Eigen::MatrixXf(layerArrayParams[i].mChannels, 0)); + mHeadArrays.push_back(Eigen::MatrixXf(layerArrayParams[i].mChannels, 0)); if (i > 0) if (layerArrayParams[i].mChannels != layerArrayParams[i - 1].mHeadSize) { @@ -266,29 +266,29 @@ nam::wavenet::WaveNet::WaveNet(const std::vector << ") doesn't match head_size of preceding layer (" << layerArrayParams[i - 1].mHeadSize << "!\n"; throw std::runtime_error(ss.str().c_str()); } - this->mHeadArrays.push_back(Eigen::MatrixXf(layerArrayParams[i].mHeadSize, 0)); + mHeadArrays.push_back(Eigen::MatrixXf(layerArrayParams[i].mHeadSize, 0)); } - this->mHeadOutput.resize(1, 0); // Mono output! - this->SetWeights(weights); + mHeadOutput.resize(1, 0); // Mono output! + SetWeights(weights); mPrewarmSamples = 1; - for (size_t i = 0; i < this->mLayerArrays.size(); i++) - mPrewarmSamples += this->mLayerArrays[i].GetReceptiveField(); + for (size_t i = 0; i < mLayerArrays.size(); i++) + mPrewarmSamples += mLayerArrays[i].GetReceptiveField(); } void nam::wavenet::WaveNet::Finalize(const int numFrames) { - this->DSP::Finalize(numFrames); - this->AdvanceBuffers(numFrames); + DSP::Finalize(numFrames); + AdvanceBuffers(numFrames); } void nam::wavenet::WaveNet::SetWeights(const std::vector& weights) { weights_it it = weights.begin(); - for (size_t i = 0; i < this->mLayerArrays.size(); i++) - this->mLayerArrays[i].SetWeights(it); - // this->_head.set_params_(it); - this->mHeadScale = *(it++); + for (size_t i = 0; i < mLayerArrays.size(); i++) + mLayerArrays[i].SetWeights(it); + // _head.set_params_(it); + mHeadScale = *(it++); if (it != weights.end()) { std::stringstream ss; @@ -305,69 +305,69 @@ void nam::wavenet::WaveNet::SetWeights(const std::vector& weights) void nam::wavenet::WaveNet::AdvanceBuffers(const int numFrames) { - for (size_t i = 0; i < this->mLayerArrays.size(); i++) - this->mLayerArrays[i].AdvanceBuffers(numFrames); + for (size_t i = 0; i < mLayerArrays.size(); i++) + mLayerArrays[i].AdvanceBuffers(numFrames); } void nam::wavenet::WaveNet::PrepareForFrames(const long numFrames) { - for (size_t i = 0; i < this->mLayerArrays.size(); i++) - this->mLayerArrays[i].PrepareForFrames(numFrames); + for (size_t i = 0; i < mLayerArrays.size(); i++) + mLayerArrays[i].PrepareForFrames(numFrames); } void nam::wavenet::WaveNet::SetConditionArray(float* input, const int numFrames) { for (int j = 0; j < numFrames; j++) { - this->mCondition(0, j) = input[j]; + mCondition(0, j) = input[j]; } } void nam::wavenet::WaveNet::Process(float* input, float* output, const int numFrames) { - this->SetNumFrames(numFrames); - this->PrepareForFrames(numFrames); - this->SetConditionArray(input, numFrames); + SetNumFrames(numFrames); + PrepareForFrames(numFrames); + SetConditionArray(input, numFrames); // Main layer arrays: // Layer-to-layer // Sum on head output - this->mHeadArrays[0].setZero(); - for (size_t i = 0; i < this->mLayerArrays.size(); i++) - this->mLayerArrays[i].Process(i == 0 ? this->mCondition : this->mLayerArrayOutputs[i - 1], this->mCondition, - this->mHeadArrays[i], this->mLayerArrayOutputs[i], this->mHeadArrays[i + 1]); - // this->_head.Process( - // this->_head_input, - // this->_head_output + mHeadArrays[0].setZero(); + for (size_t i = 0; i < mLayerArrays.size(); i++) + mLayerArrays[i].Process(i == 0 ? mCondition : mLayerArrayOutputs[i - 1], mCondition, + mHeadArrays[i], mLayerArrayOutputs[i], mHeadArrays[i + 1]); + // _head.Process( + // _head_input, + // _head_output //); // Copy to required output array // Hack: apply head scale here; revisit when/if I activate the head. - // assert(this->_head_output.rows() == 1); + // assert(_head_output.rows() == 1); - const long final_head_array = this->mHeadArrays.size() - 1; - assert(this->mHeadArrays[final_head_array].rows() == 1); + const long final_head_array = mHeadArrays.size() - 1; + assert(mHeadArrays[final_head_array].rows() == 1); for (int s = 0; s < numFrames; s++) { - float out = this->mHeadScale * this->mHeadArrays[final_head_array](0, s); + float out = mHeadScale * mHeadArrays[final_head_array](0, s); output[s] = out; } } void nam::wavenet::WaveNet::SetNumFrames(const long numFrames) { - if (numFrames == this->mNumFrames) + if (numFrames == mNumFrames) return; - this->mCondition.resize(this->GetConditionDim(), numFrames); - for (size_t i = 0; i < this->mHeadArrays.size(); i++) - this->mHeadArrays[i].resize(this->mHeadArrays[i].rows(), numFrames); - for (size_t i = 0; i < this->mLayerArrayOutputs.size(); i++) - this->mLayerArrayOutputs[i].resize(this->mLayerArrayOutputs[i].rows(), numFrames); - this->mHeadOutput.resize(this->mHeadOutput.rows(), numFrames); - this->mHeadOutput.setZero(); - - for (size_t i = 0; i < this->mLayerArrays.size(); i++) - this->mLayerArrays[i].SetNumFrames(numFrames); - // this->_head.SetNumFrames(numFrames); - this->mNumFrames = numFrames; + mCondition.resize(GetConditionDim(), numFrames); + for (size_t i = 0; i < mHeadArrays.size(); i++) + mHeadArrays[i].resize(mHeadArrays[i].rows(), numFrames); + for (size_t i = 0; i < mLayerArrayOutputs.size(); i++) + mLayerArrayOutputs[i].resize(mLayerArrayOutputs[i].rows(), numFrames); + mHeadOutput.resize(mHeadOutput.rows(), numFrames); + mHeadOutput.setZero(); + + for (size_t i = 0; i < mLayerArrays.size(); i++) + mLayerArrays[i].SetNumFrames(numFrames); + // _head.SetNumFrames(numFrames); + mNumFrames = numFrames; } diff --git a/NAM/wavenet.h b/NAM/wavenet.h index a61a16b..271d0af 100644 --- a/NAM/wavenet.h +++ b/NAM/wavenet.h @@ -36,9 +36,9 @@ class Layer void Process(const Eigen::Ref input, const Eigen::Ref condition, Eigen::Ref head_input, Eigen::Ref output, const long i_start, const long j_start); void SetNumFrames(const long numFrames); - long GetChannels() const { return this->mConv.GetInChannels(); }; - int GetDilation() const { return this->mConv.GetDilation(); }; - long GetKernelSize() const { return this->mConv.GetKernelSize(); }; + long GetChannels() const { return mConv.GetInChannels(); }; + int GetDilation() const { return mConv.GetDilation(); }; + long GetKernelSize() const { return mConv.GetKernelSize(); }; private: // The dilated convolution at the front of the block @@ -70,7 +70,7 @@ class LayerArrayParams , mHeadBias(headBias) { for (size_t i = 0; i < dilations.size(); i++) - this->mDilations.push_back(dilations[i]); + mDilations.push_back(dilations[i]); }; const int mInputSize; @@ -129,7 +129,7 @@ class LayerArray // Rechannel for the head Conv1x1 mHeadRechannel; - long GetBufferSize() const { return this->mLayerBuffers.size() > 0 ? this->mLayerBuffers[0].cols() : 0; }; + long GetBufferSize() const { return mLayerBuffers.size() > 0 ? mLayerBuffers[0].cols() : 0; }; long GetChannels() const; // "One-indexed" receptive field // TODO remove! From 0c835066b533367f9e38c067391cce2054a5ed01 Mon Sep 17 00:00:00 2001 From: Oli Larkin Date: Sat, 20 Jan 2024 01:19:29 +0100 Subject: [PATCH 123/133] final_head_array --- NAM/wavenet.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/NAM/wavenet.cpp b/NAM/wavenet.cpp index f5c1a4f..1c8261a 100644 --- a/NAM/wavenet.cpp +++ b/NAM/wavenet.cpp @@ -344,11 +344,11 @@ void nam::wavenet::WaveNet::Process(float* input, float* output, const int numFr // Hack: apply head scale here; revisit when/if I activate the head. // assert(_head_output.rows() == 1); - const long final_head_array = mHeadArrays.size() - 1; - assert(mHeadArrays[final_head_array].rows() == 1); + const long finalHeadArray = mHeadArrays.size() - 1; + assert(mHeadArrays[finalHeadArray].rows() == 1); for (int s = 0; s < numFrames; s++) { - float out = mHeadScale * mHeadArrays[final_head_array](0, s); + float out = mHeadScale * mHeadArrays[finalHeadArray](0, s); output[s] = out; } } From a58e46c5b7bda395bc8b40fe7a9c17cfcfb4cb86 Mon Sep 17 00:00:00 2001 From: Oli Larkin Date: Sat, 20 Jan 2024 01:22:18 +0100 Subject: [PATCH 124/133] headInput --- NAM/wavenet.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NAM/wavenet.h b/NAM/wavenet.h index 271d0af..fcf09f7 100644 --- a/NAM/wavenet.h +++ b/NAM/wavenet.h @@ -33,7 +33,7 @@ class Layer void SetWeights(weights_it& weights); // :param `input`: from previous layer // :param `output`: to next layer - void Process(const Eigen::Ref input, const Eigen::Ref condition, Eigen::Ref head_input, + void Process(const Eigen::Ref input, const Eigen::Ref condition, Eigen::Ref headInput, Eigen::Ref output, const long i_start, const long j_start); void SetNumFrames(const long numFrames); long GetChannels() const { return mConv.GetInChannels(); }; From c55924564fbfe39bce6f08fd4e7438cc3db4e1d6 Mon Sep 17 00:00:00 2001 From: Oli Larkin Date: Sat, 20 Jan 2024 01:23:51 +0100 Subject: [PATCH 125/133] weights_it -> weightsIterator --- NAM/convnet.cpp | 8 ++++---- NAM/convnet.h | 6 +++--- NAM/dsp.cpp | 6 +++--- NAM/dsp.h | 8 ++++---- NAM/lstm.cpp | 2 +- NAM/lstm.h | 2 +- NAM/wavenet.cpp | 8 ++++---- NAM/wavenet.h | 6 +++--- 8 files changed, 23 insertions(+), 23 deletions(-) diff --git a/NAM/convnet.cpp b/NAM/convnet.cpp index a9817df..7d60137 100644 --- a/NAM/convnet.cpp +++ b/NAM/convnet.cpp @@ -10,7 +10,7 @@ #include "dsp.h" #include "convnet.h" -nam::convnet::BatchNorm::BatchNorm(const int dim, weights_it& weights) +nam::convnet::BatchNorm::BatchNorm(const int dim, weightsIterator& weights) { // Extract from param buffer Eigen::VectorXf running_mean(dim); @@ -48,7 +48,7 @@ void nam::convnet::BatchNorm::Process(Eigen::Ref x, const long void nam::convnet::ConvNetBlock::SetWeights(const int inChannels, const int outChannels, const int dilation, const bool doBatchNorm, const std::string activation, - weights_it& weights) + weightsIterator& weights) { mDoBatchNorm = doBatchNorm; // HACK 2 kernel @@ -74,7 +74,7 @@ long nam::convnet::ConvNetBlock::GetOutChannels() const return conv.GetOutChannels(); } -nam::convnet::Head::Head(const int channels, weights_it& weights) +nam::convnet::Head::Head(const int channels, weightsIterator& weights) { mWeight.resize(channels); for (int i = 0; i < channels; i++) @@ -98,7 +98,7 @@ nam::convnet::ConvNet::ConvNet(const int channels, const std::vector& dilat { VerifyWeights(channels, dilations, batchnorm, weights.size()); mBlocks.resize(dilations.size()); - weights_it it = weights.begin(); + weightsIterator it = weights.begin(); for (size_t i = 0; i < dilations.size(); i++) mBlocks[i].SetWeights(i == 0 ? 1 : channels, channels, dilations[i], batchnorm, activation, it); mBlockVals.resize(mBlocks.size() + 1); diff --git a/NAM/convnet.h b/NAM/convnet.h index effc701..6f7d997 100644 --- a/NAM/convnet.h +++ b/NAM/convnet.h @@ -23,7 +23,7 @@ class BatchNorm { public: BatchNorm(){}; - BatchNorm(const int dim, weights_it& weights); + BatchNorm(const int dim, weightsIterator& weights); void Process(Eigen::Ref input, const long i_start, const long i_end) const; private: @@ -41,7 +41,7 @@ class ConvNetBlock public: ConvNetBlock(){}; void SetWeights(const int inChannels, const int outChannels, const int dilation, const bool batchnorm, - const std::string activation, weights_it& weights); + const std::string activation, weightsIterator& weights); void Process(const Eigen::Ref input, Eigen::Ref output, const long i_start, const long i_end) const; long GetOutChannels() const; Conv1D conv; @@ -56,7 +56,7 @@ class Head { public: Head(){}; - Head(const int channels, weights_it& weights); + Head(const int channels, weightsIterator& weights); void Process(const Eigen::Ref input, Eigen::VectorXf& output, const long i_start, const long i_end) const; private: diff --git a/NAM/dsp.cpp b/NAM/dsp.cpp index db22fe6..7c16505 100644 --- a/NAM/dsp.cpp +++ b/NAM/dsp.cpp @@ -167,7 +167,7 @@ void nam::Linear::Process(float* input, float* output, const int numFrames) // NN modules ================================================================= -void nam::Conv1D::SetWeights(weights_it& weights) +void nam::Conv1D::SetWeights(weightsIterator& weights) { if (mWeight.size() > 0) { @@ -198,7 +198,7 @@ void nam::Conv1D::SetSize(const int inChannels, const int outChannels, const int } void nam::Conv1D::SetSizeAndWeights(const int inChannels, const int outChannels, const int kernelSize, - const int dilation, const bool doBias, weights_it& weights) + const int dilation, const bool doBias, weightsIterator& weights) { SetSize(inChannels, outChannels, kernelSize, doBias, dilation); SetWeights(weights); @@ -236,7 +236,7 @@ nam::Conv1x1::Conv1x1(const int inChannels, const int outChannels, const bool bi mBias.resize(outChannels); } -void nam::Conv1x1::SetWeights(weights_it& weights) +void nam::Conv1x1::SetWeights(weightsIterator& weights) { for (int i = 0; i < mWeight.rows(); i++) for (int j = 0; j < mWeight.cols(); j++) diff --git a/NAM/dsp.h b/NAM/dsp.h index b1ce395..1d5f23a 100644 --- a/NAM/dsp.h +++ b/NAM/dsp.h @@ -18,7 +18,7 @@ namespace nam { -using weights_it = std::vector::const_iterator; +using weightsIterator = std::vector::const_iterator; enum EArchitectures { @@ -119,11 +119,11 @@ class Conv1D { public: Conv1D() { mDilation = 1; }; - void SetWeights(weights_it& weights); + void SetWeights(weightsIterator& weights); void SetSize(const int inChannels, const int outChannels, const int kernelSize, const bool doBias, const int dilation); void SetSizeAndWeights(const int inChannels, const int outChannels, const int kernelSize, const int dilation, - const bool doBias, weights_it& weights); + const bool doBias, weightsIterator& weights); // Process from input to output // Rightmost indices of input go from i_start to i_end, // Indices on output for from j_start (to j_start + i_end - i_start) @@ -148,7 +148,7 @@ class Conv1x1 { public: Conv1x1(const int inChannels, const int outChannels, const bool bias); - void SetWeights(weights_it& weights); + void SetWeights(weightsIterator& weights); // :param input: (N,Cin) or (Cin,) // :return: (N,Cout) or (Cout,), respectively Eigen::MatrixXf Process(const Eigen::Ref input) const; diff --git a/NAM/lstm.cpp b/NAM/lstm.cpp index 4d72efb..f3b3af9 100644 --- a/NAM/lstm.cpp +++ b/NAM/lstm.cpp @@ -5,7 +5,7 @@ #include "dsp.h" #include "lstm.h" -nam::lstm::LSTMCell::LSTMCell(const int inputSize, const int hiddenSize, weights_it& weights) +nam::lstm::LSTMCell::LSTMCell(const int inputSize, const int hiddenSize, weightsIterator& weights) { // Resize arrays _w.resize(4 * hiddenSize, inputSize + hiddenSize); diff --git a/NAM/lstm.h b/NAM/lstm.h index 6f25ab3..8701bc3 100644 --- a/NAM/lstm.h +++ b/NAM/lstm.h @@ -22,7 +22,7 @@ namespace lstm class LSTMCell { public: - LSTMCell(const int inputSize, const int hiddenSize, weights_it& weights); + LSTMCell(const int inputSize, const int hiddenSize, weightsIterator& weights); Eigen::VectorXf GetHiddenState() const { return _xh(Eigen::placeholders::lastN(GetHiddenSize())); }; void Process(const Eigen::VectorXf& x); diff --git a/NAM/wavenet.cpp b/NAM/wavenet.cpp index 1c8261a..fe9be53 100644 --- a/NAM/wavenet.cpp +++ b/NAM/wavenet.cpp @@ -12,7 +12,7 @@ nam::wavenet::DilatedConv::DilatedConv(const int inChannels, const int outChanne SetSize(inChannels, outChannels, kernelSize, bias, dilation); } -void nam::wavenet::Layer::SetWeights(weights_it& weights) +void nam::wavenet::Layer::SetWeights(weightsIterator& weights) { mConv.SetWeights(weights); mInputMixin.SetWeights(weights); @@ -143,7 +143,7 @@ void nam::wavenet::LayerArray::SetNumFrames(const long numFrames) mLayers[i].SetNumFrames(numFrames); } -void nam::wavenet::LayerArray::SetWeights(weights_it& weights) +void nam::wavenet::LayerArray::SetWeights(weightsIterator& weights) { mReChannel.SetWeights(weights); for (size_t i = 0; i < mLayers.size(); i++) @@ -196,7 +196,7 @@ nam::wavenet::Head::Head(const int inputSize, const int numLayers, const int cha } } -void nam::wavenet::Head::SetWeights(weights_it& weights) +void nam::wavenet::Head::SetWeights(weightsIterator& weights) { for (size_t i = 0; i < mLayers.size(); i++) mLayers[i].SetWeights(weights); @@ -284,7 +284,7 @@ void nam::wavenet::WaveNet::Finalize(const int numFrames) void nam::wavenet::WaveNet::SetWeights(const std::vector& weights) { - weights_it it = weights.begin(); + weightsIterator it = weights.begin(); for (size_t i = 0; i < mLayerArrays.size(); i++) mLayerArrays[i].SetWeights(it); // _head.set_params_(it); diff --git a/NAM/wavenet.h b/NAM/wavenet.h index fcf09f7..6d253d9 100644 --- a/NAM/wavenet.h +++ b/NAM/wavenet.h @@ -30,7 +30,7 @@ class Layer , _1x1(channels, channels, true) , mActivation(activations::Activation::GetActivation(activation)) , mGated(gated){}; - void SetWeights(weights_it& weights); + void SetWeights(weightsIterator& weights); // :param `input`: from previous layer // :param `output`: to next layer void Process(const Eigen::Ref input, const Eigen::Ref condition, Eigen::Ref headInput, @@ -108,7 +108,7 @@ class LayerArray Eigen::Ref headOutputs // post head-rechannel ); void SetNumFrames(const long numFrames); - void SetWeights(weights_it& it); + void SetWeights(weightsIterator& it); // "Zero-indexed" receptive field. // E.g. a 1x1 convolution has a z.i.r.f. of zero. @@ -144,7 +144,7 @@ class Head { public: Head(const int inputSize, const int numLayers, const int channels, const std::string activation); - void SetWeights(weights_it& weights); + void SetWeights(weightsIterator& weights); // NOTE: the head transforms the provided input by applying a nonlinearity // to it in-place! void Process(Eigen::Ref inputs, Eigen::Ref outputs); From 115e72729117d1b82999d3135c0cf935ff227d8e Mon Sep 17 00:00:00 2001 From: Oli Larkin Date: Sat, 20 Jan 2024 01:26:35 +0100 Subject: [PATCH 126/133] const std::filesystem::path& --- NAM/dsp.h | 6 +++--- NAM/get_dsp.cpp | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/NAM/dsp.h b/NAM/dsp.h index 1d5f23a..45f8428 100644 --- a/NAM/dsp.h +++ b/NAM/dsp.h @@ -194,11 +194,11 @@ struct dspData void VerifyConfigVersion(const std::string version); // Takes the model file and uses it to instantiate an instance of DSP. -std::unique_ptr GetDSP(const std::filesystem::path modelFile); +std::unique_ptr GetDSP(const std::filesystem::path& modelFile); // Creates an instance of DSP. Also returns a dspData struct that holds the data of the model. -std::unique_ptr GetDSP(const std::filesystem::path modelFile, dspData& returnedConfig); +std::unique_ptr GetDSP(const std::filesystem::path& modelFile, dspData& returnedConfig); // Instantiates a DSP object from dsp_config struct. std::unique_ptr GetDSP(dspData& conf); // Legacy loader for directory-type DSPs -std::unique_ptr GetDSPLegacy(const std::filesystem::path dirname); +std::unique_ptr GetDSPLegacy(const std::filesystem::path& dirname); }; // namespace nam diff --git a/NAM/get_dsp.cpp b/NAM/get_dsp.cpp index 150a1ad..42fd585 100644 --- a/NAM/get_dsp.cpp +++ b/NAM/get_dsp.cpp @@ -66,7 +66,7 @@ void VerifyConfigVersion(const std::string versionStr) } } -std::vector GetWeights(nlohmann::json const& j, const std::filesystem::path config_path) +std::vector GetWeights(nlohmann::json const& j, const std::filesystem::path& config_path) { if (j.find("weights") != j.end()) { @@ -80,13 +80,13 @@ std::vector GetWeights(nlohmann::json const& j, const std::filesystem::pa throw std::runtime_error("Corrupted model file is missing weights."); } -std::unique_ptr GetDSP(const std::filesystem::path config_filename) +std::unique_ptr GetDSP(const std::filesystem::path& config_filename) { dspData temp; return GetDSP(config_filename, temp); } -std::unique_ptr GetDSP(const std::filesystem::path config_filename, dspData& returnedConfig) +std::unique_ptr GetDSP(const std::filesystem::path& config_filename, dspData& returnedConfig) { if (!std::filesystem::exists(config_filename)) throw std::runtime_error("Config JSON doesn't exist!\n"); From 8622454db27b9386c36e15de85148ba5fae629a3 Mon Sep 17 00:00:00 2001 From: Oli Larkin Date: Sat, 20 Jan 2024 01:30:03 +0100 Subject: [PATCH 127/133] const std::string& --- NAM/activations.cpp | 2 +- NAM/activations.h | 2 +- NAM/convnet.cpp | 4 ++-- NAM/convnet.h | 4 ++-- NAM/dsp.h | 2 +- NAM/get_dsp.cpp | 4 ++-- NAM/util.cpp | 2 +- NAM/util.h | 2 +- NAM/wavenet.cpp | 4 ++-- NAM/wavenet.h | 8 ++++---- 10 files changed, 17 insertions(+), 17 deletions(-) diff --git a/NAM/activations.cpp b/NAM/activations.cpp index ca37364..d15e888 100644 --- a/NAM/activations.cpp +++ b/NAM/activations.cpp @@ -13,7 +13,7 @@ std::unordered_map nam::activations: nam::activations::Activation* tanh_bak = nullptr; -nam::activations::Activation* nam::activations::Activation::GetActivation(const std::string name) +nam::activations::Activation* nam::activations::Activation::GetActivation(const std::string& name) { if (_activations.find(name) == _activations.end()) return nullptr; diff --git a/NAM/activations.h b/NAM/activations.h index d70dafc..313288d 100644 --- a/NAM/activations.h +++ b/NAM/activations.h @@ -53,7 +53,7 @@ class Activation } virtual void Apply(float* data, long size) {} - static Activation* GetActivation(const std::string name); + static Activation* GetActivation(const std::string& name); static void EnableFastTanh(); static void DisableFastTanh(); static bool sUsingFastTanh; diff --git a/NAM/convnet.cpp b/NAM/convnet.cpp index 7d60137..b4d3155 100644 --- a/NAM/convnet.cpp +++ b/NAM/convnet.cpp @@ -47,7 +47,7 @@ void nam::convnet::BatchNorm::Process(Eigen::Ref x, const long } void nam::convnet::ConvNetBlock::SetWeights(const int inChannels, const int outChannels, const int dilation, - const bool doBatchNorm, const std::string activation, + const bool doBatchNorm, const std::string& activation, weightsIterator& weights) { mDoBatchNorm = doBatchNorm; @@ -92,7 +92,7 @@ void nam::convnet::Head::Process(const Eigen::Ref input, } nam::convnet::ConvNet::ConvNet(const int channels, const std::vector& dilations, const bool batchnorm, - const std::string activation, std::vector& weights, + const std::string& activation, std::vector& weights, const double expectedSampleRate) : Buffer(*std::max_element(dilations.begin(), dilations.end()), expectedSampleRate) { diff --git a/NAM/convnet.h b/NAM/convnet.h index 6f7d997..92103c7 100644 --- a/NAM/convnet.h +++ b/NAM/convnet.h @@ -41,7 +41,7 @@ class ConvNetBlock public: ConvNetBlock(){}; void SetWeights(const int inChannels, const int outChannels, const int dilation, const bool batchnorm, - const std::string activation, weightsIterator& weights); + const std::string& activation, weightsIterator& weights); void Process(const Eigen::Ref input, Eigen::Ref output, const long i_start, const long i_end) const; long GetOutChannels() const; Conv1D conv; @@ -67,7 +67,7 @@ class Head class ConvNet : public Buffer { public: - ConvNet(const int channels, const std::vector& dilations, const bool batchnorm, const std::string activation, + ConvNet(const int channels, const std::vector& dilations, const bool batchnorm, const std::string& activation, std::vector& weights, const double expectedSampleRate = -1.0); ~ConvNet() = default; diff --git a/NAM/dsp.h b/NAM/dsp.h index 45f8428..953cda4 100644 --- a/NAM/dsp.h +++ b/NAM/dsp.h @@ -191,7 +191,7 @@ struct dspData // Verify that the config that we are building our model from is supported by // this plugin version. -void VerifyConfigVersion(const std::string version); +void VerifyConfigVersion(const std::string& version); // Takes the model file and uses it to instantiate an instance of DSP. std::unique_ptr GetDSP(const std::filesystem::path& modelFile); diff --git a/NAM/get_dsp.cpp b/NAM/get_dsp.cpp index 42fd585..e592ac3 100644 --- a/NAM/get_dsp.cpp +++ b/NAM/get_dsp.cpp @@ -53,7 +53,7 @@ Version ParseVersion(const std::string& versionStr) return version; } -void VerifyConfigVersion(const std::string versionStr) +void VerifyConfigVersion(const std::string& versionStr) { Version version = ParseVersion(versionStr); if (version.major != 0 || version.minor != 5) @@ -156,7 +156,7 @@ std::unique_ptr GetDSP(dspData& conf) std::vector dilations; for (size_t i = 0; i < config["dilations"].size(); i++) dilations.push_back(config["dilations"][i]); - const std::string activation = config["activation"]; + auto activation = config["activation"]; out = std::make_unique(channels, dilations, batchnorm, activation, weights, expectedSampleRate); } else if (architecture == "LSTM") diff --git a/NAM/util.cpp b/NAM/util.cpp index 93815fc..d94724d 100644 --- a/NAM/util.cpp +++ b/NAM/util.cpp @@ -3,7 +3,7 @@ #include "util.h" -std::string nam::util::lowercase(const std::string& s) +std::string nam::util::lowercase(const std::string&& s) { std::string out(s); std::transform(s.begin(), s.end(), out.begin(), [](unsigned char c) { return std::tolower(c); }); diff --git a/NAM/util.h b/NAM/util.h index c0a5bd4..8b0f579 100644 --- a/NAM/util.h +++ b/NAM/util.h @@ -9,6 +9,6 @@ namespace nam { namespace util { -std::string lowercase(const std::string& s); +std::string lowercase(const std::string&& s); }; // namespace util }; // namespace nam diff --git a/NAM/wavenet.cpp b/NAM/wavenet.cpp index fe9be53..bf0d15d 100644 --- a/NAM/wavenet.cpp +++ b/NAM/wavenet.cpp @@ -61,7 +61,7 @@ void nam::wavenet::Layer::SetNumFrames(const long numFrames) nam::wavenet::LayerArray::LayerArray(const int inputSize, const int condition_size, const int head_size, const int channels, const int kernelSize, const std::vector& dilations, - const std::string activation, const bool gated, const bool head_bias) + const std::string& activation, const bool gated, const bool head_bias) : mReChannel(inputSize, channels, false) , mHeadRechannel(channels, head_size, head_bias) { @@ -180,7 +180,7 @@ void nam::wavenet::LayerArray::RewindBuffers() // Head ======================================================================= -nam::wavenet::Head::Head(const int inputSize, const int numLayers, const int channels, const std::string activation) +nam::wavenet::Head::Head(const int inputSize, const int numLayers, const int channels, const std::string& activation) : mChannels(channels) , mHead(numLayers > 0 ? channels : inputSize, 1, true) , mActivation(activations::Activation::GetActivation(activation)) diff --git a/NAM/wavenet.h b/NAM/wavenet.h index 6d253d9..0b7f4a7 100644 --- a/NAM/wavenet.h +++ b/NAM/wavenet.h @@ -24,7 +24,7 @@ class Layer { public: Layer(const int conditionSize, const int channels, const int kernelSize, const int dilation, - const std::string activation, const bool gated) + const std::string& activation, const bool gated) : mConv(channels, gated ? 2 * channels : channels, kernelSize, true, dilation) , mInputMixin(conditionSize, gated ? 2 * channels : channels, false) , _1x1(channels, channels, true) @@ -58,7 +58,7 @@ class LayerArrayParams { public: LayerArrayParams(const int inputSize, const int conditionSize, const int headSize, const int channels, - const int kernelSize, const std::vector& dilations, const std::string activation, + const int kernelSize, const std::vector& dilations, const std::string& activation, const bool gated, const bool headBias) : mInputSize(inputSize) , mConditionSize(conditionSize) @@ -89,7 +89,7 @@ class LayerArray { public: LayerArray(const int inputSize, const int condition_size, const int head_size, const int channels, - const int kernelSize, const std::vector& dilations, const std::string activation, const bool gated, + const int kernelSize, const std::vector& dilations, const std::string& activation, const bool gated, const bool head_bias); void AdvanceBuffers(const int numFrames); @@ -143,7 +143,7 @@ class LayerArray class Head { public: - Head(const int inputSize, const int numLayers, const int channels, const std::string activation); + Head(const int inputSize, const int numLayers, const int channels, const std::string& activation); void SetWeights(weightsIterator& weights); // NOTE: the head transforms the provided input by applying a nonlinearity // to it in-place! From c43383da37feab316ba2545cbd7a9ac29922c83e Mon Sep 17 00:00:00 2001 From: Oli Larkin Date: Sat, 20 Jan 2024 11:18:20 +0100 Subject: [PATCH 128/133] conditionSize --- NAM/wavenet.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NAM/wavenet.h b/NAM/wavenet.h index 0b7f4a7..9234f20 100644 --- a/NAM/wavenet.h +++ b/NAM/wavenet.h @@ -88,7 +88,7 @@ class LayerArrayParams class LayerArray { public: - LayerArray(const int inputSize, const int condition_size, const int head_size, const int channels, + LayerArray(const int inputSize, const int conditionSize, const int head_size, const int channels, const int kernelSize, const std::vector& dilations, const std::string& activation, const bool gated, const bool head_bias); From 1754a13cb996bd9034d0a9baa1b99ea73ebfa455 Mon Sep 17 00:00:00 2001 From: Oli Larkin Date: Sat, 20 Jan 2024 11:18:40 +0100 Subject: [PATCH 129/133] headSize --- NAM/wavenet.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NAM/wavenet.h b/NAM/wavenet.h index 9234f20..b1e6248 100644 --- a/NAM/wavenet.h +++ b/NAM/wavenet.h @@ -88,7 +88,7 @@ class LayerArrayParams class LayerArray { public: - LayerArray(const int inputSize, const int conditionSize, const int head_size, const int channels, + LayerArray(const int inputSize, const int conditionSize, const int headSize, const int channels, const int kernelSize, const std::vector& dilations, const std::string& activation, const bool gated, const bool head_bias); From f8743bb8044c8712a3f8598ac8c9895ca0d37f47 Mon Sep 17 00:00:00 2001 From: Oli Larkin Date: Sat, 20 Jan 2024 11:39:59 +0100 Subject: [PATCH 130/133] layerConfig --- NAM/get_dsp.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/NAM/get_dsp.cpp b/NAM/get_dsp.cpp index e592ac3..e1a67a6 100644 --- a/NAM/get_dsp.cpp +++ b/NAM/get_dsp.cpp @@ -171,14 +171,14 @@ std::unique_ptr GetDSP(dspData& conf) std::vector layerArrayParams; for (size_t i = 0; i < config["layers"].size(); i++) { - nlohmann::json layer_config = config["layers"][i]; + nlohmann::json layerConfig = config["layers"][i]; std::vector dilations; - for (size_t j = 0; j < layer_config["dilations"].size(); j++) - dilations.push_back(layer_config["dilations"][j]); + for (size_t j = 0; j < layerConfig["dilations"].size(); j++) + dilations.push_back(layerConfig["dilations"][j]); layerArrayParams.push_back( - wavenet::LayerArrayParams(layer_config["input_size"], layer_config["condition_size"], layer_config["head_size"], - layer_config["channels"], layer_config["kernel_size"], dilations, - layer_config["activation"], layer_config["gated"], layer_config["head_bias"])); + wavenet::LayerArrayParams(layerConfig["input_size"], layerConfig["condition_size"], layerConfig["head_size"], + layerConfig["channels"], layerConfig["kernel_size"], dilations, + layerConfig["activation"], layerConfig["gated"], layerConfig["head_bias"])); } const bool withHead = config["head"] == NULL; const float headScale = config["head_scale"]; From e090dfef90298c5a9111da22723da8f74614b154 Mon Sep 17 00:00:00 2001 From: Oli Larkin Date: Sat, 20 Jan 2024 17:36:24 +0100 Subject: [PATCH 131/133] configFileName --- NAM/get_dsp.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/NAM/get_dsp.cpp b/NAM/get_dsp.cpp index e1a67a6..86819da 100644 --- a/NAM/get_dsp.cpp +++ b/NAM/get_dsp.cpp @@ -80,24 +80,24 @@ std::vector GetWeights(nlohmann::json const& j, const std::filesystem::pa throw std::runtime_error("Corrupted model file is missing weights."); } -std::unique_ptr GetDSP(const std::filesystem::path& config_filename) +std::unique_ptr GetDSP(const std::filesystem::path& configFileName) { dspData temp; - return GetDSP(config_filename, temp); + return GetDSP(configFileName, temp); } -std::unique_ptr GetDSP(const std::filesystem::path& config_filename, dspData& returnedConfig) +std::unique_ptr GetDSP(const std::filesystem::path& configFileName, dspData& returnedConfig) { - if (!std::filesystem::exists(config_filename)) + if (!std::filesystem::exists(configFileName)) throw std::runtime_error("Config JSON doesn't exist!\n"); - std::ifstream i(config_filename); + std::ifstream i(configFileName); nlohmann::json j; i >> j; VerifyConfigVersion(j["version"]); auto architecture = j["architecture"]; nlohmann::json config = j["config"]; - std::vector weights = GetWeights(j, config_filename); + std::vector weights = GetWeights(j, configFileName); // Assign values to returnedConfig returnedConfig.version = j["version"]; From 7ea2631e8d401a3146968cf5d53ddd477a3f8f2c Mon Sep 17 00:00:00 2001 From: Oli Larkin Date: Mon, 22 Jan 2024 00:01:23 +0100 Subject: [PATCH 132/133] Add GetDSP(const char* jsonStr) --- NAM/dsp.h | 2 ++ NAM/get_dsp.cpp | 58 ++++++++++++++++++++++++++++++++++++------------- 2 files changed, 45 insertions(+), 15 deletions(-) diff --git a/NAM/dsp.h b/NAM/dsp.h index 953cda4..6c590bc 100644 --- a/NAM/dsp.h +++ b/NAM/dsp.h @@ -197,6 +197,8 @@ void VerifyConfigVersion(const std::string& version); std::unique_ptr GetDSP(const std::filesystem::path& modelFile); // Creates an instance of DSP. Also returns a dspData struct that holds the data of the model. std::unique_ptr GetDSP(const std::filesystem::path& modelFile, dspData& returnedConfig); +// Creates an instance of DSP. Also returns a dspData struct that holds the data of the model. +std::unique_ptr GetDSP(const char* jsonStr, dspData& returnedConfig); // Instantiates a DSP object from dsp_config struct. std::unique_ptr GetDSP(dspData& conf); // Legacy loader for directory-type DSPs diff --git a/NAM/get_dsp.cpp b/NAM/get_dsp.cpp index 86819da..6ca34db 100644 --- a/NAM/get_dsp.cpp +++ b/NAM/get_dsp.cpp @@ -66,7 +66,7 @@ void VerifyConfigVersion(const std::string& versionStr) } } -std::vector GetWeights(nlohmann::json const& j, const std::filesystem::path& config_path) +std::vector GetWeights(nlohmann::json const& j) { if (j.find("weights") != j.end()) { @@ -77,7 +77,7 @@ std::vector GetWeights(nlohmann::json const& j, const std::filesystem::pa return weights; } else - throw std::runtime_error("Corrupted model file is missing weights."); + throw std::runtime_error("Corrupted model is missing weights."); } std::unique_ptr GetDSP(const std::filesystem::path& configFileName) @@ -86,7 +86,7 @@ std::unique_ptr GetDSP(const std::filesystem::path& configFileName) return GetDSP(configFileName, temp); } -std::unique_ptr GetDSP(const std::filesystem::path& configFileName, dspData& returnedConfig) +std::unique_ptr GetDSP(const std::filesystem::path& configFileName, dspData& config) { if (!std::filesystem::exists(configFileName)) throw std::runtime_error("Config JSON doesn't exist!\n"); @@ -96,28 +96,56 @@ std::unique_ptr GetDSP(const std::filesystem::path& configFileName, dspData VerifyConfigVersion(j["version"]); auto architecture = j["architecture"]; - nlohmann::json config = j["config"]; - std::vector weights = GetWeights(j, configFileName); - - // Assign values to returnedConfig - returnedConfig.version = j["version"]; - returnedConfig.architecture = j["architecture"]; - returnedConfig.config = j["config"]; - returnedConfig.metadata = j["metadata"]; - returnedConfig.weights = weights; + std::vector weights = GetWeights(j); + + // Assign values to config + config.version = j["version"]; + config.architecture = j["architecture"]; + config.config = j["config"]; + config.metadata = j["metadata"]; + config.weights = weights; if (j.find("sample_rate") != j.end()) - returnedConfig.expectedSampleRate = j["sample_rate"]; + config.expectedSampleRate = j["sample_rate"]; else { - returnedConfig.expectedSampleRate = -1.0; + config.expectedSampleRate = -1.0; } + /*Copy to a new dsp_config object for GetDSP below, + since not sure if weights actually get modified as being non-const references on some + model constructors inside GetDSP(dsp_config& conf). + We need to return unmodified version of dsp_config via returnedConfig.*/ + dspData conf = config; + + return GetDSP(conf); +} + +std::unique_ptr GetDSP(const char* jsonStr, dspData& config) +{ + nlohmann::json j = nlohmann::json::parse(jsonStr); + VerifyConfigVersion(j["version"]); + + auto architecture = j["architecture"]; + std::vector weights = GetWeights(j); + + // Assign values to config + config.version = j["version"]; + config.architecture = j["architecture"]; + config.config = j["config"]; + config.metadata = j["metadata"]; + config.weights = weights; + if (j.find("sample_rate") != j.end()) + config.expectedSampleRate = j["sample_rate"]; + else + { + config.expectedSampleRate = -1.0; + } /*Copy to a new dsp_config object for GetDSP below, since not sure if weights actually get modified as being non-const references on some model constructors inside GetDSP(dsp_config& conf). We need to return unmodified version of dsp_config via returnedConfig.*/ - dspData conf = returnedConfig; + dspData conf = config; return GetDSP(conf); } From cd6e73a91f63586c6c7d7813a92d56c572661793 Mon Sep 17 00:00:00 2001 From: Oli Larkin Date: Wed, 24 Jan 2024 07:37:11 +0100 Subject: [PATCH 133/133] Remove non-standard header file --- tools/benchmodel.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/tools/benchmodel.cpp b/tools/benchmodel.cpp index 6055e73..5432a53 100644 --- a/tools/benchmodel.cpp +++ b/tools/benchmodel.cpp @@ -1,4 +1,3 @@ -#include "malloc.h" #include #include