Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
167 changes: 167 additions & 0 deletions notebooks/kaggle-satellite-challenge-data-pipeline.ipynb

Large diffs are not rendered by default.

567 changes: 567 additions & 0 deletions notebooks/kaggle-satellite-challenge-dataset-creation.ipynb

Large diffs are not rendered by default.

141 changes: 141 additions & 0 deletions notebooks/kaggle-satellite-challenge-model.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Model\n",
"* load ternaus-net model (or my model for bone seg)\n",
"* set frozen pretrained VGG weights\n",
"* keras to estimator\n",
"* T2T keras model - TODO\n",
"* train the rest\n",
"* fine tune the whole network - TODO\n",
"\n",
"References:\n",
"* [VGG16 TernausNet](https://github.com/ternaus/TernausNet/blob/master/unet_models.py) \n",
"* [Keras Transfer Learning I](https://www.learnopencv.com/keras-tutorial-fine-tuning-using-pre-trained-models)\n",
"* [Keras Transfer Learning II](https://flyyufelix.github.io/2016/10/08/fine-tuning-in-keras-part2.html)"
]
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"INFO:tensorflow:Using the Keras model provided.\n",
"INFO:tensorflow:Using default config.\n",
"WARNING:tensorflow:Using temporary folder as model directory: /tmp/tmplcozb2dq\n",
"INFO:tensorflow:Using config: {'_model_dir': '/tmp/tmplcozb2dq', '_tf_random_seed': None, '_save_summary_steps': 100, '_save_checkpoints_steps': None, '_save_checkpoints_secs': 600, '_session_config': None, '_keep_checkpoint_max': 5, '_keep_checkpoint_every_n_hours': 10000, '_log_step_count_steps': 100, '_train_distribute': None, '_service': None, '_cluster_spec': <tensorflow.python.training.server_lib.ClusterSpec object at 0x7f58bb6fcb38>, '_task_type': 'worker', '_task_id': 0, '_global_id_in_cluster': 0, '_master': '', '_evaluation_master': '', '_is_chief': True, '_num_ps_replicas': 0, '_num_worker_replicas': 1}\n"
]
},
{
"data": {
"text/plain": [
"<tensorflow.python.estimator.estimator.Estimator at 0x7f58d86fff28>"
]
},
"execution_count": 17,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import sys\n",
"sys.path.append('../sentinel/')\n",
"sys.path.append('../')\n",
"\n",
"from importlib import reload\n",
"\n",
"import numpy as np\n",
"import tensorflow as tf\n",
"\n",
"import vgg_unet\n",
"reload(vgg_unet)\n",
"from vgg_unet import vgg16_unet, jaccard_coef_loss, jaccard_coef_int\n",
"\n",
"%matplotlib inline\n",
"%load_ext autoreload\n",
"%autoreload 2\n",
"\n",
"hparams = tf.contrib.training.HParams(\n",
" image_size=224,\n",
" num_classes=1,\n",
" num_filters=32,\n",
" is_deconv=False,\n",
" use_bn_elu=False,\n",
" freeze_encoder=True,\n",
")\n",
"\n",
"ternaus_net = vgg16_unet(hparams)\n",
"Nadam = tf.keras.optimizers.Nadam\n",
"ternaus_net.compile(optimizer=Nadam(lr=1e-3), loss=jaccard_coef_loss,\n",
" metrics=['binary_crossentropy', jaccard_coef_int])\n",
"\n",
"estimator = tf.keras.estimator.model_to_estimator(ternaus_net)\n",
"estimator"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Fix the variables in the TEST"
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {},
"outputs": [],
"source": [
"# ternaus_net._make_train_function()\n",
"# train_op = ternaus_net.train_function.updates_op\n",
"\n",
"# var_name = 'block'\n",
"# variables = [x for x in tf.trainable_variables() if var_name in x.name]\n",
"# var_list = list(set(tf.trainable_variables()) - set(variables))\n",
"\n",
"# import numpy as np\n",
"# import mltest\n",
"# feed_dict = {\n",
"# 'input_1:0': np.random.normal(size=(10,)+input_shape),\n",
"# 'logit_target:0': np.random.randint(1, size=(10, 224, 224, 1)),\n",
"# 'logit_sample_weights:0': [0.] * 10\n",
"# }\n",
"\n",
"# # Run the test suite!\n",
"# mltest.test_suite(\n",
"# ternaus_net.output,\n",
"# train_op,\n",
"# feed_dict=feed_dict,\n",
"# var_list=var_list)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"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.6.5"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Loading