This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def main(): | |
clear_exports() | |
export_test() | |
optimize_model("test") | |
convert_blob("test") | |
pipeline = setup_pipeline() | |
run_pipeline(pipeline) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Test(nn.Module): | |
def __init__(self): | |
super().__init__() | |
def forward(self, x): | |
return x / 2 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def export_test(): | |
image = torch.ones((1, 3, 256, 256), requires_grad = False) | |
model = Test() | |
torch.onnx.export(model, image, "exports/test.onnx", | |
export_params = True, | |
opset_version = 11, | |
do_constant_folding = True, | |
input_names = ['input'], | |
output_names = ['output'] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def optimize_model(name): | |
optimizer_path = "/opt/intel/openvino_2020.1.023/" + \ | |
"deployment_tools/model_optimizer/mo.py" | |
subprocess.run(["python3", optimizer_path, | |
"--input_model", f"./exports/{name}.onnx", | |
"--data_type", "FP16"]) | |
os.rename(name + ".bin", os.path.join("./exports", name + ".bin")) | |
os.rename(name + ".xml", os.path.join("./exports", name + ".xml")) | |
os.rename(name + ".mapping", os.path.join("./exports", name + ".mapping")) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import blobconverter | |
def convert_blob(name): | |
xmlfile = os.path.join("./exports", name) + ".xml" | |
binfile = os.path.join("./exports", name) + ".bin" | |
blob_path = blobconverter.from_openvino( | |
xml = xmlfile, | |
bin = binfile, | |
data_type = "FP16", |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def setup_pipeline(): | |
pipeline = depthai.Pipeline() | |
cam_rgb = pipeline.createColorCamera() | |
cam_rgb.setPreviewSize(256, 256) | |
cam_rgb.setInterleaved(False) | |
detection_nn = pipeline.createNeuralNetwork() | |
detection_nn.setBlobPath("./exports/test_openvino_2021.4_5shave.blob") | |
cam_rgb.preview.link(detection_nn.input) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def run_pipeline(pipeline): | |
with depthai.Device(pipeline) as device: | |
q_nn = device.getOutputQueue("nn", maxSize=4, blocking=False) | |
while True: | |
in_nn = q_nn.tryGet() | |
if in_nn is not None: | |
# get data | |
output = in_nn.getAllLayerNames()[-1] | |
data = np.array(in_nn.getLayerFp16(output)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from flask import Flask | |
app = Flask(__name__) | |
@app.route("/classify") | |
def classify_symbol(): | |
return {"top5": ["A", "B", "C", "D", "E"]} | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function addClassifyRequestInterval() { | |
setInterval(function() { | |
if (!shouldUpdate) { | |
return | |
} | |
shouldUpdate = false; | |
var xhttp = new XMLHttpRequest(); | |
xhttp.onreadystatechange = function() { | |
if (xhttp.readyState == 4 && xhttp.status == 200) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function addReTypesetHandler() { | |
var script = document.createElement("script"); | |
script.innerHTML = ` | |
last = "1"; | |
setInterval(function() { | |
var tag = document.getElementsByClassName("invisible")[0]; | |
if (tag.innerHTML != last) { | |
MathJax.Hub.Queue(["Typeset", MathJax.Hub]); | |
last = tag.innerHTML; | |
} |