/usr/local/lib64/python3.6/site-packages/caffe2/python
NameSizeModeActions
docs/-0755rm
examples/-0755rm
fakelowp/-0755rm
helpers/-0755rm
ideep/-0755rm
layers/-0755rm
mint/-0755rm
mkl/-0755rm
modeling/-0755rm
models/-0755rm
onnx/-0755rm
operator_test/-0755rm
predictor/-0755rm
rnn/-0755rm
serialized_test/-0755rm
test/-0755rm
trt/-0755rm
__pycache__/-0755rm
allcompare_test.py22550644editdlrm
attention.py123590644editdlrm
benchmark_generator.py49120644editdlrm
binarysize.py55210644editdlrm
brew.py47620644editdlrm
brew_test.py117390644editdlrm
build.py1530644editdlrm
cached_reader.py43940644editdlrm
caffe2_pybind11_state.cpython-36m-x86_64-linux-gnu.so482997120755editdlrm
caffe2_pybind11_state_gpu.cpython-36m-x86_64-linux-gnu.so490481440755editdlrm
caffe_translator.py352270644editdlrm
caffe_translator_test.py35530644editdlrm
checkpoint.py321010644editdlrm
checkpoint_test.py134050644editdlrm
cnn.py76260644editdlrm
context.py28410644editdlrm
context_test.py17920644editdlrm
control.py193090644editdlrm
control_ops_grad.py288930644editdlrm
control_ops_grad_test.py17520644editdlrm
control_ops_util.py108630644editdlrm
control_test.py122760644editdlrm
convert.py550644editdlrm
convert_test.py2010644editdlrm
convnet_benchmarks.py205330644editdlrm
convnet_benchmarks_test.py8390644editdlrm
core.py1194000644editdlrm
core_gradients_test.py380220644editdlrm
core_test.py476830644editdlrm
crf.py132500644editdlrm
crf_predict.py11590644editdlrm
crf_viterbi_test.py16630644editdlrm
dataio.py235320644editdlrm
dataio_test.py175750644editdlrm
dataset.py128860644editdlrm
data_parallel_model.py831000644editdlrm
data_parallel_model_test.py561450644editdlrm
data_workers.py159410644editdlrm
data_workers_test.py65610644editdlrm
db_file_reader.py66080644editdlrm
db_test.py11100644editdlrm
device_checker.py51570644editdlrm
dyndep.py15330644editdlrm
embedding_generation_benchmark.py52560644editdlrm
experiment_util.py36250644editdlrm
extension_loader.py7440644editdlrm
fakefp16_transform_lib.py3220644editdlrm
filler_test.py7480644editdlrm
functional.py44150644editdlrm
functional_test.py42040644editdlrm
fused_8bit_rowwise_conversion_ops_test.py39450644editdlrm
gradient_checker.py153770644editdlrm
gradient_check_test.py207290644editdlrm
gru_cell.py51290644editdlrm
hip_test_util.py4050644editdlrm
hsm_util.py22590644editdlrm
hypothesis_test.py1057620644editdlrm
hypothesis_test_util.py268530644editdlrm
ideep_test_util.py9980644editdlrm
layers_test.py929310644editdlrm
layer_model_helper.py293400644editdlrm
layer_model_instantiator.py39350644editdlrm
layer_parameter_sharing_test.py91480644editdlrm
layer_test_util.py48750644editdlrm
lazy.py2770644editdlrm
lazy_dyndep.py25620644editdlrm
lazy_dyndep_test.py39140644editdlrm
lengths_reducer_fused_8bit_rowwise_ops_test.py75750644editdlrm
lengths_reducer_rowwise_8bit_ops_test.py57100644editdlrm
lstm_benchmark.py106490644editdlrm
memonger.py340410644editdlrm
memonger_test.py369100644editdlrm
mkl_test_util.py11420644editdlrm
model_device_test.py47770644editdlrm
model_helper.py234920644editdlrm
model_helper_test.py23360644editdlrm
modifier_context.py17720644editdlrm
muji.py81310644editdlrm
muji_test.py30580644editdlrm
net_builder.py276790644editdlrm
net_builder_test.py113820644editdlrm
net_drawer.py142640644editdlrm
net_printer.py127040644editdlrm
net_printer_test.py31900644editdlrm
nomnigraph.py42160644editdlrm
nomnigraph_test.py154270644editdlrm
nomnigraph_transformations.py37870644editdlrm
nomnigraph_transformations_test.py57670644editdlrm
normalizer.py14110644editdlrm
normalizer_context.py10070644editdlrm
normalizer_test.py4870644editdlrm
numa_benchmark.py22300644editdlrm
numa_test.py16630644editdlrm
observer_test.py53160644editdlrm
operator_fp_exceptions_test.py12480644editdlrm
optimizer.py788130644editdlrm
optimizer_context.py14620644editdlrm
optimizer_test.py307050644editdlrm
optimizer_test_util.py91870644editdlrm
parallelize_bmuf_distributed_test.py99080644editdlrm
parallel_workers.py76820644editdlrm
parallel_workers_test.py35010644editdlrm
pipeline.py172830644editdlrm
pipeline_test.py25420644editdlrm
predictor_constants.py1980644editdlrm
python_op_test.py91690644editdlrm
queue_util.py44590644editdlrm
record_queue.py44530644editdlrm
recurrent.py132970644editdlrm
regularizer.py211200644editdlrm
regularizer_context.py10130644editdlrm
regularizer_test.py102660644editdlrm
rnn_cell.py682330644editdlrm
schema.py456210644editdlrm
schema_test.py157540644editdlrm
scope.py36230644editdlrm
scope_test.py52490644editdlrm
session.py76420644editdlrm
session_test.py20780644editdlrm
sparse_to_dense_mask_test.py65650644editdlrm
sparse_to_dense_test.py35560644editdlrm
task.py242740644editdlrm
task_test.py8700644editdlrm
test_util.py35240644editdlrm
text_file_reader.py19900644editdlrm
timeout_guard.py40540644editdlrm
toy_regression_test.py28220644editdlrm
transformations.py18320644editdlrm
transformations_test.py119600644editdlrm
tt_core.py93490644editdlrm
tt_core_test.py25180644editdlrm
utils.py141810644editdlrm
utils_test.py13990644editdlrm
visualize.py63150644editdlrm
workspace.py252630644editdlrm
workspace_test.py348440644editdlrm
_import_c_extension.py22500644editdlrm
__init__.py39250644editdlrm
Edit: /usr/local/lib64/python3.6/site-packages/caffe2/python/net_drawer.py (14264B)
## @package net_drawer # Module caffe2.python.net_drawer import argparse import json import logging from collections import defaultdict from caffe2.python import utils from future.utils import viewitems logger = logging.getLogger(__name__) logger.setLevel(logging.INFO) try: import pydot except ImportError: logger.info( 'Cannot import pydot, which is required for drawing a network. This ' 'can usually be installed in python with "pip install pydot". Also, ' 'pydot requires graphviz to convert dot files to pdf: in ubuntu, this ' 'can usually be installed with "sudo apt-get install graphviz".' ) print( 'net_drawer will not run correctly. Please install the correct ' 'dependencies.' ) pydot = None from caffe2.proto import caffe2_pb2 OP_STYLE = { 'shape': 'box', 'color': '#0F9D58', 'style': 'filled', 'fontcolor': '#FFFFFF' } BLOB_STYLE = {'shape': 'octagon'} def _rectify_operator_and_name(operators_or_net, name): """Gets the operators and name for the pydot graph.""" if isinstance(operators_or_net, caffe2_pb2.NetDef): operators = operators_or_net.op if name is None: name = operators_or_net.name elif hasattr(operators_or_net, 'Proto'): net = operators_or_net.Proto() if not isinstance(net, caffe2_pb2.NetDef): raise RuntimeError( "Expecting NetDef, but got {}".format(type(net))) operators = net.op if name is None: name = net.name else: operators = operators_or_net if name is None: name = "unnamed" return operators, name def _escape_label(name): # json.dumps is poor man's escaping return json.dumps(name) def GetOpNodeProducer(append_output, **kwargs): def ReallyGetOpNode(op, op_id): if op.name: node_name = '%s/%s (op#%d)' % (op.name, op.type, op_id) else: node_name = '%s (op#%d)' % (op.type, op_id) if append_output: for output_name in op.output: node_name += '\n' + output_name return pydot.Node(node_name, **kwargs) return ReallyGetOpNode def GetBlobNodeProducer(**kwargs): def ReallyGetBlobNode(node_name, label): return pydot.Node(node_name, label=label, **kwargs) return ReallyGetBlobNode def GetPydotGraph( operators_or_net, name=None, rankdir='LR', op_node_producer=None, blob_node_producer=None ): if op_node_producer is None: op_node_producer = GetOpNodeProducer(False, **OP_STYLE) if blob_node_producer is None: blob_node_producer = GetBlobNodeProducer(**BLOB_STYLE) operators, name = _rectify_operator_and_name(operators_or_net, name) graph = pydot.Dot(name, rankdir=rankdir) pydot_nodes = {} pydot_node_counts = defaultdict(int) for op_id, op in enumerate(operators): op_node = op_node_producer(op, op_id) graph.add_node(op_node) # print 'Op: %s' % op.name # print 'inputs: %s' % str(op.input) # print 'outputs: %s' % str(op.output) for input_name in op.input: if input_name not in pydot_nodes: input_node = blob_node_producer( _escape_label( input_name + str(pydot_node_counts[input_name])), label=_escape_label(input_name), ) pydot_nodes[input_name] = input_node else: input_node = pydot_nodes[input_name] graph.add_node(input_node) graph.add_edge(pydot.Edge(input_node, op_node)) for output_name in op.output: if output_name in pydot_nodes: # we are overwriting an existing blob. need to update the count. pydot_node_counts[output_name] += 1 output_node = blob_node_producer( _escape_label( output_name + str(pydot_node_counts[output_name])), label=_escape_label(output_name), ) pydot_nodes[output_name] = output_node graph.add_node(output_node) graph.add_edge(pydot.Edge(op_node, output_node)) return graph def GetPydotGraphMinimal( operators_or_net, name=None, rankdir='LR', minimal_dependency=False, op_node_producer=None, ): """Different from GetPydotGraph, hide all blob nodes and only show op nodes. If minimal_dependency is set as well, for each op, we will only draw the edges to the minimal necessary ancestors. For example, if op c depends on op a and b, and op b depends on a, then only the edge b->c will be drawn because a->c will be implied. """ if op_node_producer is None: op_node_producer = GetOpNodeProducer(False, **OP_STYLE) operators, name = _rectify_operator_and_name(operators_or_net, name) graph = pydot.Dot(name, rankdir=rankdir) # blob_parents maps each blob name to its generating op. blob_parents = {} # op_ancestry records the ancestors of each op. op_ancestry = defaultdict(set) for op_id, op in enumerate(operators): op_node = op_node_producer(op, op_id) graph.add_node(op_node) # Get parents, and set up op ancestry. parents = [ blob_parents[input_name] for input_name in op.input if input_name in blob_parents ] op_ancestry[op_node].update(parents) for node in parents: op_ancestry[op_node].update(op_ancestry[node]) if minimal_dependency: # only add nodes that do not have transitive ancestry for node in parents: if all( [node not in op_ancestry[other_node] for other_node in parents] ): graph.add_edge(pydot.Edge(node, op_node)) else: # Add all parents to the graph. for node in parents: graph.add_edge(pydot.Edge(node, op_node)) # Update blob_parents to reflect that this op created the blobs. for output_name in op.output: blob_parents[output_name] = op_node return graph def GetOperatorMapForPlan(plan_def): operator_map = {} for net_id, net in enumerate(plan_def.network): if net.HasField('name'): operator_map[plan_def.name + "_" + net.name] = net.op else: operator_map[plan_def.name + "_network_%d" % net_id] = net.op return operator_map def _draw_nets(nets, g): nodes = [] for i, net in enumerate(nets): nodes.append(pydot.Node(_escape_label(net))) g.add_node(nodes[-1]) if i > 0: g.add_edge(pydot.Edge(nodes[-2], nodes[-1])) return nodes def _draw_steps(steps, g, skip_step_edges=False): # noqa kMaxParallelSteps = 3 def get_label(): label = [step.name + '\n'] if step.report_net: label.append('Reporter: {}'.format(step.report_net)) if step.should_stop_blob: label.append('Stopper: {}'.format(step.should_stop_blob)) if step.concurrent_substeps: label.append('Concurrent') if step.only_once: label.append('Once') return '\n'.join(label) def substep_edge(start, end): return pydot.Edge(start, end, arrowhead='dot', style='dashed') nodes = [] for i, step in enumerate(steps): parallel = step.concurrent_substeps nodes.append(pydot.Node(_escape_label(get_label()), **OP_STYLE)) g.add_node(nodes[-1]) if i > 0 and not skip_step_edges: g.add_edge(pydot.Edge(nodes[-2], nodes[-1])) if step.network: sub_nodes = _draw_nets(step.network, g) elif step.substep: if parallel: sub_nodes = _draw_steps( step.substep[:kMaxParallelSteps], g, skip_step_edges=True) else: sub_nodes = _draw_steps(step.substep, g) else: raise ValueError('invalid step') if parallel: for sn in sub_nodes: g.add_edge(substep_edge(nodes[-1], sn)) if len(step.substep) > kMaxParallelSteps: ellipsis = pydot.Node('{} more steps'.format( len(step.substep) - kMaxParallelSteps), **OP_STYLE) g.add_node(ellipsis) g.add_edge(substep_edge(nodes[-1], ellipsis)) else: g.add_edge(substep_edge(nodes[-1], sub_nodes[0])) return nodes def GetPlanGraph(plan_def, name=None, rankdir='TB'): graph = pydot.Dot(name, rankdir=rankdir) _draw_steps(plan_def.execution_step, graph) return graph def GetGraphInJson(operators_or_net, output_filepath): operators, _ = _rectify_operator_and_name(operators_or_net, None) blob_strid_to_node_id = {} node_name_counts = defaultdict(int) nodes = [] edges = [] for op_id, op in enumerate(operators): op_label = op.name + '/' + op.type if op.name else op.type op_node_id = len(nodes) nodes.append({ 'id': op_node_id, 'label': op_label, 'op_id': op_id, 'type': 'op' }) for input_name in op.input: strid = _escape_label( input_name + str(node_name_counts[input_name])) if strid not in blob_strid_to_node_id: input_node = { 'id': len(nodes), 'label': input_name, 'type': 'blob' } blob_strid_to_node_id[strid] = len(nodes) nodes.append(input_node) else: input_node = nodes[blob_strid_to_node_id[strid]] edges.append({ 'source': blob_strid_to_node_id[strid], 'target': op_node_id }) for output_name in op.output: strid = _escape_label( output_name + str(node_name_counts[output_name])) if strid in blob_strid_to_node_id: # we are overwriting an existing blob. need to update the count. node_name_counts[output_name] += 1 strid = _escape_label( output_name + str(node_name_counts[output_name])) if strid not in blob_strid_to_node_id: output_node = { 'id': len(nodes), 'label': output_name, 'type': 'blob' } blob_strid_to_node_id[strid] = len(nodes) nodes.append(output_node) edges.append({ 'source': op_node_id, 'target': blob_strid_to_node_id[strid] }) with open(output_filepath, 'w') as f: json.dump({'nodes': nodes, 'edges': edges}, f) # A dummy minimal PNG image used by GetGraphPngSafe as a # placeholder when rendering fail to run. _DummyPngImage = ( b'\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x00\x01\x00\x00\x00' b'\x01\x01\x00\x00\x00\x007n\xf9$\x00\x00\x00\nIDATx\x9cc`\x00\x00' b'\x00\x02\x00\x01H\xaf\xa4q\x00\x00\x00\x00IEND\xaeB`\x82') def GetGraphPngSafe(func, *args, **kwargs): """ Invokes `func` (e.g. GetPydotGraph) with args. If anything fails - returns and empty image instead of throwing Exception """ try: graph = func(*args, **kwargs) if not isinstance(graph, pydot.Dot): raise ValueError("func is expected to return pydot.Dot") return graph.create_png() except Exception as e: logger.error("Failed to draw graph: {}".format(e)) return _DummyPngImage def main(): parser = argparse.ArgumentParser(description="Caffe2 net drawer.") parser.add_argument( "--input", type=str, required=True, help="The input protobuf file." ) parser.add_argument( "--output_prefix", type=str, default="", help="The prefix to be added to the output filename." ) parser.add_argument( "--minimal", action="store_true", help="If set, produce a minimal visualization." ) parser.add_argument( "--minimal_dependency", action="store_true", help="If set, only draw minimal dependency." ) parser.add_argument( "--append_output", action="store_true", help="If set, append the output blobs to the operator names.") parser.add_argument( "--rankdir", type=str, default="LR", help="The rank direction of the pydot graph." ) args = parser.parse_args() with open(args.input, 'r') as fid: content = fid.read() graphs = utils.GetContentFromProtoString( content, { caffe2_pb2.PlanDef: lambda x: GetOperatorMapForPlan(x), caffe2_pb2.NetDef: lambda x: {x.name: x.op}, } ) for key, operators in viewitems(graphs): if args.minimal: graph = GetPydotGraphMinimal( operators, name=key, rankdir=args.rankdir, node_producer=GetOpNodeProducer(args.append_output, **OP_STYLE), minimal_dependency=args.minimal_dependency) else: graph = GetPydotGraph( operators, name=key, rankdir=args.rankdir, node_producer=GetOpNodeProducer(args.append_output, **OP_STYLE)) filename = args.output_prefix + graph.get_name() + '.dot' graph.write(filename, format='raw') pdf_filename = filename[:-3] + 'pdf' try: graph.write_pdf(pdf_filename) except Exception: print( 'Error when writing out the pdf file. Pydot requires graphviz ' 'to convert dot files to pdf, and you may not have installed ' 'graphviz. On ubuntu this can usually be installed with "sudo ' 'apt-get install graphviz". We have generated the .dot file ' 'but will not be able to generate pdf file for now.' ) if __name__ == '__main__': main()