-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
77fa7aa
commit 145486a
Showing
2 changed files
with
153 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,147 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# %load_ext autoreload\n", | ||
"# %autoreload 2" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import os \n", | ||
"import glob\n", | ||
"import numpy as np\n", | ||
"import matplotlib.pyplot as plt\n", | ||
"\n", | ||
"from PIL import Image\n", | ||
"from torchvision import transforms\n", | ||
"\n", | ||
"\n", | ||
"try:\n", | ||
" from torchvision.transforms import InterpolationMode\n", | ||
"\n", | ||
" BICUBIC = InterpolationMode.BICUBIC\n", | ||
"except ImportError:\n", | ||
" BICUBIC = Image.BICUBIC\n", | ||
" " | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"def to_numpy(tensor):\n", | ||
" return (\n", | ||
" tensor.detach().cpu().numpy() if tensor.requires_grad else tensor.cpu().numpy()\n", | ||
" )\n", | ||
"\n", | ||
"\n", | ||
"def _convert_image_to_rgb(image):\n", | ||
" return image.convert(\"RGB\")\n", | ||
"\n", | ||
"\n", | ||
"def preprocess_img(img):\n", | ||
" transform = transforms.Compose(\n", | ||
" [\n", | ||
" transforms.Resize(448, BICUBIC),\n", | ||
" transforms.CenterCrop(448),\n", | ||
" _convert_image_to_rgb,\n", | ||
" ]\n", | ||
" )\n", | ||
" return transform(img)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"scribbles_folder = '../datasets/SCRIBBLES'\n", | ||
"scribbles_paths = sorted(glob.glob(scribbles_folder + \"/*.png\"))[::-1][:1000] # For heavy masking [::-1] \n", | ||
"scribbles_paths[:5]\n", | ||
"# https://github.com/hasibzunair/masksup-segmentation/blob/master/notebooks/exp_dataloader.ipynb" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"scribble = Image.open(scribbles_paths[10]).convert('P')\n", | ||
"scribble" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"scribble_pre = preprocess_img(scribble)\n", | ||
"scribble_pre" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"scribble_pre.size" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3.8.12 ('maskrec')", | ||
"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.8.12" | ||
}, | ||
"orig_nbformat": 4, | ||
"vscode": { | ||
"interpreter": { | ||
"hash": "35d972689a4ebd6112cf5bf9eea2c3bb189b2972b77b117bc02bba8b4bbbd65a" | ||
} | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |