Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automated dataset setup, tf 1.x support, resnet support, keras support #25

Open
wants to merge 173 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
173 commits
Select commit Hold shift + click to select a range
f209718
move explicit paths to a separate script
VittalP Jan 24, 2017
fffa24a
change checkpoint_dir to save_dir
VittalP Jan 24, 2017
ab79067
convert notebook to py script for running in the terminal
VittalP Jan 24, 2017
76989ea
enable MARCC support
VittalP Jan 24, 2017
3e87730
fix typo
VittalP Jan 24, 2017
e0afdc7
automatically download vgg_16.ckpt if not found in checkpoints_dir
VittalP Jan 24, 2017
a92458b
fix slim_path
VittalP Jan 24, 2017
aa1db6b
fix issue with same names
VittalP Jan 25, 2017
217915a
log_folder to log_dir
VittalP Jan 25, 2017
cc48f0a
only the root directory needs to be added
VittalP Jan 25, 2017
3f65fef
Display iteration number along with loss
VittalP Jan 25, 2017
fb84cf4
do not set CUDA env variable on MARCC
VittalP Jan 26, 2017
dae61fc
add fcn32s testing script
VittalP Jan 26, 2017
da50b5d
add script to test fcn8s
VittalP Jan 27, 2017
16221aa
merge .gitignore from 'outer_product'
VittalP Jan 27, 2017
303a91d
ignore log files, tfrecords, etc
VittalP Jan 31, 2017
9a33a06
merge move_paths
VittalP Jan 31, 2017
6253cce
Merge remote-tracking branch 'upstream/master'
VittalP Jan 31, 2017
f33525b
add path relative to cwd
VittalP Jan 31, 2017
2a81b13
don't import function directly
VittalP Jan 31, 2017
c946e8f
add script to finetune resnet
VittalP Jan 31, 2017
caf45b2
have path for data dir
VittalP Jan 31, 2017
87cc75c
read from data_dir
VittalP Jan 31, 2017
541fd65
save, log and data dirs are the root dir
VittalP Jan 31, 2017
8a62db9
support variable learning rate
VittalP Feb 2, 2017
e9517c1
concatenate paths using os join
VittalP Feb 2, 2017
d5c3b1f
make num_epochs a variable
VittalP Feb 2, 2017
fd8740e
Merge branch 'master' of https://github.com/VittalP/tf-image-segmenta…
VittalP Feb 2, 2017
73434cc
test 20 epochs
VittalP Feb 4, 2017
7e727bc
don't concatenate while path join
VittalP Feb 4, 2017
f854e57
pass feed_dict as parameter
VittalP Feb 4, 2017
cf76aaf
support adjusted learning rate
VittalP Feb 5, 2017
623ee90
Merge branch 'master' of https://github.com/warmspringwinds/tf-image-…
VittalP Feb 5, 2017
846b613
merge from test_branch
VittalP Feb 6, 2017
8920a95
Merge branch 'master' of https://github.com/warmspringwinds/tf-image-…
VittalP Feb 6, 2017
0e2f3b8
Merge branch 'master' of https://github.com/VittalP/tf-image-segmenta…
VittalP Feb 6, 2017
d256fd4
Merge pull request #1 from VittalP/move_paths
ahundt Feb 9, 2017
2bccd78
Squashed 'tf_image_segmentation/models/densenet-fcn/' content from co…
ahundt Feb 9, 2017
1ddcb99
Merge commit '2bccd78a8e02b6552b91b64cb52ee6a11414b74e' as 'tf_image_…
ahundt Feb 9, 2017
d3c0009
PASCAL VOC download instructions
ahundt Feb 9, 2017
788c19d
pascal voc converion simplified
ahundt Feb 9, 2017
f7a955c
densenet network created
ahundt Feb 9, 2017
7986169
add update ops to collect moving average and moving variance
VittalP Feb 9, 2017
4dba0d4
Merge branch 'master' of https://github.com/warmspringwinds/tf-image-…
VittalP Feb 9, 2017
f21fed2
keras style dataset training
ahundt Feb 10, 2017
d95cace
densenet_fcn.py tf mode almost working fails initializing optimizer
ahundt Feb 11, 2017
dcf25a1
add missing _init_.py
ahundt Feb 11, 2017
8ea2672
improve loading of resnet v1 101 8s ipynb
ahundt Feb 11, 2017
65a7e63
unet.py simplified fcn added
ahundt Feb 11, 2017
c6ff8af
resnet_v1_101_16s_train is more general
ahundt Feb 11, 2017
cd7df53
densenet.fc now correctly creates ops, small tweak needed for sesion.run
ahundt Feb 11, 2017
64ccdd4
add mscoco support
VittalP Feb 14, 2017
77f1558
update test notebook: valset=65%
VittalP Feb 14, 2017
b1eefb9
fix merge conflict on test notebook
VittalP Feb 14, 2017
8d7f9b9
Merge branch 'mscoco' of https://github.com/VittalP/tf-image-segmenta…
VittalP Feb 14, 2017
818cc4e
add script to convert mscoco dataset to tfrecords
VittalP Feb 14, 2017
49fbfc4
merge tf_records from master
VittalP Feb 14, 2017
23ec24f
add script to convert mscoco to tfrecords
VittalP Feb 14, 2017
0cad606
delete mscoco script from utils
VittalP Feb 14, 2017
e6dbf43
densenet_fcn.py no longer crashes before training starts, but trainin…
ahundt Feb 14, 2017
abb43e6
move tf cast to float back out of tfrecord loading
ahundt Feb 14, 2017
32f2b6d
densnet_fc.py and densenet_fcn.py can now train on pascal_voc
ahundt Feb 18, 2017
20dfce3
.gitignore ignores tfrecords
ahundt Feb 18, 2017
e581465
merge gitignore from master
VittalP Feb 20, 2017
ece17a9
add script to convert from json to seg_mask
VittalP Feb 20, 2017
fc9beb7
hack to fix scope issue
VittalP Feb 21, 2017
fede25e
hack to fix scope issue
VittalP Feb 21, 2017
694564a
clean up some variables
VittalP Feb 21, 2017
e00b54d
Merge branch 'mscoco' of https://github.com/VittalP/tf-image-segmenta…
VittalP Feb 21, 2017
3e15959
remove manual path settings
ahundt Mar 12, 2017
9bae8ee
remove densenet_fcn model folder because it is now in keras-contrib
ahundt Mar 12, 2017
5711949
densenet_fcn.py fixed FLAGS
ahundt Mar 12, 2017
d9c72ae
Merge commit '08412ad5a4e9896eec4dfe2e8a803c187418636e' into ahundt-k…
ahundt Mar 12, 2017
2a22ac5
Merge commit 'e00b54dda39664f7464d48fdb08cec8afa32ce7e' from mscoco i…
ahundt Mar 12, 2017
974d4ae
initial sacred.readthedocs.io coco implementation
ahundt Mar 17, 2017
74dd4a6
data_pascal_voc.py initial implementation
ahundt Mar 17, 2017
f742639
data_pascal_voc fix errors
ahundt Mar 17, 2017
22a1db1
dataset command line support
ahundt Mar 18, 2017
01c0e87
recipes try to fix script running
ahundt Mar 18, 2017
128675e
recipes create runnable experiments for datasets
ahundt Mar 18, 2017
0cb1bbd
data_pascal_voc.py full setup command
ahundt Mar 18, 2017
94b8f6a
data_pascal_voc.py attempted loading fix
ahundt Mar 18, 2017
4ca260d
data_pascal_voc.py typo fix
ahundt Mar 18, 2017
b7559a4
data_pascal_voc.py as experiment
ahundt Mar 18, 2017
5e2cb2a
data_pascal_voc.py config scope fix
ahundt Mar 18, 2017
da44a03
data_pascal_voc.py try member access
ahundt Mar 18, 2017
92f1005
dta_pascal_voc.py try dataset
ahundt Mar 18, 2017
88b42e3
data_pascal_voc.py include ingredients directly
ahundt Mar 18, 2017
4132ae2
data_pascal_voc.py import path fix
ahundt Mar 18, 2017
140b284
data_pascal_voc fix function calls
ahundt Mar 18, 2017
a206bab
revertme
ahundt Mar 18, 2017
b4a9e79
test
ahundt Mar 18, 2017
71fa80e
test
ahundt Mar 18, 2017
8237e05
test
ahundt Mar 18, 2017
9669ec6
test
ahundt Mar 18, 2017
561c492
try automain
ahundt Mar 18, 2017
39289e1
cut out all modularity
ahundt Mar 18, 2017
a665165
remove all modularity
ahundt Mar 18, 2017
b494e73
remove all modularity
ahundt Mar 18, 2017
7b7760a
remove settings
ahundt Mar 18, 2017
6756cb5
data_pascal_voc extraction
ahundt Mar 19, 2017
a92133f
pascal_voc_download and extract works
ahundt Mar 19, 2017
af978e2
switch to command line based
ahundt Mar 19, 2017
23c654a
run full setup
ahundt Mar 19, 2017
1b378b3
fix infinite loop
ahundt Mar 19, 2017
d13fea6
remove accidentally committed files
ahundt Mar 19, 2017
8cb2606
stop tracking accidentally committed files
ahundt Mar 19, 2017
258e004
data_pascal_voc.py minor cleanup
ahundt Mar 19, 2017
5570a52
data_coco.py major cleanup
ahundt Mar 19, 2017
a0970e9
data_coco.py path fixes
ahundt Mar 19, 2017
2b158c7
coco and pascal md5 support
ahundt Mar 20, 2017
b87946c
data_coco.py md5 fix
ahundt Mar 20, 2017
03773a9
get_file() extract param in fchollet/keras/#5861
ahundt Mar 20, 2017
9dcfd1e
coco_json_to_segmentation() typo fix
ahundt Mar 20, 2017
6706df2
data_coco.py md5 fix
ahundt Mar 20, 2017
6a4d4c6
print annotation_paths
ahundt Mar 20, 2017
4494519
add print_coco_files
ahundt Mar 20, 2017
6262ee4
data_coco.py seg mask list fix
ahundt Mar 20, 2017
4a0f293
data_coco.py path typo
ahundt Mar 20, 2017
df6a37a
data_coco.py better errors
ahundt Mar 21, 2017
80762e1
data_coco.py param fix
ahundt Mar 21, 2017
d5b878b
data_coco.py better printouts
ahundt Mar 21, 2017
6ffa788
data_coco.py debug info
ahundt Mar 21, 2017
13265a0
data_coco.py better error output
ahundt Mar 21, 2017
135accf
data_coco.py annotations is now instances
ahundt Mar 21, 2017
8f00099
data_coco.py update for api change
ahundt Mar 21, 2017
14b50e3
data_coco.py create output dir if needed
ahundt Mar 21, 2017
af93f9b
data_coco.py initial one hot encoding integration
ahundt Apr 6, 2017
c0484fc
data_coco.py fix for function and object with same name
ahundt Apr 6, 2017
31218ce
data_coco.py verbose conversion printouts
ahundt Apr 6, 2017
aa55f32
data_coco.py json to segmentation verbose param
ahundt Apr 6, 2017
f955d56
data_coco.py switch to progbar
ahundt Apr 6, 2017
b5c2244
data_coco.py progbar fix
ahundt Apr 6, 2017
a66cf7b
data_coco.py progbar verbose
ahundt Apr 6, 2017
a7ab914
data_coco.py added stat calculation capabilities
ahundt Apr 6, 2017
ed83126
data_coco.py image and category stats
ahundt Apr 6, 2017
9bacb54
data_coco.py typo fix
ahundt Apr 6, 2017
bae251c
data_coco.py missing variable fix
ahundt Apr 6, 2017
3747c7b
data_coco.py bincount fix
ahundt Apr 6, 2017
58fad68
data_coco.py typo fix
ahundt Apr 6, 2017
eb53398
data_coco.py image stats main loop runs
ahundt Apr 6, 2017
24de844
data_coco.py stats aren't run in overall setup
ahundt Apr 6, 2017
a107940
Make forward/backward compatible with tf-1.0.x.
barryridge Apr 6, 2017
f0bfe07
data_coco.py float64 type bugfix
ahundt Apr 6, 2017
45030b4
data_coco.py fix divide
ahundt Apr 9, 2017
0b91e3a
data_coco.py var name error fixed
ahundt Apr 9, 2017
5bd7f0d
print annotation file info
ahundt Apr 9, 2017
0934e0d
data_coco.py print extra info
ahundt Apr 9, 2017
bc5c32d
data_coco.py init bug
ahundt Apr 9, 2017
e72e6f8
data_coco.py improve notes
ahundt Apr 9, 2017
f5b2972
data_coco.py print category names and supercategories
ahundt Apr 9, 2017
8eac0fa
data_coco.py more useful stats
ahundt Apr 10, 2017
fa93a27
data_coco.py typo fix
ahundt Apr 10, 2017
37ab452
data_coco.py support lading class weighting from a file
ahundt Apr 10, 2017
505807d
data_coco.py rename class_weighting to class_weight
ahundt Apr 10, 2017
d42ff41
data_coco.py add coco_to_pascal_voc_imageset_txt
ahundt Apr 10, 2017
54eacba
data_coco.py typo fix
ahundt Apr 10, 2017
7b15c81
data_coco.py put pascal voc in annotations folder
ahundt Apr 10, 2017
1075e2b
data_coco.py file fix
ahundt Apr 10, 2017
4e70b69
data_pascal_voc.py add pascal_voc_berkeley_combined()
ahundt Apr 13, 2017
8e370a5
small path fix
ahundt Apr 13, 2017
d22922f
pascal_voc.py add missing import
ahundt Apr 19, 2017
af3b095
add pascal-context
ahundt Apr 19, 2017
f1afc2c
add pascal context to download list
ahundt Apr 19, 2017
2833e95
pascal context link
ahundt Apr 19, 2017
75f9470
Remove version checks for >=tf-1.0.x compatibility
barryridge Apr 29, 2017
fbbb104
fixed paths for resnet_101, added reasonable default paths
ahundt May 5, 2017
121882e
Merge branch 'Keras-FCN' of github.com:ahundt/tf-image-segmentation i…
ahundt May 5, 2017
6fbb2fb
Merge pull request #16 from barryridge/tf-1.0.x-compatibility
ahundt May 5, 2017
cac3f52
resnet_v1 101 8s training runs on tensorflow 1.1
ahundt May 6, 2017
6157d7e
Merge commit 'dd02343d8e0df9b4aa9a9d217999bef8b32903bb' into ahundt-k…
ahundt Jun 19, 2017
f5e8570
cleanup
ahundt Jun 19, 2017
b990a13
whitespace
ahundt Jun 21, 2017
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
11 changes: 11 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,13 @@
# file tpyes to ignore
.ipynb_checkpoints
*.pyc
*.tfrecords
*.log
*.ckpt*

