Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 22 additions & 9 deletions src/SOFIE_core/test/Conv1dModelGenerator.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,17 @@

### generate COnv2d model using Pytorch

import sys
import os
import logging
import numpy as np
import argparse
import torch
import torch.nn as nn
import torch.nn.functional as F

logging.basicConfig(level=logging.INFO, format="%(levelname)s: %(message)s")


result = []

Expand Down Expand Up @@ -132,12 +137,21 @@ def main():
torch.save({'model_state_dict':model.state_dict()}, name + ".pt")

if saveOnnx:
torch.onnx.export(
onnx_file = name + ".onnx"
try:
torch.onnx.export(
model,
xinput,
name + ".onnx",
onnx_file,
export_params=True
)
)
except Exception as e:
logging.error("Failed to export ONNX model %s: %s", onnx_file, e)
sys.exit(1)
if not os.path.isfile(onnx_file) or os.path.getsize(onnx_file) == 0:
logging.error("ONNX file %s was not created or is empty", onnx_file)
sys.exit(1)
logging.info("Exported %s", onnx_file)

if loadModel :
print('Loading model from file....')
Expand All @@ -156,12 +170,11 @@ def main():
# for i in range(0,outSize):
# print(float(yvec[i]))

f = open(name + ".out", "w")
for i in range(0,outSize):
f.write(str(float(yvec[i]))+" ")



with open(name + ".out", "w") as f:
for i in range(0,outSize):
f.write(str(float(yvec[i]))+" ")
logging.info("Wrote %s.out", name)


if __name__ == '__main__':
main()
31 changes: 22 additions & 9 deletions src/SOFIE_core/test/Conv2dModelGenerator.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,17 @@

### generate COnv2d model using Pytorch

import sys
import os
import logging
import numpy as np
import argparse
import torch
import torch.nn as nn
import torch.nn.functional as F

logging.basicConfig(level=logging.INFO, format="%(levelname)s: %(message)s")


result = []

Expand Down Expand Up @@ -134,12 +139,21 @@ def main():
torch.save({'model_state_dict':model.state_dict()}, name + ".pt")

if saveOnnx:
torch.onnx.export(
onnx_file = name + ".onnx"
try:
torch.onnx.export(
model,
xinput,
name + ".onnx",
onnx_file,
export_params=True
)
)
except Exception as e:
logging.error("Failed to export ONNX model %s: %s", onnx_file, e)
sys.exit(1)
if not os.path.isfile(onnx_file) or os.path.getsize(onnx_file) == 0:
logging.error("ONNX file %s was not created or is empty", onnx_file)
sys.exit(1)
logging.info("Exported %s", onnx_file)

if loadModel :
print('Loading model from file....')
Expand All @@ -158,12 +172,11 @@ def main():
# for i in range(0,outSize):
# print(float(yvec[i]))

f = open(name + ".out", "w")
for i in range(0,outSize):
f.write(str(float(yvec[i]))+" ")



with open(name + ".out", "w") as f:
for i in range(0,outSize):
f.write(str(float(yvec[i]))+" ")
logging.info("Wrote %s.out", name)


if __name__ == '__main__':
main()
31 changes: 22 additions & 9 deletions src/SOFIE_core/test/Conv3dModelGenerator.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,17 @@

### generate COnv2d model using Pytorch

import sys
import os
import logging
import numpy as np
import argparse
import torch
import torch.nn as nn
import torch.nn.functional as F

logging.basicConfig(level=logging.INFO, format="%(levelname)s: %(message)s")


result = []

Expand Down Expand Up @@ -143,12 +148,21 @@ def main():
torch.save({'model_state_dict':model.state_dict()}, name + ".pt")

if saveOnnx:
torch.onnx.export(
onnx_file = name + ".onnx"
try:
torch.onnx.export(
model,
xinput,
name + ".onnx",
onnx_file,
export_params=True
)
)
except Exception as e:
logging.error("Failed to export ONNX model %s: %s", onnx_file, e)
sys.exit(1)
if not os.path.isfile(onnx_file) or os.path.getsize(onnx_file) == 0:
logging.error("ONNX file %s was not created or is empty", onnx_file)
sys.exit(1)
logging.info("Exported %s", onnx_file)

if loadModel :
print('Loading model from file....')
Expand All @@ -167,12 +181,11 @@ def main():
# for i in range(0,outSize):
# print(float(yvec[i]))

f = open(name + ".out", "w")
for i in range(0,outSize):
f.write(str(float(yvec[i]))+" ")



with open(name + ".out", "w") as f:
for i in range(0,outSize):
f.write(str(float(yvec[i]))+" ")
logging.info("Wrote %s.out", name)


