Skip to content

Commit

Permalink
Added comments and fixed augmentation issue
Browse files Browse the repository at this point in the history
  • Loading branch information
jccaicedo committed Jul 30, 2018
1 parent f2d6a67 commit 930e47e
Show file tree
Hide file tree
Showing 4 changed files with 215 additions and 26 deletions.
File renamed without changes.
50 changes: 44 additions & 6 deletions unet4nuclei/00-download-dataset.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "code",
"execution_count": null,
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -14,9 +14,16 @@
"from config import config_vars"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Download zip files from BBBC website"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -27,7 +34,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -36,63 +43,94 @@
"assert metadata.ok"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Extract images"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"images_zip = os.path.join(config_vars['raw_images_dir'], 'images.zip')\n",
"os.makedirs(config_vars['raw_images_dir'], exist_ok=True)\n",
"with open(images_zip, 'wb') as f:\n",
" f.write(images.content)\n",
" \n",
"zip_ref = zipfile.ZipFile(images_zip, 'r')\n",
"for file in zip_ref.namelist():\n",
" if file.startswith('images/'):\n",
" zip_ref.extract(file, config_vars['raw_images_dir'])\n",
"\n",
"zip_ref.close()\n",
"os.remove(images_zip)\n",
"\n",
"for file in glob.glob(os.path.join(config_vars['raw_images_dir'], 'images/*')):\n",
" shutil.move(file, config_vars['raw_images_dir'])\n",
"\n",
"shutil.rmtree(os.path.join(config_vars['raw_images_dir'], 'images'))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Extract annotations"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"masks_zip = os.path.join(config_vars['raw_annotations_dir'], 'masks.zip')\n",
"os.makedirs(config_vars['raw_annotations_dir'], exist_ok=True)\n",
"with open(masks_zip, 'wb') as f:\n",
" f.write(masks.content)\n",
"\n",
"zip_ref = zipfile.ZipFile(masks_zip, 'r')\n",
"for file in zip_ref.namelist():\n",
" if file.startswith('masks/'):\n",
" zip_ref.extract(file, config_vars['raw_annotations_dir'])\n",
"\n",
"zip_ref.close()\n",
"os.remove(masks_zip)\n",
"\n",
"for file in glob.glob(os.path.join(config_vars['raw_annotations_dir'], 'masks/*')):\n",
" shutil.move(file, config_vars['raw_annotations_dir'])\n",
"shutil.rmtree(os.path.join(config_vars['raw_annotations_dir'], 'masks'))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Extract metadata"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
"metadata_zip = os.path.join(config_vars['root_directory'], 'metadata.zip')\n",
"with open(metadata_zip, 'wb') as f:\n",
" f.write(metadata.content)\n",
"\n",
"zip_ref = zipfile.ZipFile(metadata_zip, 'r')\n",
"for file in zip_ref.namelist():\n",
" if file.startswith('metadata/'):\n",
" zip_ref.extract(file, config_vars['root_directory'])\n",
"\n",
"zip_ref.close()\n",
"os.remove(metadata_zip)\n",
"\n",
"for file in glob.glob(os.path.join(config_vars['root_directory'], 'metadata/*')):\n",
" shutil.move(file, config_vars['root_directory'])\n",
"shutil.rmtree(os.path.join(config_vars['root_directory'], 'metadata'))"
Expand Down
183 changes: 167 additions & 16 deletions unet4nuclei/01-preprocessing.ipynb

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions unet4nuclei/utils/model_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def get_core(dim1, dim2):

d = keras.layers.UpSampling2D()(d)

y = keras.layers.merge([d, c], concat_axis=3, mode="concat")
y = keras.layers.merge.concatenate([d, c], axis=3)

e = keras.layers.Convolution2D(256, 3, 3, **option_dict_conv)(y)
e = keras.layers.BatchNormalization(**option_dict_bn)(e)
Expand All @@ -62,7 +62,7 @@ def get_core(dim1, dim2):
e = keras.layers.UpSampling2D()(e)


y = keras.layers.merge([e, b], concat_axis=3, mode="concat")
y = keras.layers.merge.concatenate([e, b], axis=3)

f = keras.layers.Convolution2D(128, 3, 3, **option_dict_conv)(y)
f = keras.layers.BatchNormalization(**option_dict_bn)(f)
Expand All @@ -73,7 +73,7 @@ def get_core(dim1, dim2):
f = keras.layers.UpSampling2D()(f)


y = keras.layers.merge([f, a], concat_axis=3, mode="concat")
y = keras.layers.merge.concatenate([f, a], axis=3)

y = keras.layers.Convolution2D(64, 3, 3, **option_dict_conv)(y)
y = keras.layers.BatchNormalization(**option_dict_bn)(y)
Expand All @@ -95,4 +95,4 @@ def get_model_3_class(dim1, dim2, activation="softmax"):

model = keras.models.Model(x, y)

return model
return model

0 comments on commit 930e47e

Please sign in to comment.