MCPcopy Index your code
hub / github.com/pytorch/pytorch / __init__

Method __init__

caffe2/python/core.py:1476–1541  ·  view source on GitHub ↗

Create a Net. Args: name_or_proto: If a NetDef is provided, clone it (or take ownership, depending on the value of `inplace`). Otherwise, create an empty net with the given name. inplace: If a NetDef is

(self, name_or_proto, inplace=False)

Source from the content-addressed store, hash-verified

1474 return name
1475
1476 def __init__(self, name_or_proto, inplace=False):
1477 """
1478 Create a Net.
1479 Args:
1480 name_or_proto: If a NetDef is provided, clone it (or take ownership,
1481 depending on the value of `inplace`). Otherwise,
1482 create an empty net with the given name.
1483 inplace: If a NetDef is provided, take ownership when `inplace` is True;
1484 otherwise, clone it.
1485 """
1486 self._input_record = None
1487 self._output_record = None
1488 # Register blobs so that it's guaranteed that different calls to
1489 # NextBlob/NextScopedBlob always return blobs with different names
1490 self._registered_blob_names = set()
1491 self._recreate_lookup_tables = False
1492 self._op_outputs = set()
1493 self._external_input_map = set()
1494 self._attr_dict = defaultdict(list)
1495 if type(name_or_proto) is caffe2_pb2.NetDef:
1496 proto = name_or_proto
1497 # We are initializing a network by a NetDef. In this case, we will
1498 # initialize our network with the given netdef.
1499 if inplace:
1500 self._net = proto
1501 else:
1502 self._net = caffe2_pb2.NetDef()
1503 self._net.CopyFrom(proto)
1504
1505 existing_outputs = [list(op.output) for op in self._net.op]
1506
1507 self._external_input_map.update(list(self._net.external_input))
1508
1509 # Set the next name index properly.
1510 existing_names = set()
1511 for op in self._net.op:
1512 existing_names.update(list(op.input))
1513 for output in existing_outputs:
1514 existing_names.update(output)
1515
1516 for outs in existing_outputs:
1517 self._op_outputs.update(outs)
1518
1519 prefix_len = len(self._net.name + '_blob_')
1520 autogen_indices = []
1521 for s in existing_names:
1522 if s.startswith(self._net.name + '_blob_'):
1523 try:
1524 autogen_indices.append(int(s[prefix_len]))
1525 except ValueError:
1526 pass
1527 if len(autogen_indices):
1528 self._next_name_index = max(autogen_indices) + 1
1529 else:
1530 self._next_name_index = 0
1531 name = self._net.name
1532 else:
1533 name = name_or_proto

Callers

nothing calls this directly

Calls 5

listFunction · 0.85
_get_next_net_nameMethod · 0.80
maxFunction · 0.50
updateMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected