diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..073df75 --- /dev/null +++ b/Makefile @@ -0,0 +1,8 @@ +upload: + make clean + python3 setup.py sdist bdist_wheel && twine upload dist/* + +clean: + python setup.py clean --all + pyclean . + rm -rf *.pyc __pycache__ build dist tensorvision.egg-info tensorvision/__pycache__ tests/__pycache__ tests/reports docs/build diff --git a/README.md b/README.md index 024e0a8..07df0c7 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,4 @@ [![Documentation Status](https://readthedocs.org/projects/tensorvision/badge/?version=latest)](http://tensorvision.readthedocs.org/en/latest/?badge=latest) -[![Code Issues](https://www.quantifiedcode.com/api/v1/project/3ef49e94e03a42b0bf896f5377c8e741/badge.svg)](https://www.quantifiedcode.com/app/project/3ef49e94e03a42b0bf896f5377c8e741) [![license](https://img.shields.io/github/license/mashape/apistatus.svg?maxAge=2592000)](https://github.com/ TensorVision/TensorVision/blob/master/LICENSE) diff --git a/setup.py b/setup.py index 25d40a0..e5d9553 100644 --- a/setup.py +++ b/setup.py @@ -45,7 +45,8 @@ description="A library to build and train neural networks " "in with TensorFlow for Computer Vision", long_description="\n\n".join([README, CHANGES]), - classifiers=["Development Status :: 1 - Planning", + long_description_content_type='text/markdown', + classifiers=["Development Status :: 7 - Inactive", "Intended Audience :: Developers", "Intended Audience :: Science/Research", "License :: OSI Approved :: MIT License", diff --git a/tensorvision/__init__.py b/tensorvision/__init__.py index a19f475..26e1382 100644 --- a/tensorvision/__init__.py +++ b/tensorvision/__init__.py @@ -1,3 +1,3 @@ """Tools to train neural networks for computer vision in TensorFlow.""" -__version__ = "0.1.dev1" +__version__ = "0.1.dev2" diff --git a/tensorvision/analyze.py b/tensorvision/analyze.py index dbf149f..18be429 100644 --- a/tensorvision/analyze.py +++ b/tensorvision/analyze.py @@ -71,6 +71,7 @@ def do_analyze(logdir, base_path=None): image_pl = tf.placeholder(tf.float32) image = tf.expand_dims(image_pl, 0) + image.set_shape([1, None, None, 3]) inf_out = core.build_inference_graph(hypes, modules, image=image) diff --git a/tensorvision/core.py b/tensorvision/core.py index f906b05..22c56ee 100644 --- a/tensorvision/core.py +++ b/tensorvision/core.py @@ -14,6 +14,12 @@ import tensorvision.utils as utils +flags = tf.app.flags +FLAGS = flags.FLAGS + +tf.app.flags.DEFINE_boolean( + 'summary', True, ('Whether or not to save summaries to tensorboard.')) + def load_weights(checkpoint_dir, sess, saver): """ @@ -107,6 +113,7 @@ def build_training_graph(hypes, queue, modules): graph['train_op'] = train_op graph['global_step'] = global_step graph['learning_rate'] = learning_rate + graph['decoded_logits'] = decoded_logits return graph @@ -149,22 +156,30 @@ def start_tv_session(hypes): (sess, saver, summary_op, summary_writer, threads) """ # Build the summary operation based on the TF collection of Summaries. - summary_op = tf.summary.merge_all() + if FLAGS.summary: + tf.contrib.layers.summarize_collection(tf.GraphKeys.WEIGHTS) + tf.contrib.layers.summarize_collection(tf.GraphKeys.BIASES) + summary_op = tf.summary.merge_all() + else: + summary_op = None # Create a saver for writing training checkpoints. if 'keep_checkpoint_every_n_hours' in hypes['solver']: kc = hypes['solver']['keep_checkpoint_every_n_hours'] else: kc = 10000.0 - saver = tf.train.Saver(max_to_keep=int(utils.cfg.max_to_keep), - keep_checkpoint_every_n_hours=kc) - # Create a session for running Ops on the Graph. - sess = tf.Session() + saver = tf.train.Saver(max_to_keep=int(utils.cfg.max_to_keep)) + + sess = tf.get_default_session() # Run the Op to initialize the variables. - init = tf.global_variables_initializer() - sess.run(init) + if 'init_function' in hypes: + _initalize_variables = hypes['init_function'] + _initalize_variables(hypes) + else: + init = tf.global_variables_initializer() + sess.run(init) # Start the queue runners. coord = tf.train.Coordinator() diff --git a/tensorvision/train.py b/tensorvision/train.py index 0064c00..51c7ec7 100644 --- a/tensorvision/train.py +++ b/tensorvision/train.py @@ -221,7 +221,7 @@ def run_training(hypes, modules, tv_graph, tv_sess, start_step=0): save_iter = hypes['logging']['save_iter'] image_iter = hypes['logging'].get('image_iter', 5*save_iter) - py_smoother = MedianSmoother(50) + py_smoother = MedianSmoother(20) dict_smoother = ExpoSmoother(0.95) n = 0 @@ -255,28 +255,29 @@ def run_training(hypes, modules, tv_graph, tv_sess, start_step=0): _print_eval_dict(eval_names, smoothed_results, prefix='(smooth)') - if step % write_iter == 0: - # write values to summary + # Reset timer + start_time = time.time() + + if step % write_iter == 0: + # write values to summary + if FLAGS.summary: summary_str = sess.run(tv_sess['summary_op'], feed_dict=feed_dict) summary_writer.add_summary(summary_str, global_step=step) - summary.value.add(tag='training/total_loss', - simple_value=float(loss_value)) - summary.value.add(tag='training/learning_rate', - simple_value=lr) - summary_writer.add_summary(summary, step) - # Convert numpy types to simple types. - eval_results = np.array(eval_results) - eval_results = eval_results.tolist() - eval_dict = zip(eval_names, eval_results) - _write_eval_dict_to_summary(eval_dict, 'Eval/raw', - summary_writer, step) - eval_dict = zip(eval_names, smoothed_results) - _write_eval_dict_to_summary(eval_dict, 'Eval/smooth', - summary_writer, step) - - # Reset timer - start_time = time.time() + summary.value.add(tag='training/total_loss', + simple_value=float(loss_value)) + summary.value.add(tag='training/learning_rate', + simple_value=lr) + summary_writer.add_summary(summary, step) + # Convert numpy types to simple types. + eval_results = np.array(eval_results) + eval_results = eval_results.tolist() + eval_dict = zip(eval_names, eval_results) + _write_eval_dict_to_summary(eval_dict, 'Eval/raw', + summary_writer, step) + eval_dict = zip(eval_names, smoothed_results) + _write_eval_dict_to_summary(eval_dict, 'Eval/smooth', + summary_writer, step) # Do a evaluation and print the current state if (step) % eval_iter == 0 and step > 0 or \ @@ -367,7 +368,7 @@ def do_training(hypes): modules = utils.load_modules_from_hypes(hypes) # Tell TensorFlow that the model will be built into the default Graph. - with tf.Graph().as_default(): + with tf.Session() as sess: # build the graph based on the loaded modules with tf.name_scope("Queues"): @@ -377,12 +378,12 @@ def do_training(hypes): # prepaire the tv session tv_sess = core.start_tv_session(hypes) - sess = tv_sess['sess'] with tf.name_scope('Validation'): tf.get_variable_scope().reuse_variables() image_pl = tf.placeholder(tf.float32) image = tf.expand_dims(image_pl, 0) + image.set_shape([1, None, None, 3]) inf_out = core.build_inference_graph(hypes, modules, image=image) tv_graph['image_pl'] = image_pl @@ -415,7 +416,7 @@ def continue_training(logdir): modules = utils.load_modules_from_logdir(logdir) # Tell TensorFlow that the model will be built into the default Graph. - with tf.Graph().as_default(): + with tf.Session() as sess: # build the graph based on the loaded modules with tf.name_scope("Queues"): @@ -445,6 +446,7 @@ def continue_training(logdir): tf.get_variable_scope().reuse_variables() image_pl = tf.placeholder(tf.float32) image = tf.expand_dims(image_pl, 0) + image.set_shape([1, None, None, 3]) inf_out = core.build_inference_graph(hypes, modules, image=image) tv_graph['image_pl'] = image_pl