/** This allows connecting a layer to the backbone */
sub_in_out.insert(
std::make_pair(prefix, graph.getNode(graph.size() - 1)->getName()));
+
+ /** @todo Update shared_from node name as well */
+ /** @todo Add test for this */
}
void NetworkGraph::addLayer(std::shared_ptr<LayerNode> layer) {
/**
* @brief Get the Weight Gradient tensor object
*
+ * @note this method returns the fresh gradient to be filled
* @param idx Identifier of the weight
* @return Tensor& Reference to the weight grad tensor
*/
}
};
+class SharedFrom : public Name {
+public:
+ static constexpr const char *key = "shared_from"; /**< unique key to access */
+ using prop_tag = str_prop_tag; /**< property type */
+};
+
} // namespace props
/**
layer(std::move(l)),
run_context(nullptr),
layer_node_props(new PropsType(props::Name(), props::Distribute(),
- props::Trainable(), {}, {})),
+ props::Trainable(), {}, {},
+ props::SharedFrom())),
layer_node_props_realization(
new RealizationPropsType(props::Flatten(), props::Activation())),
loss(new props::Loss()),
return flatten.get();
}
+std::string LayerNode::getSharedFrom() const {
+ auto &shared_from = std::get<props::SharedFrom>(*layer_node_props);
+ return shared_from.empty() ? "" : shared_from.get();
+}
+
bool LayerNode::getDistribute() const {
auto &distribute = std::get<props::Distribute>(*layer_node_props);
if (distribute.empty()) {
class InputLayer;
class InputShape;
class Activation;
+class SharedFrom;
} // namespace props
/**
bool getFlatten() const;
/**
+ * @brief Get the Shared From property of the layer node
+ *
+ * @return std::string node name where the weights are borrowed
+ */
+ std::string getSharedFrom() const;
+
+ /**
* @brief get distribute for this layer
* @retval dist to enable/disable distribute
*/
using PropsType =
std::tuple<props::Name, props::Distribute, props::Trainable,
- std::vector<props::InputLayer>, std::vector<props::InputShape>>;
+ std::vector<props::InputLayer>, std::vector<props::InputShape>,
+ props::SharedFrom>;
using RealizationPropsType = std::tuple<props::Flatten, props::Activation>;
/** these realization properties results in addition of new layers, hence
void Exporter::saveTflResult(
const std::tuple<props::Name, props::Distribute, props::Trainable,
std::vector<props::InputLayer>,
- std::vector<props::InputShape>> &props,
+ std::vector<props::InputShape>, props::SharedFrom> &props,
const LayerNode *self) {
createIfNull(tf_node);
tf_node->setLayerNode(*self);
class WeightRegularizerConstant;
class WeightInitializer;
class BiasInitializer;
+class SharedFrom;
} // namespace props
class LayerNode;
void Exporter::saveTflResult(
const std::tuple<props::Name, props::Distribute, props::Trainable,
std::vector<props::InputLayer>,
- std::vector<props::InputShape>> &props,
+ std::vector<props::InputShape>, props::SharedFrom> &props,
const LayerNode *self);
class LayerImpl;