MCPcopy Index your code
hub / github.com/Project-MONAI/MONAI / test_script_save

Function test_script_save

tests/test_utils.py:787–806  ·  view source on GitHub ↗

Test the ability to save `net` as a Torchscript object, reload it, and apply inference. The value `inputs` is forward-passed through the original and loaded copy of the network and their results returned. The forward pass for both is done without gradient accumulation. The test wil

(net, *inputs, device=None, rtol=1e-4, atol=0.0)

Source from the content-addressed store, hash-verified

785
786
787def test_script_save(net, *inputs, device=None, rtol=1e-4, atol=0.0):
788 """
789 Test the ability to save `net` as a Torchscript object, reload it, and apply inference. The value `inputs` is
790 forward-passed through the original and loaded copy of the network and their results returned.
791 The forward pass for both is done without gradient accumulation.
792
793 The test will be performed with CUDA if available, else CPU.
794 """
795 # TODO: would be nice to use GPU if available, but it currently causes CI failures.
796 device = "cpu"
797 with tempfile.TemporaryDirectory() as tempdir:
798 convert_to_torchscript(
799 model=net,
800 filename_or_obj=os.path.join(tempdir, "model.ts"),
801 verify=True,
802 inputs=inputs,
803 device=device,
804 rtol=rtol,
805 atol=atol,
806 )
807
808
809def test_onnx_save(net, *inputs, device=None, rtol=1e-4, atol=0.0):

Callers 15

test_scriptMethod · 0.90
test_scriptMethod · 0.90
test_scriptMethod · 0.90
test_scriptMethod · 0.90
test_scriptMethod · 0.90
test_scriptMethod · 0.90
test_scriptMethod · 0.90
test_scriptMethod · 0.90
test_scriptMethod · 0.90
test_scriptMethod · 0.90
test_scriptMethod · 0.90
test_scriptMethod · 0.90

Calls 1

convert_to_torchscriptFunction · 0.90

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…