()
| 343 | |
| 344 | |
| 345 | def main(): |
| 346 | parser = argparse.ArgumentParser(description="Caffe2 net drawer.") |
| 347 | parser.add_argument( |
| 348 | "--input", |
| 349 | type=str, required=True, |
| 350 | help="The input protobuf file." |
| 351 | ) |
| 352 | parser.add_argument( |
| 353 | "--output_prefix", |
| 354 | type=str, default="", |
| 355 | help="The prefix to be added to the output filename." |
| 356 | ) |
| 357 | parser.add_argument( |
| 358 | "--minimal", action="store_true", |
| 359 | help="If set, produce a minimal visualization." |
| 360 | ) |
| 361 | parser.add_argument( |
| 362 | "--minimal_dependency", action="store_true", |
| 363 | help="If set, only draw minimal dependency." |
| 364 | ) |
| 365 | parser.add_argument( |
| 366 | "--append_output", action="store_true", |
| 367 | help="If set, append the output blobs to the operator names.") |
| 368 | parser.add_argument( |
| 369 | "--rankdir", type=str, default="LR", |
| 370 | help="The rank direction of the pydot graph." |
| 371 | ) |
| 372 | args = parser.parse_args() |
| 373 | with open(args.input, 'r') as fid: |
| 374 | content = fid.read() |
| 375 | graphs = utils.GetContentFromProtoString( |
| 376 | content, { |
| 377 | caffe2_pb2.PlanDef: GetOperatorMapForPlan, |
| 378 | caffe2_pb2.NetDef: lambda x: {x.name: x.op}, |
| 379 | } |
| 380 | ) |
| 381 | for key, operators in graphs.items(): |
| 382 | if args.minimal: |
| 383 | graph = GetPydotGraphMinimal( |
| 384 | operators, |
| 385 | name=key, |
| 386 | rankdir=args.rankdir, |
| 387 | node_producer=GetOpNodeProducer(args.append_output, **OP_STYLE), |
| 388 | minimal_dependency=args.minimal_dependency) |
| 389 | else: |
| 390 | graph = GetPydotGraph( |
| 391 | operators, |
| 392 | name=key, |
| 393 | rankdir=args.rankdir, |
| 394 | node_producer=GetOpNodeProducer(args.append_output, **OP_STYLE)) |
| 395 | filename = args.output_prefix + graph.get_name() + '.dot' |
| 396 | graph.write(filename, format='raw') |
| 397 | pdf_filename = filename[:-3] + 'pdf' |
| 398 | try: |
| 399 | graph.write_pdf(pdf_filename) |
| 400 | except Exception: |
| 401 | print( |
| 402 | 'Error when writing out the pdf file. Pydot requires graphviz ' |
no test coverage detected
searching dependent graphs…