Skip to content
Snippets Groups Projects
Commit 11a950fd authored by Cyril Moineau's avatar Cyril Moineau
Browse files

Remove all str path and use Pathlib module instead.

parent 5cd72096
No related branches found
No related tags found
2 merge requests!152Update Aidge export to take a graph view has an argument instead of a...,!115Aidge export
from pathlib import Path
# Constants
......
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,
......
......@@ -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
......
......@@ -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
......
......@@ -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
......
......@@ -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,
......
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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment