diff --git a/aidge_core/aidge_export_aidge/__init__.py b/aidge_core/aidge_export_aidge/__init__.py index 6dc611fc4e55450390cf2683dee0d8d4b1aa7169..c5d6f96b3300c0e86147baac30d7cae8a3a0b798 100644 --- a/aidge_core/aidge_export_aidge/__init__.py +++ b/aidge_core/aidge_export_aidge/__init__.py @@ -1,4 +1,3 @@ - from pathlib import Path # Constants diff --git a/aidge_core/aidge_export_aidge/export.py b/aidge_core/aidge_export_aidge/export.py index d2320aa0c383c7e26c7d7eaca7dcc12c0b63de9d..417e3e9538f16a4e487acc6157213d1645f88f70 100644 --- a/aidge_core/aidge_export_aidge/export.py +++ b/aidge_core/aidge_export_aidge/export.py @@ -1,6 +1,7 @@ import aidge_core import shutil import os +from pathlib import Path from .utils import supported_operators, OPERATORS_REGISTRY from . import ROOT_EXPORT @@ -9,12 +10,12 @@ from . import ROOT_EXPORT def export(export_folder: str, graphview: aidge_core.GraphView, scheduler: aidge_core.Scheduler): - + export_folder_path = Path(export_folder) # Create export directory os.makedirs(export_folder, exist_ok=True) # Cpy static files - shutil.copytree(ROOT_EXPORT / "static/", export_folder, dirs_exist_ok=True) + shutil.copytree(ROOT_EXPORT / "static/", export_folder_path, dirs_exist_ok=True) ordered_nodes = scheduler.get_static_scheduling() @@ -27,7 +28,7 @@ def export(export_folder: str, op = OPERATORS_REGISTRY[node.type()](node) # Export the configuration - list_configs = op.export(export_folder, list_configs) + list_configs = op.export(export_folder_path, list_configs) # Add forward kernel list_actions = op.forward(list_actions) @@ -38,8 +39,8 @@ def export(export_folder: str, # Generate full dnn.cpp aidge_core.generate_file( - f"{export_folder}/src/dnn.cpp", - str(ROOT_EXPORT) + "/templates/dnn.jinja", + export_folder_path / "src/dnn.cpp", + ROOT_EXPORT / "templates/dnn.jinja", headers=list_configs, operators=set_operator, actions=list_actions, diff --git a/aidge_core/aidge_export_aidge/operator_export/conv.py b/aidge_core/aidge_export_aidge/operator_export/conv.py index e3ce0ff98cb49b4c6a0743188d2e0405b90ca284..52558980bd3d943e6e8fc0144f37b2f06d4231a4 100644 --- a/aidge_core/aidge_export_aidge/operator_export/conv.py +++ b/aidge_core/aidge_export_aidge/operator_export/conv.py @@ -2,7 +2,7 @@ from aidge_core.aidge_export_aidge.utils import operator_register, parse_node_in from aidge_core.aidge_export_aidge import ROOT_EXPORT from aidge_core import ExportNode, generate_file, generate_str import os - +from pathlib import Path @operator_register("Conv") class Conv(ExportNode): @@ -10,11 +10,10 @@ class Conv(ExportNode): super().__init__(node) - def export(self, export_folder:str, list_configs:list): + def export(self, export_folder:Path, list_configs:list): - name = f"{self.name}" - include_path = f"attributes/{name}.hpp" - filepath = f"{export_folder}/include/{include_path}" + include_path = f"attributes/{self.name}.hpp" + filepath = export_folder / f"include/{include_path}" dirname = os.path.dirname(filepath) # If directory doesn't exist, create it @@ -22,7 +21,7 @@ class Conv(ExportNode): generate_file( filepath, - str(ROOT_EXPORT) + "/templates/attributes/conv.jinja", + ROOT_EXPORT / "templates/attributes/conv.jinja", name=self.name, **self.attributes ) @@ -31,7 +30,7 @@ class Conv(ExportNode): def forward(self, list_actions:list): list_actions.append(generate_str( - str(ROOT_EXPORT) + "/templates/graph_ctor/conv.jinja", + ROOT_EXPORT /"templates/graph_ctor/conv.jinja", name=self.name, inputs=parse_node_input(self.node.inputs()), **self.attributes diff --git a/aidge_core/aidge_export_aidge/operator_export/fc.py b/aidge_core/aidge_export_aidge/operator_export/fc.py index 0d0d60ea10bcc1b74dc3f827dbe2d192486df182..af17486911531144c3f63a83a20ebabffecff735 100644 --- a/aidge_core/aidge_export_aidge/operator_export/fc.py +++ b/aidge_core/aidge_export_aidge/operator_export/fc.py @@ -2,7 +2,7 @@ from aidge_core.aidge_export_aidge.utils import operator_register,parse_node_inp from aidge_core.aidge_export_aidge import ROOT_EXPORT from aidge_core import ExportNode, generate_file, generate_str import os - +from pathlib import Path @operator_register("FC") class FC(ExportNode): @@ -10,11 +10,11 @@ class FC(ExportNode): super().__init__(node) - def export(self, export_folder:str, list_configs:list): + def export(self, export_folder:Path, list_configs:list): + - name = f"{self.name}" - include_path = f"attributes/{name}.hpp" - filepath = f"{export_folder}/include/{include_path}" + include_path = f"attributes/{self.name}.hpp" + filepath = export_folder / f"include/{include_path}" dirname = os.path.dirname(filepath) # If directory doesn't exist, create it @@ -22,7 +22,7 @@ class FC(ExportNode): generate_file( filepath, - str(ROOT_EXPORT) + "/templates/attributes/fc.jinja", + ROOT_EXPORT / "templates/attributes/fc.jinja", name=self.name, InChannels=self.inputs_dims[1][1], **self.attributes @@ -32,7 +32,7 @@ class FC(ExportNode): def forward(self, list_actions:list): list_actions.append(generate_str( - str(ROOT_EXPORT) + "/templates/graph_ctor/fc.jinja", + ROOT_EXPORT / "templates/graph_ctor/fc.jinja", name=self.name, inputs=parse_node_input(self.node.inputs()), **self.attributes diff --git a/aidge_core/aidge_export_aidge/operator_export/maxpooling.py b/aidge_core/aidge_export_aidge/operator_export/maxpooling.py index ad26fa3c68c193213f56ff7d15939a6368808938..a88d31b1aa655f107c97edc4a96f37c9decf99a9 100644 --- a/aidge_core/aidge_export_aidge/operator_export/maxpooling.py +++ b/aidge_core/aidge_export_aidge/operator_export/maxpooling.py @@ -2,7 +2,7 @@ from aidge_core.aidge_export_aidge.utils import operator_register, parse_node_in from aidge_core.aidge_export_aidge import ROOT_EXPORT from aidge_core import ExportNode, generate_file, generate_str import os - +from pathlib import Path @operator_register("MaxPooling") class MaxPooling(ExportNode): @@ -10,11 +10,10 @@ class MaxPooling(ExportNode): super().__init__(node) - def export(self, export_folder:str, list_configs:list): + def export(self, export_folder:Path, list_configs:list): - name = f"{self.name}" - include_path = f"attributes/{name}.hpp" - filepath = f"{export_folder}/include/{include_path}" + include_path = f"attributes/{self.name}.hpp" + filepath = export_folder / f"include/{include_path}" dirname = os.path.dirname(filepath) # If directory doesn't exist, create it @@ -22,7 +21,7 @@ class MaxPooling(ExportNode): generate_file( filepath, - str(ROOT_EXPORT) + "/templates/attributes/maxpooling.jinja", + ROOT_EXPORT / "templates/attributes/maxpooling.jinja", name=self.name, **self.attributes ) @@ -31,7 +30,7 @@ class MaxPooling(ExportNode): def forward(self, list_actions:list): list_actions.append(generate_str( - str(ROOT_EXPORT) + "/templates/graph_ctor/maxpooling.jinja", + ROOT_EXPORT / "templates/graph_ctor/maxpooling.jinja", name=self.name, inputs=parse_node_input(self.node.inputs()), **self.attributes diff --git a/aidge_core/aidge_export_aidge/operator_export/producer.py b/aidge_core/aidge_export_aidge/operator_export/producer.py index c8435db173f6f87d7bfbc68276e5908f5ee47d52..4d8e6fe1c0831a0546b294f801a28d9c86541cf1 100644 --- a/aidge_core/aidge_export_aidge/operator_export/producer.py +++ b/aidge_core/aidge_export_aidge/operator_export/producer.py @@ -3,6 +3,7 @@ from aidge_core.aidge_export_aidge import ROOT_EXPORT from aidge_core import ExportNode, generate_file, generate_str import numpy as np import os +from pathlib import Path @operator_register("Producer") @@ -17,20 +18,21 @@ class Producer(ExportNode): self.tensor_name = f"{child.name()}_{in_idx}" self.values = np.array(self.operator.get_output(0)) - def export(self, export_folder:str, list_configs:list): + def export(self, export_folder:Path, list_configs:list): assert(len(self.node.output(0)) == 1) include_path = f"parameters/{self.tensor_name}.hpp" - filepath = f"{export_folder}/include/{include_path}" + filepath = export_folder / f"include/{include_path}" dirname = os.path.dirname(filepath) # If directory doesn't exist, create it if not os.path.exists(dirname): os.makedirs(dirname) + aidge_tensor = self.operator.get_output(0) generate_file( filepath, - str(ROOT_EXPORT) + "/templates/parameter.jinja", + ROOT_EXPORT / "templates/parameter.jinja", dims = aidge_tensor.dims(), data_t = "float", # TODO : get data from producer name = self.tensor_name, diff --git a/aidge_core/aidge_export_aidge/operator_export/relu.py b/aidge_core/aidge_export_aidge/operator_export/relu.py index 0d18e6a7409f406aec5bfd19c2f559d674aea5ad..c0f4f6afdc35737a8967f51c1859bda0c9773f88 100644 --- a/aidge_core/aidge_export_aidge/operator_export/relu.py +++ b/aidge_core/aidge_export_aidge/operator_export/relu.py @@ -1,19 +1,19 @@ from aidge_core.aidge_export_aidge.utils import operator_register, parse_node_input from aidge_core import ExportNode, generate_str from aidge_core.aidge_export_aidge import ROOT_EXPORT +from pathlib import Path @operator_register("ReLU") class ReLU(ExportNode): def __init__(self, node): super().__init__(node) - - def export(self, export_folder:str, list_configs:list): + def export(self, export_folder:Path, list_configs:list): return list_configs def forward(self, list_actions:list): list_actions.append(generate_str( - str(ROOT_EXPORT) + "/templates/graph_ctor/relu.jinja", + ROOT_EXPORT / "templates/graph_ctor/relu.jinja", name=self.name, inputs=parse_node_input(self.node.inputs()), **self.attributes