# Files
Untitled*

# directories to ignore
/log_dir
/save_dir
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,17 @@ the PASCAL VOC 2012 Training data and additional Berkeley segmentation data for
It was important to test models on restricted Validation dataset to make sure no images in the
validation dataset were seen by model during training.

Here is how to download the datasets:
```bash

# original PASCAL VOC 2012
curl -O http://host.robots.ox.ac.uk/pascal/VOC/voc2012/VOCtrainval_11-May-2012.tar # 2 GB

# berkeley augmented PASCAL VOC
curl -O http://www.eecs.berkeley.edu/Research/Projects/CS/vision/grouping/semantic_contours/benchmark.tgz # 1.3 GB
```


The code to acquire the training and validating the model is also provided in the framework.

### Fully Convolutional Networks for Semantic Segmentation (FCNs)
Expand Down
11 changes: 7 additions & 4 deletions tf_image_segmentation/models/fcn_16s.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
from preprocessing import vgg_preprocessing
from ..utils.upsampling import bilinear_upsample_weights

# For comparing tf versions for backwards compatibility
from packaging import version

slim = tf.contrib.slim

# Mean values for VGG-16
Expand Down Expand Up @@ -83,7 +86,7 @@ def FCN_16s(image_batch_tensor,


# Calculate the ouput size of the upsampled tensor
last_layer_upsampled_by_factor_2_logits_shape = tf.pack([
last_layer_upsampled_by_factor_2_logits_shape = tf.stack([
last_layer_logits_shape[0],
last_layer_logits_shape[1] * 2,
last_layer_logits_shape[2] * 2,
Expand All @@ -108,7 +111,7 @@ def FCN_16s(image_batch_tensor,
[1, 1],
activation_fn=None,
normalizer_fn=None,
weights_initializer=tf.zeros_initializer,
weights_initializer=tf.zeros_initializer(),
scope='pool4_fc')

fused_last_layer_and_pool4_logits = pool4_logits + last_layer_upsampled_by_factor_2_logits
Expand All @@ -117,7 +120,7 @@ def FCN_16s(image_batch_tensor,


# Calculate the ouput size of the upsampled tensor
fused_last_layer_and_pool4_upsampled_by_factor_16_logits_shape = tf.pack([
fused_last_layer_and_pool4_upsampled_by_factor_16_logits_shape = tf.stack([
fused_last_layer_and_pool4_logits_shape[0],
fused_last_layer_and_pool4_logits_shape[1] * 16,
fused_last_layer_and_pool4_logits_shape[2] * 16,
Expand Down Expand Up @@ -146,4 +149,4 @@ def FCN_16s(image_batch_tensor,
original_fcn_32s_checkpoint_string = 'fcn_32s/' + variable.name[len(fcn_16s_scope.original_name_scope):-2]
fcn_32s_variables_mapping[original_fcn_32s_checkpoint_string] = variable

return fused_last_layer_and_pool4_upsampled_by_factor_16_logits, fcn_32s_variables_mapping
return fused_last_layer_and_pool4_upsampled_by_factor_16_logits, fcn_32s_variables_mapping
7 changes: 5 additions & 2 deletions tf_image_segmentation/models/fcn_32s.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
from preprocessing import vgg_preprocessing
from ..utils.upsampling import bilinear_upsample_weights

# For comparing tf versions for backwards compatibility
from packaging import version

slim = tf.contrib.slim

# Mean values for VGG-16
Expand Down Expand Up @@ -114,7 +117,7 @@ def FCN_32s(image_batch_tensor,
downsampled_logits_shape = tf.shape(logits)

# Calculate the ouput size of the upsampled tensor
upsampled_logits_shape = tf.pack([
upsampled_logits_shape = tf.stack([
downsampled_logits_shape[0],
downsampled_logits_shape[1] * upsample_factor,
downsampled_logits_shape[2] * upsample_factor,
Expand Down Expand Up @@ -147,4 +150,4 @@ def FCN_32s(image_batch_tensor,
original_vgg_16_checkpoint_string = variable.name[len(fcn_32s_scope.name)+1:-2]
vgg_16_variables_mapping[original_vgg_16_checkpoint_string] = variable

return upsampled_logits, vgg_16_variables_mapping
return upsampled_logits, vgg_16_variables_mapping
15 changes: 9 additions & 6 deletions tf_image_segmentation/models/fcn_8s.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
from preprocessing import vgg_preprocessing
from ..utils.upsampling import bilinear_upsample_weights

# For comparing tf versions for backwards compatibility
from packaging import version

slim = tf.contrib.slim

# Mean values for VGG-16
Expand Down Expand Up @@ -83,7 +86,7 @@ def FCN_8s(image_batch_tensor,


# Calculate the ouput size of the upsampled tensor
last_layer_upsampled_by_factor_2_logits_shape = tf.pack([
last_layer_upsampled_by_factor_2_logits_shape = tf.stack([
last_layer_logits_shape[0],
last_layer_logits_shape[1] * 2,
last_layer_logits_shape[2] * 2,
Expand All @@ -110,7 +113,7 @@ def FCN_8s(image_batch_tensor,
[1, 1],
activation_fn=None,
normalizer_fn=None,
weights_initializer=tf.zeros_initializer,
weights_initializer=tf.zeros_initializer(),
scope='pool4_fc')

fused_last_layer_and_pool4_logits = pool4_logits + last_layer_upsampled_by_factor_2_logits
Expand All @@ -121,7 +124,7 @@ def FCN_8s(image_batch_tensor,


# Calculate the ouput size of the upsampled tensor
fused_last_layer_and_pool4_upsampled_by_factor_2_logits_shape = tf.pack([
fused_last_layer_and_pool4_upsampled_by_factor_2_logits_shape = tf.stack([
fused_last_layer_and_pool4_logits_shape[0],
fused_last_layer_and_pool4_logits_shape[1] * 2,
fused_last_layer_and_pool4_logits_shape[2] * 2,
Expand All @@ -147,7 +150,7 @@ def FCN_8s(image_batch_tensor,
[1, 1],
activation_fn=None,
normalizer_fn=None,
weights_initializer=tf.zeros_initializer,
weights_initializer=tf.zeros_initializer(),
scope='pool3_fc')


Expand All @@ -159,7 +162,7 @@ def FCN_8s(image_batch_tensor,


# Calculate the ouput size of the upsampled tensor
fused_last_layer_and_pool4_logits_and_pool_3_upsampled_by_factor_8_logits_shape = tf.pack([
fused_last_layer_and_pool4_logits_and_pool_3_upsampled_by_factor_8_logits_shape = tf.stack([
fused_last_layer_and_pool4_logits_and_pool_3_logits_shape[0],
fused_last_layer_and_pool4_logits_and_pool_3_logits_shape[1] * 8,
fused_last_layer_and_pool4_logits_and_pool_3_logits_shape[2] * 8,
Expand Down Expand Up @@ -191,4 +194,4 @@ def FCN_8s(image_batch_tensor,
original_fcn_16s_checkpoint_string = 'fcn_16s/' + variable.name[len(fcn_8s_scope.original_name_scope):-2]
fcn_16s_variables_mapping[original_fcn_16s_checkpoint_string] = variable

return fused_last_layer_and_pool4_logits_and_pool_3_upsampled_by_factor_8_logits, fcn_16s_variables_mapping
return fused_last_layer_and_pool4_logits_and_pool_3_upsampled_by_factor_8_logits, fcn_16s_variables_mapping
7 changes: 5 additions & 2 deletions tf_image_segmentation/models/resnet_v1_101_16s.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
from preprocessing import vgg_preprocessing
from ..utils.upsampling import bilinear_upsample_weights

# For comparing tf versions for backwards compatibility
from packaging import version

slim = tf.contrib.slim

# Mean values for VGG-16
Expand Down Expand Up @@ -116,7 +119,7 @@ def resnet_v1_101_16s(image_batch_tensor,
downsampled_logits_shape = tf.shape(logits)

# Calculate the ouput size of the upsampled tensor
upsampled_logits_shape = tf.pack([
upsampled_logits_shape = tf.stack([
downsampled_logits_shape[0],
downsampled_logits_shape[1] * upsample_factor,
downsampled_logits_shape[2] * upsample_factor,
Expand Down Expand Up @@ -145,4 +148,4 @@ def resnet_v1_101_16s(image_batch_tensor,
original_resnet_v1_101_checkpoint_string = variable.name[len(resnet_v1_101_16s.original_name_scope):-2]
resnet_v1_101_16s_variables_mapping[original_resnet_v1_101_checkpoint_string] = variable

return upsampled_logits, resnet_v1_101_16s_variables_mapping
return upsampled_logits, resnet_v1_101_16s_variables_mapping
24 changes: 16 additions & 8 deletions tf_image_segmentation/models/resnet_v1_101_8s.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from preprocessing.vgg_preprocessing import _R_MEAN, _G_MEAN, _B_MEAN


def extract_resnet_v1_101_mapping_without_logits(resnet_v1_101_variables_mapping):
def extract_resnet_v1_101_mapping_without_logits(resnet_v1_101_variables_mapping, mapping_prefix=''):
"""Removes the logits variable mapping from resnet_v1_101_8s to resnet_v1_101 model mapping dict.
Given the resnet_v1_101_8s to resnet_v1_101 model mapping dict which is returned by
resnet_v1_101_8s() function, remove the mapping for the fc8 variable. This is done because this
Expand All @@ -24,6 +24,13 @@ def extract_resnet_v1_101_mapping_without_logits(resnet_v1_101_variables_mapping
Dict which maps the resnet_v1_101_8s model's variables to resnet_v1_101 checkpoint variables
names. Look at resnet_v1_101_8s() function for more details.

mapping_prefix : string
mapping_prefix is the prefix added to convert the names of the tensors you've created to match
the names of the tensors in the saved model checkpoint. When loading from imagenet pretrained
weights such as http://download.tensorflow.org/models/resnet_v1_101_2016_08_28.tar.gz,
use the default empty mapping prefix, then when reloading from a checkpoint use
'resnet_v1_101_8s/'.

Returns
-------
updated_mapping : dict {string: variable}
Expand All @@ -37,11 +44,12 @@ def extract_resnet_v1_101_mapping_without_logits(resnet_v1_101_variables_mapping
resnet_v1_101_without_logits_keys = []

for key in resnet_v1_101_keys:

print key
if 'logits' not in key:
resnet_v1_101_without_logits_keys.append(key)

updated_mapping = {key: resnet_v1_101_variables_mapping[key] for key in resnet_v1_101_without_logits_keys}
# TODO: fix the following hack to get the scope right
# updated_mapping = {'resnet_v1_101_8s/' + key: resnet_v1_101_variables_mapping[key] for key in resnet_v1_101_without_logits_keys}
updated_mapping = {mapping_prefix + key: resnet_v1_101_variables_mapping[key] for key in resnet_v1_101_without_logits_keys}

return updated_mapping

Expand Down Expand Up @@ -110,13 +118,14 @@ def resnet_v1_101_8s(image_batch_tensor,
number_of_classes,
is_training=is_training,
global_pool=False,
output_stride=8)
output_stride=8,
spatial_squeeze=False)


downsampled_logits_shape = tf.shape(logits)

# Calculate the ouput size of the upsampled tensor
upsampled_logits_shape = tf.pack([
upsampled_logits_shape = tf.stack([
downsampled_logits_shape[0],
downsampled_logits_shape[1] * upsample_factor,
downsampled_logits_shape[2] * upsample_factor,
Expand All @@ -139,10 +148,9 @@ def resnet_v1_101_8s(image_batch_tensor,
resnet_v1_101_8s_variables = slim.get_variables(resnet_v1_101_8s)

for variable in resnet_v1_101_8s_variables:

# Here we remove the part of a name of the variable
# that is responsible for the current variable scope
original_resnet_v1_101_checkpoint_string = variable.name[len(resnet_v1_101_8s.original_name_scope):-2]
resnet_v1_101_8s_variables_mapping[original_resnet_v1_101_checkpoint_string] = variable

return upsampled_logits, resnet_v1_101_8s_variables_mapping
return upsampled_logits, resnet_v1_101_8s_variables_mapping
7 changes: 5 additions & 2 deletions tf_image_segmentation/models/resnet_v1_50_16s.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
from preprocessing import vgg_preprocessing
from ..utils.upsampling import bilinear_upsample_weights

# For comparing tf versions for backwards compatibility
from packaging import version

slim = tf.contrib.slim

# Mean values for VGG-16
Expand Down Expand Up @@ -116,7 +119,7 @@ def resnet_v1_50_16s(image_batch_tensor,
downsampled_logits_shape = tf.shape(logits)

# Calculate the ouput size of the upsampled tensor
upsampled_logits_shape = tf.pack([
upsampled_logits_shape = tf.stack([
downsampled_logits_shape[0],
downsampled_logits_shape[1] * upsample_factor,
downsampled_logits_shape[2] * upsample_factor,
Expand Down Expand Up @@ -145,4 +148,4 @@ def resnet_v1_50_16s(image_batch_tensor,
original_resnet_v1_50_checkpoint_string = variable.name[len(resnet_v1_50_16s.original_name_scope):-2]
resnet_v1_50_16s_variables_mapping[original_resnet_v1_50_checkpoint_string] = variable

return upsampled_logits, resnet_v1_50_16s_variables_mapping
return upsampled_logits, resnet_v1_50_16s_variables_mapping
7 changes: 5 additions & 2 deletions tf_image_segmentation/models/resnet_v1_50_8s.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
from preprocessing import vgg_preprocessing
from ..utils.upsampling import bilinear_upsample_weights

# For comparing tf versions for backwards compatibility
from packaging import version

slim = tf.contrib.slim

# Mean values for VGG-16
Expand Down Expand Up @@ -116,7 +119,7 @@ def resnet_v1_50_8s(image_batch_tensor,
downsampled_logits_shape = tf.shape(logits)

# Calculate the ouput size of the upsampled tensor
upsampled_logits_shape = tf.pack([
upsampled_logits_shape = tf.stack([
downsampled_logits_shape[0],
downsampled_logits_shape[1] * upsample_factor,
downsampled_logits_shape[2] * upsample_factor,
Expand Down Expand Up @@ -145,4 +148,4 @@ def resnet_v1_50_8s(image_batch_tensor,
original_resnet_v1_50_checkpoint_string = variable.name[len(resnet_v1_50_8s.original_name_scope):-2]
resnet_v1_50_8s_variables_mapping[original_resnet_v1_50_checkpoint_string] = variable

return upsampled_logits, resnet_v1_50_8s_variables_mapping
return upsampled_logits, resnet_v1_50_8s_variables_mapping
60 changes: 60 additions & 0 deletions tf_image_segmentation/models/unet.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@

import numpy as np
from keras.layers.core import Reshape, Activation
from keras.models import Model
from keras.layers import Input, merge, Convolution2D, MaxPooling2D, UpSampling2D
from keras.optimizers import Adam
from keras.callbacks import ModelCheckpoint, LearningRateScheduler
from keras import backend as K

# https://github.com/jocicmarko/ultrasound-nerve-segmentation/blob/master/train.py
def get_unet(image_size, num_classes, tensor=None):

concat_axis = 1 if K.image_dim_ordering() == "th" else -1
inputs = Input(image_size, tensor=tensor)
conv1 = Convolution2D(32, 3, 3, activation='relu', border_mode='same')(inputs)
conv1 = Convolution2D(32, 3, 3, activation='relu', border_mode='same')(conv1)
pool1 = MaxPooling2D(pool_size=(2, 2))(conv1)

conv2 = Convolution2D(64, 3, 3, activation='relu', border_mode='same')(pool1)
conv2 = Convolution2D(64, 3, 3, activation='relu', border_mode='same')(conv2)
pool2 = MaxPooling2D(pool_size=(2, 2))(conv2)

conv3 = Convolution2D(128, 3, 3, activation='relu', border_mode='same')(pool2)
conv3 = Convolution2D(128, 3, 3, activation='relu', border_mode='same')(conv3)
pool3 = MaxPooling2D(pool_size=(2, 2))(conv3)

conv4 = Convolution2D(256, 3, 3, activation='relu', border_mode='same')(pool3)
conv4 = Convolution2D(256, 3, 3, activation='relu', border_mode='same')(conv4)
pool4 = MaxPooling2D(pool_size=(2, 2))(conv4)

conv5 = Convolution2D(512, 3, 3, activation='relu', border_mode='same')(pool4)
conv5 = Convolution2D(512, 3, 3, activation='relu', border_mode='same')(conv5)

up6 = merge([UpSampling2D(size=(2, 2))(conv5), conv4], mode='concat', concat_axis=concat_axis)
conv6 = Convolution2D(256, 3, 3, activation='relu', border_mode='same')(up6)
conv6 = Convolution2D(256, 3, 3, activation='relu', border_mode='same')(conv6)

up7 = merge([UpSampling2D(size=(2, 2))(conv6), conv3], mode='concat', concat_axis=concat_axis)
conv7 = Convolution2D(128, 3, 3, activation='relu', border_mode='same')(up7)
conv7 = Convolution2D(128, 3, 3, activation='relu', border_mode='same')(conv7)

up8 = merge([UpSampling2D(size=(2, 2))(conv7), conv2], mode='concat', concat_axis=concat_axis)
conv8 = Convolution2D(64, 3, 3, activation='relu', border_mode='same')(up8)
conv8 = Convolution2D(64, 3, 3, activation='relu', border_mode='same')(conv8)

up9 = merge([UpSampling2D(size=(2, 2))(conv8), conv1], mode='concat', concat_axis=concat_axis)
conv9 = Convolution2D(32, 3, 3, activation='relu', border_mode='same')(up9)
conv9 = Convolution2D(32, 3, 3, activation='relu', border_mode='same')(conv9)

conv10 = Convolution2D(num_classes, 1, 1, activation='relu')(conv9)

x = Reshape((image_size[0]*image_size[1], num_classes))(conv10)

x = Activation('softmax')(x)

x = Reshape((image_size[0], image_size[1], num_classes))(x)

model = Model(input=inputs, output=x)

return model
Empty file.
Loading