-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[feat] add onnx-window model to backend (ppliteseg-nysbc-ccameron)
- Loading branch information
1 parent
36b2a42
commit 77365fd
Showing
5 changed files
with
448 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"### ONNX Windowed Model Integration" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"%load_ext autoreload\n", | ||
"%autoreload 2\n", | ||
"import glob\n", | ||
"import os\n", | ||
"import numpy as np\n", | ||
"import matplotlib.pyplot as plt\n", | ||
"import PIL.Image\n", | ||
"\n", | ||
"from fibsem.segmentation.model import load_model\n", | ||
"from fibsem.structures import FibsemImage\n", | ||
"\n", | ||
"# image filenames\n", | ||
"PATH = \"example_imgs/input\"\n", | ||
"filenames = glob.glob(PATH + \"/*.jpeg\")\n", | ||
"\n", | ||
"# PATH = \"/home/patrick/github/data/autolamella-paper/model-development/train/waffle/test\"\n", | ||
"# filenames = glob.glob(PATH + \"/*.tif\")\n", | ||
"\n", | ||
"# load model\n", | ||
"MODEL_PATH = \"ppliteseg_fibsem_07022024_512x512_128k.onnx\"\n", | ||
"model = load_model(checkpoint=MODEL_PATH)\n", | ||
"\n", | ||
"os.makedirs(\"example_imgs/output/test\", exist_ok=True)\n", | ||
"\n", | ||
"for i, filename in enumerate(filenames):\n", | ||
" print(f\"Processing {i+1}/{len(filenames)}: {filename}\")\n", | ||
"\n", | ||
" # load image\n", | ||
" if \"tif\" in filename:\n", | ||
" image = FibsemImage.load(filename)\n", | ||
" else:\n", | ||
" image = FibsemImage(data=np.asarray(PIL.Image.open(filename)))\n", | ||
" \n", | ||
" # inference\n", | ||
" rgb = model.inference(image.data)\n", | ||
"\n", | ||
" fig = plt.figure(figsize=(10, 10))\n", | ||
" plt.title(f\"Predicted: {os.path.basename(filename)}\", fontsize=10)\n", | ||
" plt.imshow(image.data, cmap=\"gray\")\n", | ||
" plt.imshow(rgb, alpha=0.5)\n", | ||
" plt.axis(\"off\")\n", | ||
" plt.show()\n", | ||
"\n", | ||
" # save figure\n", | ||
" fig.savefig(f\"example_imgs/output/test/{os.path.basename(filename)}\".replace(\".tif\", \".png\"), bbox_inches=\"tight\")\n", | ||
" plt.close(fig)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "fibsem", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.9.18" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |
Oops, something went wrong.