New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create the header to determine the layer type #1987
Merged
Merged
Changes from 16 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
1aae18c
Create file
sreenikSS e2140ff
Update to include layer_names.hpp
sreenikSS 0dd18f2
Fix style errors
sreenikSS d537f59
Fix style errors
sreenikSS 75c4b84
Add a newline to the end of the file
sreenikSS 0104db7
Restructure the class and use overloads
sreenikSS 57bed73
Update function description
sreenikSS 91563dd
Add missing full stops in the description
sreenikSS 712c0ab
Fix punctuation
sreenikSS 8c50636
Create test for layer_names.hpp
sreenikSS 6e4ea92
Update to include layer_names_test.cpp
sreenikSS ead52c2
Change all occurences of BOOST_REQUIRE_EQUAL to BOOST_REQUIRE
sreenikSS e43571a
Included MoreLayers and fixed the frelu string
sreenikSS 42b3acc
Fix style errors
sreenikSS 1967e0e
Delete all instances after the test is over
sreenikSS 802cf7c
Fix MoreTypes
sreenikSS c4555a0
Fix the delete statement
sreenikSS e505d81
Add full stops at the end of comments
sreenikSS File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ set(SOURCES | |
rnn_impl.hpp | ||
brnn.hpp | ||
brnn_impl.hpp | ||
layer_names.hpp | ||
) | ||
|
||
add_subdirectory(visitor) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,322 @@ | ||
/** | ||
* @file layer_names.hpp | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It might make sense to split this into an |
||
* @author Sreenik Seal | ||
* | ||
* Implementation of a class that converts a given ann layer to string format. | ||
* | ||
* mlpack is free software; you may redistribute it and/or modify it under the | ||
* terms of the 3-clause BSD license. You should have received a copy of the | ||
* 3-clause BSD license along with mlpack. If not, see | ||
* http://www.opensource.org/licenses/BSD-3-Clause for more information. | ||
*/ | ||
|
||
#include <mlpack/core.hpp> | ||
#include <mlpack/methods/ann/layer/layer.hpp> | ||
#include <mlpack/methods/ann/layer/layer_types.hpp> | ||
#include <boost/variant/static_visitor.hpp> | ||
#include <string> | ||
|
||
using namespace mlpack::ann; | ||
|
||
/** | ||
* Implementation of a class that returns the string representation of the | ||
* name of the given layer. | ||
*/ | ||
class LayerNameVisitor : public boost::static_visitor<std::string> | ||
rcurtin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
public: | ||
//! Create the LayerNameVisitor object. | ||
LayerNameVisitor() | ||
rcurtin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
} | ||
|
||
/* | ||
* Return the name of the given layer of type AtrousConvolution as a string. | ||
* | ||
* @param Given layer of type AtrousConvolution. | ||
* @return The string representation of the layer. | ||
*/ | ||
std::string LayerString(AtrousConvolution<>* /*layer*/) const | ||
{ | ||
return "atrousconvolution"; | ||
} | ||
|
||
/* | ||
* Return the name of the given layer of type AlphaDropout as a string. | ||
* | ||
* @param Given layer of type AlphaDropout. | ||
* @return The string representation of the layer. | ||
*/ | ||
std::string LayerString(AlphaDropout<>* /*layer*/) const | ||
{ | ||
return "alphadropout"; | ||
} | ||
rcurtin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
/* | ||
* Return the name of the given layer of type BatchNorm as a string. | ||
* | ||
* @param Given layer of type BatchNorm. | ||
* @return The string representation of the layer. | ||
*/ | ||
std::string LayerString(BatchNorm<>* /*layer*/) const | ||
{ | ||
return "batchnorm"; | ||
} | ||
|
||
/* | ||
* Return the name of the given layer of type Constant as a string. | ||
* | ||
* @param Given layer of type Constant. | ||
* @return The string representation of the layer. | ||
*/ | ||
std::string LayerString(Constant<>* /*layer*/) const | ||
{ | ||
return "constant"; | ||
} | ||
|
||
/* | ||
* Return the name of the given layer of type Convolution as a string. | ||
* | ||
* @param Given layer of type Convolution. | ||
* @return The string representation of the layer. | ||
*/ | ||
std::string LayerString(Convolution<>* /*layer*/) const | ||
{ | ||
return "convolution"; | ||
} | ||
|
||
/* | ||
* Return the name of the given layer of type DropConnect as a string. | ||
* | ||
* @param Given layer of type DropConnect. | ||
* @return The string representation of the layer. | ||
*/ | ||
std::string LayerString(DropConnect<>* /*layer*/) const | ||
{ | ||
return "dropconnect"; | ||
} | ||
|
||
/* | ||
* Return the name of the given layer of type Dropout as a string. | ||
* | ||
* @param Given layer of type Dropout. | ||
* @return The string representation of the layer. | ||
*/ | ||
std::string LayerString(Dropout<>* /*layer*/) const | ||
{ | ||
return "dropout"; | ||
} | ||
|
||
/* | ||
* Return the name of the given layer of type FlexibleReLU as a string. | ||
* | ||
* @param Given layer of type FlexibleReLU. | ||
* @return The string representation of the layer. | ||
*/ | ||
std::string LayerString(FlexibleReLU<>* /*layer*/) const | ||
{ | ||
return "flexiblerelu"; | ||
} | ||
|
||
/* | ||
* Return the name of the given layer of type LayerNorm as a string. | ||
* | ||
* @param Given layer of type LayerNorm. | ||
* @return The string representation of the layer. | ||
*/ | ||
std::string LayerString(LayerNorm<>* /*layer*/) const | ||
{ | ||
return "layernorm"; | ||
} | ||
|
||
/* | ||
* Return the name of the given layer of type Linear as a string. | ||
* | ||
* @param Given layer of type Linear. | ||
* @return The string representation of the layer. | ||
*/ | ||
std::string LayerString(Linear<>* /*layer*/) const | ||
{ | ||
return "linear"; | ||
} | ||
|
||
/* | ||
* Return the name of the given layer of type LinearNoBias as a string. | ||
* | ||
* @param Given layer of type LinearNoBias. | ||
* @return The string representation of the layer. | ||
*/ | ||
std::string LayerString(LinearNoBias<>* /*layer*/) const | ||
{ | ||
return "linearnobias"; | ||
} | ||
|
||
/* | ||
* Return the name of the given layer of type MaxPooling as a string. | ||
* | ||
* @param Given layer of type MaxPooling. | ||
* @return The string representation of the layer. | ||
*/ | ||
std::string LayerString(MaxPooling<>* /*layer*/) const | ||
{ | ||
return "maxpooling"; | ||
} | ||
|
||
/* | ||
* Return the name of the given layer of type MeanPooling as a string. | ||
* | ||
* @param Given layer of type MeanPooling. | ||
* @return The string representation of the layer. | ||
*/ | ||
std::string LayerString(MeanPooling<>* /*layer*/) const | ||
{ | ||
return "meanpooling"; | ||
} | ||
|
||
/* | ||
* Return the name of the given layer of type MultiplyConstant as a string. | ||
* | ||
* @param Given layer of type MultiplyConstant. | ||
* @return The string representation of the layer. | ||
*/ | ||
std::string LayerString(MultiplyConstant<>* /*layer*/) const | ||
{ | ||
return "multiplyconstant"; | ||
} | ||
|
||
/* | ||
* Return the name of the given layer of type ReLULayer as a string. | ||
* | ||
* @param Given layer of type ReLULayer. | ||
* @return The string representation of the layer. | ||
*/ | ||
std::string LayerString(ReLULayer<>* /*layer*/) const | ||
{ | ||
return "relu"; | ||
} | ||
|
||
/* | ||
* Return the name of the given layer of type TransposedConvolution as a | ||
* string. | ||
* | ||
* @param Given layer of type TransposedConvolution. | ||
* @return The string representation of the layer. | ||
*/ | ||
std::string LayerString(TransposedConvolution<>* /*layer*/) const | ||
{ | ||
return "transposedconvolution"; | ||
} | ||
|
||
/* | ||
* Return the name of the given layer of type IdentityLayer as a string. | ||
* | ||
* @param Given layer of type IdentityLayer | ||
* @return The string representation of the layer | ||
*/ | ||
std::string LayerString(IdentityLayer<>* /*layer*/) const | ||
{ | ||
return "identity"; | ||
} | ||
|
||
/* | ||
* Return the name of the given layer of type TanHLayer as a string. | ||
* | ||
* @param Given layer of type TanHLayer. | ||
* @return The string representation of the layer. | ||
*/ | ||
std::string LayerString(TanHLayer<>* /*layer*/) const | ||
{ | ||
return "tanh"; | ||
} | ||
|
||
/* | ||
* Return the name of the given layer of type ELU as a string. | ||
* | ||
* @param Given layer of type ELU. | ||
* @return The string representation of the layer. | ||
*/ | ||
std::string LayerString(ELU<>* /*layer*/) const | ||
{ | ||
return "elu"; | ||
} | ||
|
||
/* | ||
* Return the name of the given layer of type HardTanH as a string. | ||
* | ||
* @param Given layer of type HardTanH. | ||
* @return The string representation of the layer. | ||
*/ | ||
std::string LayerString(HardTanH<>* /*layer*/) const | ||
{ | ||
return "hardtanh"; | ||
} | ||
|
||
/* | ||
* Return the name of the given layer of type LeakyReLU as a string. | ||
* | ||
* @param Given layer of type LeakyReLU. | ||
* @return The string representation of the layer. | ||
*/ | ||
std::string LayerString(LeakyReLU<>* /*layer*/) const | ||
{ | ||
return "leakyrelu"; | ||
} | ||
|
||
/* | ||
* Return the name of the given layer of type PReLU as a string. | ||
* | ||
* @param Given layer of type PReLU. | ||
* @return The string representation of the layer. | ||
*/ | ||
std::string LayerString(PReLU<>* /*layer*/) const | ||
{ | ||
return "prelu"; | ||
} | ||
|
||
/* | ||
* Return the name of the given layer of type SigmoidLayer as a string. | ||
* | ||
* @param Given layer of type SigmoidLayer. | ||
* @return The string representation of the layer. | ||
*/ | ||
std::string LayerString(SigmoidLayer<>* /*layer*/) const | ||
{ | ||
return "sigmoid"; | ||
} | ||
|
||
/* | ||
* Return the name of the given layer of type LogSoftMax as a string. | ||
* | ||
* @param Given layer of type LogSoftMax. | ||
* @return The string representation of the layer. | ||
*/ | ||
std::string LayerString(LogSoftMax<>* /*layer*/) const | ||
{ | ||
return "logsoftmax"; | ||
} | ||
|
||
/* | ||
* Return the name of the layer of specified type as a string. | ||
* | ||
* @param Given layer of any type. | ||
* @return A string declaring that the layer is unsupported. | ||
*/ | ||
template<typename T> | ||
std::string LayerString(T* /*layer*/) const | ||
{ | ||
return "unsupported"; | ||
} | ||
|
||
//! Overload function call. | ||
std::string operator()(MoreTypes layer) const | ||
{ | ||
return layer.apply_visitor(*this); | ||
} | ||
|
||
//! Overload function call. | ||
template<typename LayerType> | ||
std::string operator()(LayerType* layer) const | ||
rcurtin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
return LayerString(layer); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you write a simple test for the visitor? Similar to https://github.com/mlpack/mlpack/blob/master/src/mlpack/tests/ann_visitor_test.cpp
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, I'll get it done tomorrow, pushing the changes here for now