Skip to content

Commit 1dcf50a

Browse files
Creating first model for semantic endoscopy segmentation
1 parent f1a9c27 commit 1dcf50a

11 files changed

+1240
-0
lines changed

Diff for: .gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ __pycache__/
33
*.py[cod]
44
*$py.class
55

6+
DATA/*
7+
output/*
8+
69
# C extensions
710
*.so
811

Diff for: DATA/all.txt

+160
Large diffs are not rendered by default.

Diff for: config.py

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Dictionaries
2+
default_name = "trash"
3+
data_dir = "DATA"
4+
model_dir = "output"
5+
default_config = "hypes/medseg.json"

Diff for: eval.py

+114
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
"""Evaluation of the Model.
2+
3+
4+
"""
5+
from __future__ import absolute_import
6+
from __future__ import division
7+
from __future__ import print_function
8+
9+
from datetime import datetime
10+
import math
11+
import time
12+
13+
import tensorflow.python.platform
14+
from tensorflow.python.platform import gfile
15+
import numpy as np
16+
import tensorflow as tf
17+
import os
18+
19+
import utils
20+
import logging
21+
import sys
22+
import imp
23+
24+
25+
logging.basicConfig(format='%(asctime)s %(levelname)s %(message)s',
26+
level=logging.DEBUG,
27+
stream=sys.stdout)
28+
29+
30+
FLAGS = tf.app.flags.FLAGS
31+
tf.app.flags.DEFINE_string('eval_data', 'test',
32+
"""Either 'test' or 'train_eval'.""")
33+
34+
35+
# TODO: Iterate over all possible Values
36+
# Write Values to Tensorboard
37+
38+
39+
40+
def evaluate(train_dir):
41+
"""Loads the model and runs evaluation
42+
"""
43+
44+
target_dir = os.path.join(train_dir, "model_files")
45+
params = imp.load_source("params", os.path.join(target_dir, "params.py"))
46+
data_input = imp.load_source("input", os.path.join(target_dir, "input.py"))
47+
network = imp.load_source("network", os.path.join(target_dir, "network.py"))
48+
49+
with tf.Graph().as_default():
50+
51+
# Retrieve images and labels
52+
eval_data = FLAGS.eval_data == 'test'
53+
images, labels = data_input.inputs(eval_data=eval_data, data_dir=utils.cfg.data_dir,
54+
batch_size=params.batch_size)
55+
56+
# Generate placeholders for the images and labels.
57+
keep_prob = utils.placeholder_inputs(params.batch_size)
58+
59+
# Build a Graph that computes predictions from the inference model.
60+
logits = network.inference(images, keep_prob)
61+
62+
# Add to the Graph the Ops for loss calculation.
63+
loss = network.loss(logits, labels)
64+
65+
# Calculate predictions.
66+
top_k_op = tf.nn.in_top_k(logits, labels, 1)
67+
68+
# Add the Op to compare the logits to the labels during evaluation.
69+
eval_correct = network.evaluation(logits, labels)
70+
71+
# Build the summary operation based on the TF collection of Summaries.
72+
summary_op = tf.merge_all_summaries()
73+
74+
# Create a saver for writing training checkpoints.
75+
saver = tf.train.Saver()
76+
77+
# Create a session for running Ops on the Graph.
78+
sess = tf.Session()
79+
80+
# Run the Op to initialize the variables.
81+
init = tf.initialize_all_variables()
82+
sess.run(init)
83+
84+
# Start the queue runners.
85+
tf.train.start_queue_runners(sess=sess)
86+
87+
ckpt = tf.train.get_checkpoint_state(train_dir)
88+
if ckpt and ckpt.model_checkpoint_path:
89+
saver.restore(sess, ckpt.model_checkpoint_path)
90+
else:
91+
print("No checkpoints found! ")
92+
exit(1)
93+
94+
print("Doing Evaluation with lots of data")
95+
utils.do_eval(sess=sess,
96+
eval_correct=eval_correct,
97+
keep_prob=keep_prob,
98+
num_examples=params.num_examples_per_epoch_for_eval,
99+
params=params,
100+
name="eval")
101+
102+
103+
104+
105+
def main(_):
106+
107+
train_dir = utils.get_train_dir()
108+
evaluate(train_dir)
109+
110+
111+
112+
113+
if __name__ == '__main__':
114+
tf.app.run()

Diff for: hypes/medseg.json

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{
2+
"model": {
3+
"input_file": "model/medseg_input.py",
4+
"arch_file" : "model/VGG8.py",
5+
"solver_file" : "model/adam_optimizer.py"
6+
},
7+
8+
"data": {
9+
"train_file" : "train.txt",
10+
"val_file" : "val.txt",
11+
"num_examples_per_epoch_for_train" : 10000,
12+
"num_examples_per_epoch_for_eval" : 1000,
13+
"background_color" : [0],
14+
"instrument_color" : [[70], [160]]
15+
},
16+
17+
"arch": {
18+
"num_classes" : 2,
19+
"image_size" : 50,
20+
"num_channels" : 3
21+
},
22+
23+
"logging": {
24+
},
25+
26+
"solver": {
27+
"opt": null,
28+
"batch_size": 64,
29+
"epsilon": 0.00001,
30+
"learning_rate": 1e-4,
31+
"max_steps": 100000
32+
}
33+
}

0 commit comments

Comments
 (0)