Load the module object from the given Torchscript filename or stream, and convert the stored JSON metadata back to a dict object. This will produce an empty dict if the metadata file is not present. Args: filename_prefix_or_stream: filename or file-like stream object. m
(
filename_prefix_or_stream: str | IO[Any],
map_location: torch.device | None = None,
more_extra_files: Sequence[str] = (),
)
| 101 | |
| 102 | |
| 103 | def load_net_with_metadata( |
| 104 | filename_prefix_or_stream: str | IO[Any], |
| 105 | map_location: torch.device | None = None, |
| 106 | more_extra_files: Sequence[str] = (), |
| 107 | ) -> tuple[torch.nn.Module, dict, dict]: |
| 108 | """ |
| 109 | Load the module object from the given Torchscript filename or stream, and convert the stored JSON metadata |
| 110 | back to a dict object. This will produce an empty dict if the metadata file is not present. |
| 111 | |
| 112 | Args: |
| 113 | filename_prefix_or_stream: filename or file-like stream object. |
| 114 | map_location: network map location as in `torch.jit.load`. |
| 115 | more_extra_files: other extra file data names to load from bundle, see `_extra_files` of `torch.jit.load`. |
| 116 | Returns: |
| 117 | Triple containing loaded object, metadata dict, and extra files dict containing other file data if present |
| 118 | """ |
| 119 | extra_files = dict.fromkeys(more_extra_files, "") |
| 120 | extra_files[METADATA_FILENAME] = "" |
| 121 | |
| 122 | jit_obj = torch.jit.load(filename_prefix_or_stream, map_location, extra_files) |
| 123 | |
| 124 | extra_files = dict(extra_files.items()) # compatibility with ExtraFilesMap |
| 125 | |
| 126 | if METADATA_FILENAME in extra_files: |
| 127 | json_data = extra_files[METADATA_FILENAME] |
| 128 | del extra_files[METADATA_FILENAME] |
| 129 | else: |
| 130 | json_data = "{}" |
| 131 | |
| 132 | json_data_dict = json.loads(json_data) |
| 133 | |
| 134 | return jit_obj, json_data_dict, extra_files |
searching dependent graphs…