diff --git a/.idea/MultiNet.iml b/.idea/MultiNet.iml
new file mode 100644
index 0000000..5c88ce7
--- /dev/null
+++ b/.idea/MultiNet.iml
@@ -0,0 +1,11 @@
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml
new file mode 100644
index 0000000..7972536
--- /dev/null
+++ b/.idea/inspectionProfiles/Project_Default.xml
@@ -0,0 +1,14 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
new file mode 100644
index 0000000..3446b3f
--- /dev/null
+++ b/.idea/misc.xml
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/modules.xml b/.idea/modules.xml
new file mode 100644
index 0000000..b9e755e
--- /dev/null
+++ b/.idea/modules.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
new file mode 100644
index 0000000..cf41716
--- /dev/null
+++ b/.idea/vcs.xml
@@ -0,0 +1,37 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/demo.py b/demo.py
index eca0244..144e640 100644
--- a/demo.py
+++ b/demo.py
@@ -1,12 +1,7 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
-#
-# Author: Marvin Teichmann
-
-
-"""
+'''
Detects Cars in an image using KittiSeg.
-
Input: Image
Output: Image (with Cars plotted in Green)
@@ -16,62 +11,36 @@
Usage:
python demo.py --input data/demo.png [--output_image output_image]
[--logdir /path/to/weights] [--gpus 0]
-
-
-"""
-from __future__ import absolute_import
-from __future__ import division
-from __future__ import print_function
+'''
import json
import logging
import os
import sys
-
import collections
-
-# configure logging
-
-logging.basicConfig(format='%(asctime)s %(levelname)s %(message)s',
- level=logging.INFO,
- stream=sys.stdout)
-
-# https://github.com/tensorflow/tensorflow/issues/2034#issuecomment-220820070
import numpy as np
import scipy as scp
import scipy.misc
import tensorflow as tf
-
import time
-
+import argparse
from PIL import Image, ImageDraw, ImageFont
-
-flags = tf.app.flags
-FLAGS = flags.FLAGS
-
+logging.basicConfig(format='%(asctime)s %(levelname)s %(message)s', level=logging.INFO, stream=sys.stdout)
sys.path.insert(1, 'incl')
-
try:
- # Check whether setup was done correctly
-
import tensorvision.utils as tv_utils
import tensorvision.core as core
except ImportError:
- # You forgot to initialize submodules
logging.error("Could not import the submodules.")
- logging.error("Please execute:"
- "'git submodule update --init --recursive'")
+ logging.error("Please execute:'git submodule update --init --recursive'")
exit(1)
-
-flags.DEFINE_string('logdir', None,
- 'Path to logdir.')
-flags.DEFINE_string('input', None,
- 'Image to apply KittiSeg.')
-flags.DEFINE_string('output', None,
- 'Image to apply KittiSeg.')
-
+parser = argparse.ArgumentParser(argument_default=argparse.SUPPRESS)
+parser.add_argument('--logdir', type=str, default='None', help= "Path to logdir")
+parser.add_argument('--input', type=str, default='data/demo/um_000014.png', help= "Image to apply KittiSeg.")
+parser.add_argument('--output', type=str, default='None', help= "Image to apply KittiSeg.")
+FLAGS = parser.parse_args()
default_run = 'MultiNet_ICCV'
weights_url = ("ftp://mi.eng.cam.ac.uk/"
@@ -98,61 +67,6 @@ def maybe_download_and_extract(runs_dir):
return
-
-def resize_label_image(image, gt_image, image_height, image_width):
- image = scp.misc.imresize(image, size=(image_height, image_width),
- interp='cubic')
- shape = gt_image.shape
- gt_image = scp.misc.imresize(gt_image, size=(image_height, image_width),
- interp='nearest')
-
- return image, gt_image
-
-
-def _output_generator(sess, tensor_list, image_pl, data_file,
- process_image=lambda x: x):
- image_dir = os.path.dirname(data_file)
- with open(data_file) as file:
- for datum in file:
- datum = datum.rstrip()
- image_file = datum.split(" ")[0]
- image_file = os.path.join(image_dir, image_file)
-
- image = scp.misc.imread(image_file)
-
- image = process_image(image)
-
- feed_dict = {image_pl: image}
- start_time = time.time()
- output = sess.run(tensor_list, feed_dict=feed_dict)
- yield image_file, output
-
-
-def eval_runtime(sess, subhypes, image_pl, eval_list, data_file):
- logging.info(' ')
- logging.info('Evaluation complete. Measuring runtime.')
- image_dir = os.path.dirname(data_file)
- with open(data_file) as file:
- for datum in file:
- datum = datum.rstrip()
- image_file = datum.split(" ")[0]
- image_file = os.path.join(image_dir, image_file)
- image = scp.misc.imread(image_file)
- image = process_image(subhypes, image)
- feed = {image_pl: image}
- for i in xrange(100):
- _ = sess.run(eval_list, feed_dict=feed)
- start_time = time.time()
- for i in xrange(100):
- _ = sess.run(eval_list, feed_dict=feed)
- dt = (time.time() - start_time)/100
- logging.info('Joined inference can be conducted at the following rates on'
- ' your machine:')
- logging.info('Speed (msec): %f ', 1000*dt)
- logging.info('Speed (fps): %f ', 1/dt)
- return dt
-
-
def test_constant_input(subhypes):
road_input_conf = subhypes['road']['jitter']
seg_input_conf = subhypes['segmentation']['jitter']
@@ -219,40 +133,17 @@ def road_draw(image, highway):
return np.array(im).astype('float32')
-
-def process_image(subhypes, image):
- hypes = subhypes['road']
- shape = image.shape
- image_height = hypes['jitter']['image_height']
- image_width = hypes['jitter']['image_width']
- assert(image_height >= shape[0])
- assert(image_width >= shape[1])
-
- image = scp.misc.imresize(image, (image_height,
- image_width, 3),
- interp='cubic')
- return image
-
-
def load_united_model(logdir):
subhypes = {}
- subgraph = {}
submodules = {}
- subqueues = {}
-
first_iter = True
-
- meta_hypes = tv_utils.load_hypes_from_logdir(logdir, subdir="",
- base_path='hypes')
+ meta_hypes = tv_utils.load_hypes_from_logdir(logdir, subdir="", base_path='hypes')
for model in meta_hypes['models']:
subhypes[model] = tv_utils.load_hypes_from_logdir(logdir, subdir=model)
hypes = subhypes[model]
hypes['dirs']['output_dir'] = meta_hypes['dirs']['output_dir']
hypes['dirs']['image_dir'] = meta_hypes['dirs']['image_dir']
- submodules[model] = tv_utils.load_modules_from_logdir(logdir,
- dirname=model,
- postfix=model)
-
+ submodules[model] = tv_utils.load_modules_from_logdir(logdir, dirname=model, postfix=model)
modules = submodules[model]
image_pl = tf.placeholder(tf.float32)
@@ -266,14 +157,10 @@ def load_united_model(logdir):
with tf.name_scope('Validation_%s' % model):
reuse = {True: False, False: True}[first_iter]
-
scope = tf.get_variable_scope()
-
with tf.variable_scope(scope, reuse=reuse):
logits = modules['arch'].inference(hypes, image, train=False)
-
- decoded_logits[model] = modules['objective'].decoder(hypes, logits,
- train=False)
+ decoded_logits[model] = modules['objective'].decoder(hypes, logits, train=False)
first_iter = False
sess = tf.Session()
@@ -283,10 +170,10 @@ def load_united_model(logdir):
return meta_hypes, subhypes, submodules, decoded_logits, sess, image_pl
-def main(_):
+def main():
tv_utils.set_gpus_to_use()
- if FLAGS.input is None:
+ if FLAGS.input == 'None':
logging.error("No input was given.")
logging.info(
"Usage: python demo.py --input data/test.png "
@@ -294,13 +181,8 @@ def main(_):
"[--gpus GPUs_to_use] ")
exit(1)
- if FLAGS.logdir is None:
- # Download and use weights from the MultiNet Paper
- if 'TV_DIR_RUNS' in os.environ:
- runs_dir = os.path.join(os.environ['TV_DIR_RUNS'],
- 'MultiNet')
- else:
- runs_dir = 'RUNS'
+ if FLAGS.logdir == 'None':
+ runs_dir = 'RUNS'
maybe_download_and_extract(runs_dir)
logdir = os.path.join(runs_dir, default_run)
else:
@@ -330,6 +212,7 @@ def main(_):
test_segmentation_input(subhypes)
# Load and reseize Image
+
image_file = FLAGS.input
image = scp.misc.imread(image_file)
@@ -339,17 +222,12 @@ def main(_):
image_width = hypes_road['jitter']['image_width']
assert(image_height >= shape[0])
assert(image_width >= shape[1])
-
- image = scp.misc.imresize(image, (image_height,
- image_width, 3),
- interp='cubic')
-
- import utils.train_utils as dec_utils
+ image = scp.misc.imresize(image, (image_height, image_width, 3), interp='cubic')
# Run KittiSeg model on image
feed_dict = {image_pl: image}
output = sess.run(eval_list, feed_dict=feed_dict)
-
+ sess.close()
seg_softmax, pred_boxes_new, pred_confidences, road_softmax = output
# Create Segmentation Overlay
@@ -359,6 +237,7 @@ def main(_):
overlay_image = tv_utils.fast_overlay(image, hard)
# Draw Detection Boxes
+ import utils.train_utils as dec_utils
new_img, rects = dec_utils.add_rectangles(
subhypes['detection'], [overlay_image], pred_confidences,
pred_boxes_new, show_removed=False,
@@ -370,7 +249,6 @@ def main(_):
new_img = road_draw(new_img, highway)
logging.info("")
-
# Printing some more output information
threshold = 0.5
accepted_predictions = []
@@ -393,34 +271,19 @@ def main(_):
logging.info(" Confidence: {}".format(rect.score))
if len(meta_hypes['model_list']) == 3:
- logging.info("Raw Classification Softmax outputs are: {}"
- .format(output[0][0]))
+ logging.info("Raw Classification Softmax outputs are: {}".format(output[0][0]))
# Save output image file
- if FLAGS.output is None:
+ if FLAGS.output == 'None':
output_base_name = FLAGS.input
out_image_name = output_base_name.split('.')[0] + '_out.png'
else:
out_image_name = FLAGS.output
-
scp.misc.imsave(out_image_name, new_img)
logging.info("")
- logging.info("Output image has been saved to: {}".format(
- os.path.realpath(out_image_name)))
-
- logging.info("")
- logging.warning("Do NOT use this Code to evaluate multiple images.")
-
- logging.warning("Demo.py is **very slow** and designed "
- "to be a tutorial to show how the MultiNet works.")
- logging.warning("")
- logging.warning("Please see this comment, if you like to apply demo.py to"
- " multiple images see:")
- logging.warning("https://github.com/MarvinTeichmann/KittiBox/"
- "issues/15#issuecomment-301800058")
-
+ logging.info("Output image has been saved to: {}".format(os.path.realpath(out_image_name)))
exit(0)
if __name__ == '__main__':
- tf.app.run()
+ main()
diff --git a/subhypes_test.py b/subhypes_test.py
new file mode 100644
index 0000000..e69de29