Python graphviz.Source() Examples
The following are 17
code examples of graphviz.Source().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
graphviz
, or try the search function
.
Example #1
Source File: 23_DecisionTree.py From Python with MIT License | 7 votes |
def visualize_tree(data,clf,clf_name): features = data.columns features = features[:-1] class_names = list(set(data.iloc[:,-1])) dot_data = tree.export_graphviz(clf, out_file=None, \ feature_names=features,class_names=class_names, \ filled=True, rounded=True, special_characters=True) graph = graphviz.Source(dot_data) graph.render('dtree_render_'+clf_name,view=True) # Function to perform training with giniIndex.
Example #2
Source File: tedd.py From incubator-tvm with Apache License 2.0 | 6 votes |
def dump_graph(dot_string, show_svg=True, dot_file_path='', output_dot_string=False): """Output dot_string in various formats.""" if dot_file_path: try: dot_file = open(dot_file_path, "w+") dot_file.write(dot_string) dot_file.close() except IOError: print('Cannot open file: ' + dot_file_path) if show_svg: from IPython.display import display from IPython.display import SVG src = Source(dot_string) display(SVG(src.pipe(format='svg'))) if output_dot_string: return dot_string return None
Example #3
Source File: tree.py From toad with MIT License | 6 votes |
def dot_to_img(dot, file = 'report.png'): import os name, ext = os.path.splitext(file) graph = graphviz.Source(dot) graph.format = ext[1:] graph.view(name, cleanup = True)
Example #4
Source File: load.py From coremltools with BSD 3-Clause "New" or "Revised" License | 5 votes |
def _program_from_tf_ssa(self): """Overwrites TFLoader._mil_program_from_tf_ssa()""" # Applying frontend passes on TFSSA. Note that these are different from # passes applied to MIL in TF frontend. tf_passes = [ delete_asserts, functionalize_loops, constant_propagation, cond_to_where, remove_variable_nodes, fuse_dilation_conv, ] if self.debug: for tf_pass in _tqdm( tf_passes, desc="Running TensorFlow Graph Passes", unit=" passes" ): try: tf_pass(self._tf_ssa) except Exception as e: logging.exception('Exception in pass "{}": {}'.format(tf_pass, e)) logging.info("Ignoring exception and continuing to next pass") else: for tf_pass in _tqdm( tf_passes, desc="Running TensorFlow Graph Passes", unit=" passes" ): tf_pass(self._tf_ssa) if self.debug: import graphviz dot_string = self._tf_ssa.get_dot_string( annotation=True, name_and_op_style=True, highlight_debug_nodes=[] ) graphviz.Source(dot_string).view( filename="/tmp/ssa_after_tf_passes", cleanup=True ) converter = TFConverter(self._tf_ssa, **self.kwargs) return converter.convert()
Example #5
Source File: analysis.py From llvmlite with BSD 2-Clause "Simplified" License | 5 votes |
def view_dot_graph(graph, filename=None, view=False): """ View the given DOT source. If view is True, the image is rendered and viewed by the default application in the system. The file path of the output is returned. If view is False, a graphviz.Source object is returned. If view is False and the environment is in a IPython session, an IPython image object is returned and can be displayed inline in the notebook. This function requires the graphviz package. Args ---- - graph [str]: a DOT source code - filename [str]: optional. if given and view is True, this specifies the file path for the rendered output to write to. - view [bool]: if True, opens the rendered output file. """ # Optionally depends on graphviz package import graphviz as gv src = gv.Source(graph) if view: # Returns the output file path return src.render(filename, view=view) else: # Attempts to show the graph in IPython notebook try: __IPYTHON__ except NameError: return src else: import IPython.display as display format = 'svg' return display.SVG(data=src.pipe(format)) # Ctypes binding
Example #6
Source File: vis_utils.py From QANet-PyTorch with MIT License | 5 votes |
def plot_model(model, output, fig_name, fig_format): """ Plot neural network model architecture :param model: network model :param output: network output variable :param fig_name: figure output name :param format: figure format, such as "png", "pdf" :return: dot file string """ var = make_dot(output, params=dict(model.named_parameters())) s = Source(var, filename=fig_name, format=fig_format) s.view() return var
Example #7
Source File: ontology_viz.py From ontology-visualization with MIT License | 5 votes |
def graph(self, format='svg'): try: from graphviz import Source except ImportError: raise ImportError("You don't have graphviz package installed.\n" "Please install graphviz or use write_file function to save dot file and generate the " "graph manually.") dot = self.generate() graph = Source(dot) graph.format = format return graph
Example #8
Source File: utils.py From 4lang with MIT License | 5 votes |
def draw_dep_graph(deps, out_dir, fn): dot_str = dep_to_dot(deps) src = graphviz.Source(dot_str, format='png') pic_path = src.render(filename=fn, directory=out_dir) return pic_path
Example #9
Source File: utils.py From 4lang with MIT License | 5 votes |
def draw_text_graph( words_to_machines, out_dir, fn='text', orig_machines=[]): graph = MachineGraph.create_from_machines( words_to_machines.values(), orig_machines=orig_machines) src_str = graph.to_dot().encode('utf-8') src = graphviz.Source(src_str, format='png') pic_path = src.render(filename=fn, directory=out_dir) return pic_path
Example #10
Source File: __init__.py From tributary with Apache License 2.0 | 5 votes |
def graphviz(expr): '''Plot sympy expression tree using graphviz Args: expr (sympy expression) ''' return Source(dotprint(expr))
Example #11
Source File: load.py From coremltools with BSD 3-Clause "New" or "Revised" License | 5 votes |
def load(self): """Load TensorFlow model into MIL program.""" logging.info("Loading TensorFlow model '{}'".format(self.model)) outputs = self.kwargs.get("outputs", None) self._graph_def = self._graph_def_from_model(outputs) if self._graph_def is not None and len(self._graph_def.node) == 0: msg = "tf.Graph should have at least 1 node, Got empty graph." raise ValueError(msg) self._tf_ssa = self._tf_ssa_from_graph_def() del self._graph_def gc.collect() if self.debug: import graphviz dot_string = self._tf_ssa.get_dot_string( annotation=True, name_and_op_style=True, highlight_debug_nodes=[] ) graphviz.Source(dot_string).view( filename="/tmp/ssa_before_tf_passes", cleanup=True ) program = self._program_from_tf_ssa() logging.debug("program:\n{}".format(program)) return program # @abstractmethod
Example #12
Source File: dtree.py From Python with MIT License | 5 votes |
def visualize_tree(data,clf,clf_name): features = data.columns features = features[:-1] class_names = list(set(data.iloc[:,-1])) dot_data = tree.export_graphviz(clf, out_file=None, feature_names=features,class_names=class_names, filled=True, rounded=True, special_characters=True) graph = graphviz.Source(dot_data) graph.render('dtree_render_'+clf_name,view=True) # Function to perform training with giniIndex.
Example #13
Source File: ComponentDiGraphHTMLRenderer.py From scattertext with Apache License 2.0 | 5 votes |
def get_svg(self, dot_str): import graphviz as gv return gv.Source(dot_str, format='svg', engine=self.engine).pipe().decode('utf-8')
Example #14
Source File: tiles.py From mars with Apache License 2.0 | 5 votes |
def visualize(self, graph_attrs=None, node_attrs=None, **kw): from graphviz import Source g = self.build_graph(**kw) dot = g.to_dot(graph_attrs=graph_attrs, node_attrs=node_attrs, result_chunk_keys={c.key for c in self.chunks}) return Source(dot)
Example #15
Source File: topological.py From rankeval with Mozilla Public License 2.0 | 5 votes |
def plot_tree(dot_data): return graphviz.Source(dot_data)
Example #16
Source File: reduce_transposes.py From coremltools with BSD 3-Clause "New" or "Revised" License | 4 votes |
def apply_transform(self): """ Take in the data collected during graph traversal and transform the graph by cancelling out transpose ops that can be removed. """ logging.debug( "Block before optimize transpose transform:\n{}".format(self.block) ) if DEBUG: import graphviz graphviz.Source( self.block.get_dot_string( highlight_debug_op_names=[], highlight_debug_op_types=["transpose"] ) ).view(filename="/tmp/block_before_reduce_transpose") """ First check which transposes can be cancelled. After this function call we get an updated dictionary "transpose_op_to_cancel_ops" with only the transpose ops that can really be cancelled in the graph Reasons to not cancel: - materialize_ops are greater than cancel_ops, so removing transpose will instead end up increasing the count of transposes - removing a transpose op can only be successful, if all of its cancel ops are removed, removing all the cancel ops is only successful if all of their starting transpose ops are removed and so on. This check is also done in "_verify_cancellable_transposes()" """ self._verify_cancellable_transposes() # apply transform for transpose_op in self.transpose_op_to_cancel_ops: self._remove_transpose_ops(transpose_op) if DEBUG: graphviz.Source( self.block.get_dot_string( highlight_debug_op_names=[], highlight_debug_op_types=["transpose"] ) ).view(filename="/tmp/block_after_reduce_transpose") logging.debug( "Block after optimize transpose transform:\n{}".format(self.block) ) for op in self.block.operations: op.type_value_inference(overwrite_output=True)
Example #17
Source File: load.py From coremltools with BSD 3-Clause "New" or "Revised" License | 4 votes |
def _program_from_tf_ssa(self): # Notes: # - "flatten_while_loop_namespaces" should be after "constant_propagation" # as it changes node names which constant propagation pass is relying on # to perform session.run(), renamed nodes are not understandable for TF. tf_passes = [ # delete_asserts, # FIXME: rdar://62472804 constant_propagation, rewrite_control_flow_functions, flatten_sub_graph_namespaces, remove_variable_nodes, fuse_dilation_conv, ] if self.debug: for tf_pass in _tqdm( tf_passes, desc="Running TensorFlow Graph Passes", unit=" passes" ): try: tf_pass(self._tf_ssa) except Exception as e: _logging.exception('Exception in pass "{}": {}'.format(tf_pass, e)) _logging.info("Ignoring exception and continuing to next pass") else: for tf_pass in _tqdm( tf_passes, desc="Running TensorFlow Graph Passes", unit=" passes" ): tf_pass(self._tf_ssa) if self.debug: import graphviz dot_string = self._tf_ssa.get_dot_string( annotation=True, name_and_op_style=True, highlight_debug_nodes=[] ) graphviz.Source(dot_string).view( filename="/tmp/ssa_after_tf_passes", cleanup=True ) converter = TF2Converter(self._tf_ssa, **self.kwargs) return converter.convert()