diff --git a/src/lstm/fullyconnected.h b/src/lstm/fullyconnected.h index 2c886f9fd0fcda1a5210d8b3b0091dadf105b42d..6a1c1200a8d155ed75b923d1d5d9ef8b28f2eb3b 100644 --- a/src/lstm/fullyconnected.h +++ b/src/lstm/fullyconnected.h @@ -32,9 +32,9 @@ class FullyConnected : public Network { // Returns the shape output from the network given an input shape (which may // be partially unknown ie zero). - virtual StaticShape OutputShape(const StaticShape& input_shape) const; + StaticShape OutputShape(const StaticShape& input_shape) const override; - virtual STRING spec() const { + STRING spec() const override { STRING spec; if (type_ == NT_TANH) spec.add_str_int("Ft", no_); @@ -63,31 +63,31 @@ class FullyConnected : public Network { // Suspends/Enables training by setting the training_ flag. Serialize and // DeSerialize only operate on the run-time data if state is false. - virtual void SetEnableTraining(TrainingState state); + void SetEnableTraining(TrainingState state) override; // Sets up the network for training. Initializes weights using weights of // scale `range` picked according to the random number generator `randomizer`. - virtual int InitWeights(float range, TRand* randomizer); + int InitWeights(float range, TRand* randomizer) override; // Recursively searches the network for softmaxes with old_no outputs, // and remaps their outputs according to code_map. See network.h for details. int RemapOutputs(int old_no, const std::vector& code_map) override; // Converts a float network to an int network. - virtual void ConvertToInt(); + void ConvertToInt() override; // Provides debug output on the weights. - virtual void DebugWeights(); + void DebugWeights() override; // Writes to the given file. Returns false in case of error. - virtual bool Serialize(TFile* fp) const; + bool Serialize(TFile* fp) const override; // Reads from the given file. Returns false in case of error. - virtual bool DeSerialize(TFile* fp); + bool DeSerialize(TFile* fp) override; // Runs forward propagation of activations on the input line. // See Network for a detailed discussion of the arguments. - virtual void Forward(bool debug, const NetworkIO& input, - const TransposedArray* input_transpose, - NetworkScratch* scratch, NetworkIO* output); + void Forward(bool debug, const NetworkIO& input, + const TransposedArray* input_transpose, NetworkScratch* scratch, + NetworkIO* output) override; // Components of Forward so FullyConnected can be reused inside LSTM. void SetupForward(const NetworkIO& input, const TransposedArray* input_transpose); @@ -97,9 +97,8 @@ class FullyConnected : public Network { // Runs backward propagation of errors on the deltas line. // See Network for a detailed discussion of the arguments. - virtual bool Backward(bool debug, const NetworkIO& fwd_deltas, - NetworkScratch* scratch, - NetworkIO* back_deltas); + bool Backward(bool debug, const NetworkIO& fwd_deltas, + NetworkScratch* scratch, NetworkIO* back_deltas) override; // Components of Backward so FullyConnected can be reused inside LSTM. void BackwardTimeStep(const NetworkIO& fwd_deltas, int t, double* curr_errors, TransposedArray* errors_t, double* backprop); @@ -112,8 +111,8 @@ class FullyConnected : public Network { // Sums the products of weight updates in *this and other, splitting into // positive (same direction) in *same and negative (different direction) in // *changed. - virtual void CountAlternators(const Network& other, double* same, - double* changed) const; + void CountAlternators(const Network& other, double* same, + double* changed) const override; protected: // Weight arrays of size [no, ni + 1]. diff --git a/src/lstm/lstm.h b/src/lstm/lstm.h index baa6fa30968f1af1cdb30f8c79b32990ca9283fd..bf73affebe0825659284eb7ff3c0cb50f291d822 100644 --- a/src/lstm/lstm.h +++ b/src/lstm/lstm.h @@ -53,9 +53,9 @@ class LSTM : public Network { // Returns the shape output from the network given an input shape (which may // be partially unknown ie zero). - virtual StaticShape OutputShape(const StaticShape& input_shape) const; + StaticShape OutputShape(const StaticShape& input_shape) const override; - virtual STRING spec() const { + STRING spec() const override { STRING spec; if (type_ == NT_LSTM) spec.add_str_int("Lfx", ns_); @@ -71,37 +71,36 @@ class LSTM : public Network { // Suspends/Enables training by setting the training_ flag. Serialize and // DeSerialize only operate on the run-time data if state is false. - virtual void SetEnableTraining(TrainingState state); + void SetEnableTraining(TrainingState state) override; // Sets up the network for training. Initializes weights using weights of // scale `range` picked according to the random number generator `randomizer`. - virtual int InitWeights(float range, TRand* randomizer); + int InitWeights(float range, TRand* randomizer) override; // Recursively searches the network for softmaxes with old_no outputs, // and remaps their outputs according to code_map. See network.h for details. int RemapOutputs(int old_no, const std::vector& code_map) override; // Converts a float network to an int network. - virtual void ConvertToInt(); + void ConvertToInt() override; // Provides debug output on the weights. - virtual void DebugWeights(); + void DebugWeights() override; // Writes to the given file. Returns false in case of error. - virtual bool Serialize(TFile* fp) const; + bool Serialize(TFile* fp) const override; // Reads from the given file. Returns false in case of error. - virtual bool DeSerialize(TFile* fp); + bool DeSerialize(TFile* fp) override; // Runs forward propagation of activations on the input line. // See Network for a detailed discussion of the arguments. - virtual void Forward(bool debug, const NetworkIO& input, - const TransposedArray* input_transpose, - NetworkScratch* scratch, NetworkIO* output); + void Forward(bool debug, const NetworkIO& input, + const TransposedArray* input_transpose, NetworkScratch* scratch, + NetworkIO* output) override; // Runs backward propagation of errors on the deltas line. // See Network for a detailed discussion of the arguments. - virtual bool Backward(bool debug, const NetworkIO& fwd_deltas, - NetworkScratch* scratch, - NetworkIO* back_deltas); + bool Backward(bool debug, const NetworkIO& fwd_deltas, + NetworkScratch* scratch, NetworkIO* back_deltas) override; // Updates the weights using the given learning rate, momentum and adam_beta. // num_samples is used in the adam computation iff use_adam_ is true. void Update(float learning_rate, float momentum, float adam_beta, @@ -109,8 +108,8 @@ class LSTM : public Network { // Sums the products of weight updates in *this and other, splitting into // positive (same direction) in *same and negative (different direction) in // *changed. - virtual void CountAlternators(const Network& other, double* same, - double* changed) const; + void CountAlternators(const Network& other, double* same, + double* changed) const override; // Prints the weights for debug purposes. void PrintW(); // Prints the weight deltas for debug purposes. diff --git a/src/lstm/plumbing.h b/src/lstm/plumbing.h index 030a106011f09321ad5b0bfdbd401a31db637893..871fd987c40089754f450d923ca1eb260e9da685 100644 --- a/src/lstm/plumbing.h +++ b/src/lstm/plumbing.h @@ -34,40 +34,40 @@ class Plumbing : public Network { virtual ~Plumbing(); // Returns the required shape input to the network. - virtual StaticShape InputShape() const { return stack_[0]->InputShape(); } - virtual STRING spec() const { + StaticShape InputShape() const override { return stack_[0]->InputShape(); } + STRING spec() const override { return "Sub-classes of Plumbing must implement spec()!"; } // Returns true if the given type is derived from Plumbing, and thus contains // multiple sub-networks that can have their own learning rate. - virtual bool IsPlumbingType() const { return true; } + bool IsPlumbingType() const override { return true; } // Suspends/Enables training by setting the training_ flag. Serialize and // DeSerialize only operate on the run-time data if state is false. - virtual void SetEnableTraining(TrainingState state); + void SetEnableTraining(TrainingState state) override; // Sets flags that control the action of the network. See NetworkFlags enum // for bit values. - virtual void SetNetworkFlags(uint32_t flags); + void SetNetworkFlags(uint32_t flags) override; // Sets up the network for training. Initializes weights using weights of // scale `range` picked according to the random number generator `randomizer`. // Note that randomizer is a borrowed pointer that should outlive the network // and should not be deleted by any of the networks. // Returns the number of weights initialized. - virtual int InitWeights(float range, TRand* randomizer); + int InitWeights(float range, TRand* randomizer) override; // Recursively searches the network for softmaxes with old_no outputs, // and remaps their outputs according to code_map. See network.h for details. int RemapOutputs(int old_no, const std::vector& code_map) override; // Converts a float network to an int network. - virtual void ConvertToInt(); + void ConvertToInt() override; // Provides a pointer to a TRand for any networks that care to use it. // Note that randomizer is a borrowed pointer that should outlive the network // and should not be deleted by any of the networks. - virtual void SetRandomizer(TRand* randomizer); + void SetRandomizer(TRand* randomizer) override; // Adds the given network to the stack. virtual void AddToStack(Network* network); @@ -75,7 +75,7 @@ class Plumbing : public Network { // Sets needs_to_backprop_ to needs_backprop and returns true if // needs_backprop || any weights in this network so the next layer forward // can be told to produce backprop for this layer if needed. - virtual bool SetupNeedsBackprop(bool needs_backprop); + bool SetupNeedsBackprop(bool needs_backprop) override; // Returns an integer reduction factor that the network applies to the // time sequence. Assumes that any 2-d is already eliminated. Used for @@ -83,14 +83,14 @@ class Plumbing : public Network { // WARNING: if GlobalMinimax is used to vary the scale, this will return // the last used scale factor. Call it before any forward, and it will return // the minimum scale factor of the paths through the GlobalMinimax. - virtual int XScaleFactor() const; + int XScaleFactor() const override; // Provides the (minimum) x scale factor to the network (of interest only to // input units) so they can determine how to scale bounding boxes. - virtual void CacheXScaleFactor(int factor); + void CacheXScaleFactor(int factor) override; // Provides debug output on the weights. - virtual void DebugWeights(); + void DebugWeights() override; // Returns the current stack. const PointerVector& stack() const { @@ -117,9 +117,9 @@ class Plumbing : public Network { float* LayerLearningRatePtr(const char* id) const; // Writes to the given file. Returns false in case of error. - virtual bool Serialize(TFile* fp) const; + bool Serialize(TFile* fp) const override; // Reads from the given file. Returns false in case of error. - virtual bool DeSerialize(TFile* fp); + bool DeSerialize(TFile* fp) override; // Updates the weights using the given learning rate, momentum and adam_beta. // num_samples is used in the adam computation iff use_adam_ is true. @@ -128,8 +128,8 @@ class Plumbing : public Network { // Sums the products of weight updates in *this and other, splitting into // positive (same direction) in *same and negative (different direction) in // *changed. - virtual void CountAlternators(const Network& other, double* same, - double* changed) const; + void CountAlternators(const Network& other, double* same, + double* changed) const override; protected: // The networks. diff --git a/src/lstm/series.h b/src/lstm/series.h index 5b787e542699c025b765f77998efe479d7be9595..81061ae295627103e5f0bccaa1653a63c773f05e 100644 --- a/src/lstm/series.h +++ b/src/lstm/series.h @@ -32,9 +32,9 @@ class Series : public Plumbing { // Returns the shape output from the network given an input shape (which may // be partially unknown ie zero). - virtual StaticShape OutputShape(const StaticShape& input_shape) const; + StaticShape OutputShape(const StaticShape& input_shape) const override; - virtual STRING spec() const { + STRING spec() const override { STRING spec("["); for (int i = 0; i < stack_.size(); ++i) spec += stack_[i]->spec(); @@ -45,7 +45,7 @@ class Series : public Plumbing { // Sets up the network for training. Initializes weights using weights of // scale `range` picked according to the random number generator `randomizer`. // Returns the number of weights initialized. - virtual int InitWeights(float range, TRand* randomizer); + int InitWeights(float range, TRand* randomizer) override; // Recursively searches the network for softmaxes with old_no outputs, // and remaps their outputs according to code_map. See network.h for details. int RemapOutputs(int old_no, const std::vector& code_map) override; @@ -53,7 +53,7 @@ class Series : public Plumbing { // Sets needs_to_backprop_ to needs_backprop and returns true if // needs_backprop || any weights in this network so the next layer forward // can be told to produce backprop for this layer if needed. - virtual bool SetupNeedsBackprop(bool needs_backprop); + bool SetupNeedsBackprop(bool needs_backprop) override; // Returns an integer reduction factor that the network applies to the // time sequence. Assumes that any 2-d is already eliminated. Used for @@ -61,23 +61,22 @@ class Series : public Plumbing { // WARNING: if GlobalMinimax is used to vary the scale, this will return // the last used scale factor. Call it before any forward, and it will return // the minimum scale factor of the paths through the GlobalMinimax. - virtual int XScaleFactor() const; + int XScaleFactor() const override; // Provides the (minimum) x scale factor to the network (of interest only to // input units) so they can determine how to scale bounding boxes. - virtual void CacheXScaleFactor(int factor); + void CacheXScaleFactor(int factor) override; // Runs forward propagation of activations on the input line. // See Network for a detailed discussion of the arguments. - virtual void Forward(bool debug, const NetworkIO& input, - const TransposedArray* input_transpose, - NetworkScratch* scratch, NetworkIO* output); + void Forward(bool debug, const NetworkIO& input, + const TransposedArray* input_transpose, NetworkScratch* scratch, + NetworkIO* output) override; // Runs backward propagation of errors on the deltas line. // See Network for a detailed discussion of the arguments. - virtual bool Backward(bool debug, const NetworkIO& fwd_deltas, - NetworkScratch* scratch, - NetworkIO* back_deltas); + bool Backward(bool debug, const NetworkIO& fwd_deltas, + NetworkScratch* scratch, NetworkIO* back_deltas) override; // Splits the series after the given index, returning the two parts and // deletes itself. The first part, up to network with index last_start, goes