diff --git a/notebooks/FINN-HowToTransformationPass.ipynb b/notebooks/FINN-HowToTransformationPass.ipynb index d6b1a27537eb27191bc0ffc266c64fb6a1350915..f137f1a2d31be32dc69a55162455459e8ff8ffd6 100644 --- a/notebooks/FINN-HowToTransformationPass.ipynb +++ b/notebooks/FINN-HowToTransformationPass.ipynb @@ -8,7 +8,64 @@ "--------------------------------------\n", "* <font size=\"3\">changes (transforms) the given graph</font>\n", "* <font size=\"3\">input: ModelWrapper</font>\n", - "* <font size=\"3\">returns the changed model and flag `model_was_changed`</font>" + "* <font size=\"3\">returns the changed model (ModelWrapper) and flag `model_was_changed`</font>" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## General Information\n", + "-----------------------------\n", + "<font size=\"3\">Transformation passes have a base class and must inherit from that. Transformations are meant to be applied using .transform function from the ModelWrapper. This function makes a deep copy of the input model by default. The next cell shows .transform of ModelWrapper. </font>\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### .transform() from ModelWrapper\n", + "`def transform(self, transformation, make_deepcopy=True): \n", + " transformed_model = self\n", + " if make_deepcopy:\n", + " transformed_model = copy.deepcopy(self)\n", + " model_was_changed = True\n", + " while model_was_changed:\n", + " (transformed_model, model_was_changed) = transformation.apply(\n", + " transformed_model\n", + " )\n", + " return transformed_model`" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "<font size=\"3\">When the function is called, the model, the name of the transformation and, if required, the flag make_deepcopy are passed. It is also possible not to make a copy of the model. In this case `make_deepcopy` must be set to False. Then the branch `if make_deepcopy:` would not be taken and no copy of the model would be made. \n", + "\n", + "The unchanged model is first passed to the variable `transformed_model` to pass this variable on to the transformation later. \n", + "\n", + "`model_was_changed` indicates whether the transformation needs to be applied more then once. Because it needs to be applied at least one time `model_was_changed` is first set to True and then depending on the return values of the transformation function the transformation can be applied more then once. \n", + "\n", + "**Important**: Due to the structure of this function, `model_was_changed` must be set to False at some point. Otherwise the loop is infinite.\n", + " \n", + "\n", + "Each new transformation must correspond to the scheme of the base class and contain at least the function `apply(model)`, which returns the changed model and a bool value for `model_was_changed`.\n", + "</font>" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example - \n", + "-----------------------------\n", + "<font size=\"3\">text</font>" ] }, {