-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from kzaleskaa/dev
example run
- Loading branch information
Showing
5 changed files
with
155 additions
and
16 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,147 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import matplotlib.pyplot as plt\n", | ||
"from torchvision.transforms import transforms\n", | ||
"\n", | ||
"from src.data.components.custom_transforms import BilinearInterpolation, NormalizeData\n", | ||
"from src.data.components.nyu_dataset import NYUDataset\n", | ||
"from src.models.unet_module import UNETLitModule" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"model_ckpt = \"./logs/train/runs/2024-04-06_18-37-38/checkpoints/epoch_015.ckpt\"" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"model = UNETLitModule.load_from_checkpoint(model_ckpt)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"model.eval()" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"transforms_img = transforms.Compose([transforms.PILToTensor(), transforms.Resize((224, 224))])\n", | ||
"\n", | ||
"transforms_mask = transforms.Compose(\n", | ||
" [\n", | ||
" transforms.PILToTensor(),\n", | ||
" NormalizeData(10_000 * (1 / 255)),\n", | ||
" BilinearInterpolation((56, 56)),\n", | ||
" ]\n", | ||
")" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"test_dataset = NYUDataset(\"nyu2_test.csv\", \"data/\", transforms_img, transforms_mask)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"outputs = []\n", | ||
"\n", | ||
"for i in range(10):\n", | ||
" img, mask = test_dataset[i]\n", | ||
" img = img.unsqueeze(0)\n", | ||
" mask = mask.unsqueeze(0)\n", | ||
" img = img.to(model.device)\n", | ||
" out = model(img)\n", | ||
" outputs.append(out)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"def visualize_result(img, mask, out):\n", | ||
" _, axs = plt.subplots(1, 3)\n", | ||
" axs[0].imshow(img.squeeze().permute(1, 2, 0))\n", | ||
" axs[0].set_title(\"Input Image\")\n", | ||
" axs[1].imshow(mask.squeeze())\n", | ||
" axs[1].set_title(\"Ground Truth\")\n", | ||
" axs[2].imshow(out.squeeze().detach().cpu())\n", | ||
" axs[2].set_title(\"Predicted Mask\")\n", | ||
"\n", | ||
" for ax in axs:\n", | ||
" ax.axis(\"off\")\n", | ||
"\n", | ||
" plt.show()" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"for i in range(5):\n", | ||
" visualize_result(test_dataset[i][0], test_dataset[i][1], outputs[i])" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "venv", | ||
"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.11.3" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |
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