if __name__ == '__main__':
main()
29 changes: 21 additions & 8 deletions src/SOFIE_core/test/ConvTrans2dModelGenerator.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,17 @@

### generate COnv2d model using Pytorch

import sys
import os
import logging
import numpy as np
import argparse
import torch
import torch.nn as nn
import torch.nn.functional as F

logging.basicConfig(level=logging.INFO, format="%(levelname)s: %(message)s")


result = []

Expand Down Expand Up @@ -137,12 +142,21 @@ def main():
torch.save({'model_state_dict':model.state_dict()}, name + ".pt")

if saveOnnx:
torch.onnx.export(
onnx_file = name + ".onnx"
try:
torch.onnx.export(
model,
xinput,
name + ".onnx",
onnx_file,
export_params=True
)
)
except Exception as e:
logging.error("Failed to export ONNX model %s: %s", onnx_file, e)
sys.exit(1)
if not os.path.isfile(onnx_file) or os.path.getsize(onnx_file) == 0:
logging.error("ONNX file %s was not created or is empty", onnx_file)
sys.exit(1)
logging.info("Exported %s", onnx_file)

if loadModel :
print('Loading model from file....')
Expand All @@ -161,11 +175,10 @@ def main():
# for i in range(0,outSize):
# print(float(yvec[i]))

f = open(name + ".out", "w")
for i in range(0,outSize):
f.write(str(float(yvec[i]))+" ")


with open(name + ".out", "w") as f:
for i in range(0,outSize):
f.write(str(float(yvec[i]))+" ")
logging.info("Wrote %s.out", name)


if __name__ == '__main__':
Expand Down
28 changes: 21 additions & 7 deletions src/SOFIE_core/test/LinearModelGenerator.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,17 @@

### generate COnv2d model using Pytorch

import sys
import os
import logging
import numpy as np
import argparse
import torch
import torch.nn as nn
import torch.nn.functional as F

logging.basicConfig(level=logging.INFO, format="%(levelname)s: %(message)s")


result = []

Expand Down Expand Up @@ -120,12 +125,21 @@ def main():
torch.save({'model_state_dict':model.state_dict()}, name + ".pt")

if saveOnnx:
torch.onnx.export(
onnx_file = name + ".onnx"
try:
torch.onnx.export(
model,
xinput,
name + ".onnx",
onnx_file,
export_params=True
)
)
except Exception as e:
logging.error("Failed to export ONNX model %s: %s", onnx_file, e)
sys.exit(1)
if not os.path.isfile(onnx_file) or os.path.getsize(onnx_file) == 0:
logging.error("ONNX file %s was not created or is empty", onnx_file)
sys.exit(1)
logging.info("Exported %s", onnx_file)

if loadModel :
print('Loading model from file....')
Expand All @@ -143,10 +157,10 @@ def main():
yvec = y.reshape([outSize])


f = open(name + ".out", "w")
for i in range(0,outSize):
f.write(str(float(yvec[i]))+" ")

with open(name + ".out", "w") as f:
for i in range(0,outSize):
f.write(str(float(yvec[i]))+" ")
logging.info("Wrote %s.out", name)


if __name__ == '__main__':
Expand Down
31 changes: 22 additions & 9 deletions src/SOFIE_core/test/RecurrentModelGenerator.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,17 @@

### generate COnv2d model using Pytorch

import sys
import os
import logging
import numpy as np
import argparse
import torch
import torch.nn as nn
import torch.nn.functional as F

logging.basicConfig(level=logging.INFO, format="%(levelname)s: %(message)s")


result = []
verbose=False
Expand Down Expand Up @@ -132,12 +137,21 @@ def main():
torch.save({'model_state_dict':model.state_dict()}, name + ".pt")

if saveOnnx:
torch.onnx.export(
onnx_file = name + ".onnx"
try:
torch.onnx.export(
model,
xinput,
name + ".onnx",
onnx_file,
export_params=True
)
)
except Exception as e:
logging.error("Failed to export ONNX model %s: %s", onnx_file, e)
sys.exit(1)
if not os.path.isfile(onnx_file) or os.path.getsize(onnx_file) == 0:
logging.error("ONNX file %s was not created or is empty", onnx_file)
sys.exit(1)
logging.info("Exported %s", onnx_file)

if loadModel :
print('Loading model from file....')
Expand All @@ -154,12 +168,11 @@ def main():
outSize = y.nelement()
yvec = y.reshape([outSize])

f = open(name + ".out", "w")
for i in range(0,outSize):
f.write(str(float(yvec[i]))+" ")



with open(name + ".out", "w") as f:
for i in range(0,outSize):
f.write(str(float(yvec[i]))+" ")
logging.info("Wrote %s.out", name)


if __name__ == '__main__':
main()