def graph_persistence_onnx(): """ See :ref:`onnxsklearnconsortiumrst`. """ return draw_diagram(""" blockdiag { default_fontsize = 20; node_width = 200; node_height = 100; model[label="trained model\\nscikit-learn"]; onnx[label="ONNX model"]; rest[label="ONNX runtime", textcolor="#00AAAA"]; onnx -> rest; pred[label="predictions"]; notrain[label="cannot train", color="#FF0000"]; group { label = "machine 1"; color = "#FFAAAA"; model -> onnx[label="conversion"]; onnx; } group { label = "machine 2"; color = "#AAFFAA"; rest ; pred; rest -> pred; rest -> notrain[folded]; } }""")
def draw_design(self): """ Returns an image with all pipes and connectors. """ display("Drawing diagram using blockdiag") block_diag_print = ( 'blockdiag {default_shape = roundedbox; default_group_color = "#FFFFFF"; orientation ="portrait"\n ' + self.diagram_definition + self.diagram_notes + "\n}\n ") logger.info("Using definition for blockdiag: %s", block_diag_print) img2 = draw_diagram(block_diag_print) display(img2)
def graph_three_components(): """ See :ref:`onnxsklearnconsortiumrst`. """ return draw_diagram(""" blockdiag { default_fontsize = 20; node_width = 200; node_height = 100; onnx[label="ONNX\\n\\nset of mathematical functions", color="#FFFF00"]; conv[label="converter\\n\\nsklearn-onnx", color="#FFFF00"]; run[label="runtime\\n\\nonnxruntime\\nonnx.js\\n...", color="#FFFF00"]; onnx -> conv -> run ; }""")
def test_draw_diagram_pillow(self): fLOG( __file__, self._testMethodName, OutputPrint=__name__ == "__main__") code = """ blockdiag { A -> B -> C -> D; A -> E -> F -> G; } """.replace(" ", "") img = draw_diagram(code, format="pillow") self.assertTrue(img, Image) self.assertEqual(img.size, (832, 200))
def test_draw_diagram_svg(self): fLOG( __file__, self._testMethodName, OutputPrint=__name__ == "__main__") code = """ blockdiag { A -> B -> C -> D; A -> E -> F -> G; } """.replace(" ", "") img = draw_diagram(code, format="svg") self.assertTrue(img, str) self.assertTrue( '<rect fill="rgb(0,0,0)" height="40" stroke="rgb(0,0,0)"' in img)
def test_draw_diagram_png(self): fLOG( __file__, self._testMethodName, OutputPrint=__name__ == "__main__") code = """ blockdiag { A -> B -> C -> D; A -> E -> F -> G; } """.replace(" ", "") img = draw_diagram(code, format="png") temp = get_temp_folder(__file__, "temp_draw_diagram_png") name = os.path.join(temp, "image.png") with open(name, "wb") as f: f.write(img)
def graph_persistence_pickle_issues(): """ See :ref:`onnxsklearnconsortiumrst`. """ return draw_diagram(""" blockdiag { default_fontsize = 20; node_width = 200; node_height = 100; pkl[label="pickled model"]; rest[label="restored model\\nscikit-learn\\nUNSTABLE", textcolor="#00AAAA"]; pkl -> rest; pred[label="predictions\\nSLOW"]; train[label="training"]; group { label = "machine 1"; color = "#FFAAAA"; pkl; } group { label = "machine 2"; color = "#AAFFAA"; rest -> pred; rest -> train; } }""")
def create_tree_image(string): img = draw_diagram("blockdiag {\n" + string + "\n}") img.save("mlAssignment2DecisionTree.png")