Skip to content

Commit

Permalink
exploooooore
Browse files Browse the repository at this point in the history
  • Loading branch information
hasibzunair committed Oct 19, 2022
1 parent 77fa7aa commit 145486a
Show file tree
Hide file tree
Showing 2 changed files with 153 additions and 1 deletion.
7 changes: 6 additions & 1 deletion environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,14 @@ dependencies:
- zlib=1.2.11=h7f8727e_4
- zstd=1.4.9=haebb681_0
- pip:
- contourpy==1.0.5
- cycler==0.11.0
- fonttools==4.37.4
- joblib==1.1.0
- kiwisolver==1.4.4
- matplotlib==3.6.1
- scikit-learn==1.1.1
- scipy==1.9.0
- sklearn==0.0
- threadpoolctl==3.1.0
- tqdm==4.64.0
- tqdm==4.64.0
147 changes: 147 additions & 0 deletions notebooks/explore.ipynb
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
}

0 comments on commit 145486a

Please sign in to comment.