MCPcopy Create free account
hub / github.com/Project-MONAI/MONAI / BlockArgs

Class BlockArgs

monai/networks/nets/efficientnet.py:944–1015  ·  view source on GitHub ↗

BlockArgs object to assist in decoding string notation of arguments for MBConvBlock definition.

Source from the content-addressed store, hash-verified

942
943
944class BlockArgs(NamedTuple):
945 """
946 BlockArgs object to assist in decoding string notation
947 of arguments for MBConvBlock definition.
948 """
949
950 num_repeat: int
951 kernel_size: int
952 stride: int
953 expand_ratio: int
954 input_filters: int
955 output_filters: int
956 id_skip: bool
957 se_ratio: float | None = None
958
959 @staticmethod
960 def from_string(block_string: str):
961 """
962 Get a BlockArgs object from a string notation of arguments.
963
964 Args:
965 block_string (str): A string notation of arguments.
966 Examples: "r1_k3_s11_e1_i32_o16_se0.25".
967
968 Returns:
969 BlockArgs: namedtuple defined at the top of this function.
970 """
971 ops = block_string.split("_")
972 options = {}
973 for op in ops:
974 splits = re.split(r"(\d.*)", op)
975 if len(splits) >= 2:
976 key, value = splits[:2]
977 options[key] = value
978
979 # check stride
980 stride_check = (
981 ("s" in options and len(options["s"]) == 1)
982 or (len(options["s"]) == 2 and options["s"][0] == options["s"][1])
983 or (len(options["s"]) == 3 and options["s"][0] == options["s"][1] and options["s"][0] == options["s"][2])
984 )
985 if not stride_check:
986 raise ValueError("invalid stride option received")
987
988 return BlockArgs(
989 num_repeat=int(options["r"]),
990 kernel_size=int(options["k"]),
991 stride=int(options["s"][0]),
992 expand_ratio=int(options["e"]),
993 input_filters=int(options["i"]),
994 output_filters=int(options["o"]),
995 id_skip=("noskip" not in block_string),
996 se_ratio=float(options["se"]) if "se" in options else None,
997 )
998
999 def to_string(self):
1000 """
1001 Return a block string notation for current BlockArgs object

Callers 1

from_stringMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…