Skip to content
This repository has been archived by the owner on Sep 27, 2023. It is now read-only.

Commit

Permalink
Merge pull request #39 from Project-MONAI/anishag14/restructure-scripts
Browse files Browse the repository at this point in the history
Move the helper script out of src/
  • Loading branch information
anishag14 authored Oct 28, 2021
2 parents 18612bd + e5d1e50 commit ed32d6f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
7 changes: 7 additions & 0 deletions scripts/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
This folder contains helper scripts.

## convert_pytorch2onnx.py

This script will take the path of the Pytorch model and input tensor size. To
run the script ..code: `python scripts/convert_pytorch2onnx.py` to generate
the ONNX model.
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,24 @@

import torch.onnx

model_path = "model_jit.pt" # modify with your own path to the pytorch model


# modify model_path with the path to the pytorch model
model_path = "model_jit.pt"
torch_model = torch.jit.load(model_path)
torch_model = torch_model.eval()

# provide the input torch size that pytorch model takes
x = torch.randn(1, 3, 1024, 1264)
torch_out = torch_model(x)
input_names = ["INPUT__0"]
output_names = ["OUTPUT__0"]

# Export the model
torch.onnx.export(
torch_model, # model being run
x, # model input (or a tuple for multiple inputs)
"monai_unet_pyt.onnx", # where to save the model (can be a file or file-like object)
example_outputs=torch_out,
# export_params=True, # store the trained parameter weights inside the model file
# export_params=True, # store the trained parameter weights inside the model file
verbose=True,
input_names=input_names,
output_names=output_names,
Expand Down

0 comments on commit ed32d6f

Please sign in to comment.