feat: prerendre synthetic dataset script
Former-commit-id: f83dd74d82e9ad246a9c1ef01076f40dc1b9b897 [formerly ba0182a3220d1b2b7122227b8ef711c0a2243fc2] Former-commit-id: 59c17c59f77419b7e420bf95617f54969eabbabc
This commit is contained in:
parent
8630f1c583
commit
edcc3c7bb2
105
src/prerender.ipynb
Normal file
105
src/prerender.ipynb
Normal file
|
@ -0,0 +1,105 @@
|
|||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 1,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stderr",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"/home/laurent_fainsin/Documents/unet/.venv/lib/python3.8/site-packages/tqdm/auto.py:22: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n",
|
||||
" from .autonotebook import tqdm as notebook_tqdm\n",
|
||||
"/home/laurent_fainsin/Documents/unet/.venv/lib/python3.8/site-packages/torchvision/io/image.py:13: UserWarning: Failed to load image Python extension: /home/laurent_fainsin/Documents/unet/.venv/lib/python3.8/site-packages/torchvision/image.so: undefined symbol: _ZNK3c1010TensorImpl36is_contiguous_nondefault_policy_implENS_12MemoryFormatE\n",
|
||||
" warn(f\"Failed to load image Python extension: {e}\")\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"from PIL import Image\n",
|
||||
"\n",
|
||||
"import numpy as np\n",
|
||||
"import albumentations as A\n",
|
||||
"\n",
|
||||
"from utils import RandomPaste\n",
|
||||
"from data.dataset import SyntheticDataset\n",
|
||||
"\n",
|
||||
"from pathlib import Path\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 2,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"transform = A.Compose(\n",
|
||||
" [\n",
|
||||
" A.Resize(512, 512),\n",
|
||||
" A.Flip(),\n",
|
||||
" A.ColorJitter(),\n",
|
||||
" RandomPaste(5, \"/home/lilian/data_disk/lfainsin/spheres/\"),\n",
|
||||
" A.GaussianBlur(),\n",
|
||||
" A.ISONoise(),\n",
|
||||
" ],\n",
|
||||
")\n",
|
||||
"\n",
|
||||
"dataset = SyntheticDataset(image_dir=\"/home/lilian/data_disk/lfainsin/train/\", transform=transform)\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 6,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"10001\r"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"for i, (image, mask) in enumerate(dataset):\n",
|
||||
" path = f\"/home/lilian/data_disk/lfainsin/prerender/{i}/\"\n",
|
||||
" Path(path).mkdir(parents=True, exist_ok=True)\n",
|
||||
" Image.fromarray(image).save(f\"{path}/image.jpg\")\n",
|
||||
" Image.fromarray(mask*255).save(f\"{path}/MASK.PNG\")\n",
|
||||
" \n",
|
||||
" print(i, end=\"\\r\")\n",
|
||||
"\n",
|
||||
" if i > 10000:\n",
|
||||
" break"
|
||||
]
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"display_name": "Python 3.8.0 ('.venv': poetry)",
|
||||
"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.0"
|
||||
},
|
||||
"orig_nbformat": 4,
|
||||
"vscode": {
|
||||
"interpreter": {
|
||||
"hash": "dc80d2c03865715c8671359a6bf138f6c8ae4e26ae025f2543e0980b8db0ed7e"
|
||||
}
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 2
|
||||
}
|
Loading…
Reference in a new issue