};
/**
+ * @brief trainable property, use this to set and check how if certain layer is
+ * trainable
+ *
+ */
+class Trainable : public nntrainer::Property<bool> {
+public:
+ /**
+ * @brief Construct a new Trainable object
+ *
+ */
+ Trainable(bool val = true) : nntrainer::Property<bool>(val) {}
+ static constexpr const char *key = "trainable";
+ using prop_tag = bool_prop_tag;
+};
+
+/**
* @brief RAII class to define the connection spec
*
*/
if (!weights[idx]->getTrainable())
throw std::invalid_argument(
"Requesting gradient for a non-trainable weight.");
- if (!trainable)
- throw std::invalid_argument(
- "Requesting gradient for a non-trainable layer.");
return weights[idx]->getGradientRef();
}
*/
unsigned int getNumWeights() const { return weights.size(); }
- /**
- * @brief Get the if the layer is trainable
- *
- * @return bool true if trainable, else false
- */
- bool getTrainable() { return trainable; }
-
private:
std::tuple<props::Name> props; /**< props of the layer */
- bool trainable; /**< if the layer is trainable */
std::vector<Weight *> weights; /**< weights of the layer */
std::vector<Var_Grad *> inputs; /**< inputs of the layer */
#include <string>
#include <vector>
+#include <common_properties.h>
#include <nntrainer_error.h>
#include <nntrainer_log.h>
#include <node_exporter.h>
LayerImpl::LayerImpl() :
finalized(false),
- layer_impl_props(std::make_unique<std::tuple<>>()) {}
+ layer_impl_props(std::make_unique<std::tuple<props::Trainable>>()) {}
void LayerImpl::finalize(InitContext &context) {
NNTR_THROW_IF(finalized, nntrainer::exception::not_supported)
finalized = true;
}
-void LayerImpl::setProperty(const std::vector<std::string> &values) {}
+void LayerImpl::setProperty(const std::vector<std::string> &values) {
+ loadProperties(values, *layer_impl_props);
+}
void LayerImpl::exportTo(Exporter &exporter,
const ExportMethods &method) const {}
class Exporter;
enum class ExportMethods;
+
+namespace props {
+class Trainable;
+}
+
/**
* @class An abstract class to ease developing a layer
* @brief An abstract class for all layers
const ExportMethods &method) const override;
private:
- bool finalized; /**< check if finalized */
- std::unique_ptr<std::tuple<>> layer_impl_props; /**< layer_impl_props */
+ bool finalized; /**< check if finalized */
+ std::unique_ptr<std::tuple<props::Trainable>>
+ layer_impl_props; /**< layer_impl_props */
};
} // namespace nntrainer