Skip to content

Commit

Permalink
Update requirements.txt
Browse files Browse the repository at this point in the history
  • Loading branch information
cangermueller committed Feb 18, 2017
2 parents 84f6808 + bcd391e commit d008246
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 124 deletions.
118 changes: 7 additions & 111 deletions deepcpg/callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@


class PerformanceLogger(Callback):
"""Logs performance metrics during training.
Stores and prints performance metrics for each batch, epoch, and output.
"""



def __init__(self, metrics=['loss', 'acc'], log_freq=0.1,
precision=4, callbacks=[], verbose=1, logger=print):
Expand Down Expand Up @@ -250,6 +256,7 @@ def on_batch_end(self, batch, logs={}):


class TrainingStopper(Callback):
"""Stops training after certain time or when file is detected."""

def __init__(self, max_time=None, stop_file=None,
verbose=1, logger=print):
Expand Down Expand Up @@ -277,114 +284,3 @@ def on_epoch_end(self, batch, logs={}):
if os.path.isfile(self.stop_file):
self.log('Stopping training due to stop file!')
self.model.stop_training = True


class TensorBoard(Callback):
''' Tensorboard basic visualizations.
This callback writes a log for TensorBoard, which allows
you to visualize dynamic graphs of your training and test
metrics, as well as activation histograms for the different
layers in your model.
TensorBoard is a visualization tool provided with TensorFlow.
If you have installed TensorFlow with pip, you should be able
to launch TensorBoard from the command line:
```
tensorboard --logdir=/full_path_to_your_logs
```
You can find more information about TensorBoard
[here](https://www.tensorflow.org/versions/master/how_tos/summaries_and_tensorboard/index.html).
# Arguments
log_dir: the path of the directory where to save the log
files to be parsed by Tensorboard
histogram_freq: frequency (in epochs) at which to compute activation
histograms for the layers of the model. If set to 0,
histograms won't be computed.
write_graph: whether to visualize the graph in Tensorboard.
The log file can become quite large when
write_graph is set to True.
'''

def __init__(self, log_dir='./logs', histogram_freq=0, write_graph=True,
write_images=False):
super(TensorBoard, self).__init__()
if K._BACKEND != 'tensorflow':
raise Exception('TensorBoard callback only works '
'with the TensorFlow backend.')
self.log_dir = log_dir
self.histogram_freq = histogram_freq
self.merged = None
self.write_graph = write_graph
self.write_images = write_images

def _set_model(self, model):
import tensorflow as tf
import keras.backend.tensorflow_backend as KTF

self.model = model
self.sess = KTF.get_session()
if self.histogram_freq and self.merged is None:
for layer in self.model.layers:

for weight in layer.weights:
tf.histogram_summary(weight.name, weight)

if self.write_images:
w_img = tf.squeeze(weight)

shape = w_img.get_shape()
if len(shape) > 1 and shape[0] > shape[1]:
w_img = tf.transpose(w_img)

if len(shape) == 1:
w_img = tf.expand_dims(w_img, 0)

w_img = tf.expand_dims(tf.expand_dims(w_img, 0), -1)

tf.image_summary(weight.name, w_img)

if hasattr(layer, 'output'):
tf.histogram_summary('{}_out'.format(layer.name),
layer.output)
self.merged = tf.merge_all_summaries()
if self.write_graph:
if parse_version(tf.__version__) >= parse_version('0.8.0'):
self.writer = tf.train.SummaryWriter(self.log_dir,
self.sess.graph)
else:
self.writer = tf.train.SummaryWriter(self.log_dir,
self.sess.graph_def)
else:
self.writer = tf.train.SummaryWriter(self.log_dir)

def on_epoch_end(self, epoch, logs={}):
import tensorflow as tf

if self.model.validation_data and self.histogram_freq:
if epoch % self.histogram_freq == 0:
# TODO: implement batched calls to sess.run
# (current call will likely go OOM on GPU)
if self.model.uses_learning_phase:
cut_v_data = len(self.model.inputs)
val_data = self.model.validation_data[:cut_v_data] + [0]
tensors = self.model.inputs + [K.learning_phase()]
else:
val_data = self.model.validation_data
tensors = self.model.inputs
feed_dict = dict(zip(tensors, val_data))
result = self.sess.run([self.merged], feed_dict=feed_dict)
summary_str = result[0]
self.writer.add_summary(summary_str, epoch)

for name, value in logs.items():
if name in ['batch', 'size']:
continue
summary = tf.Summary()
summary_value = summary.value.add()
summary_value.simple_value = value
summary_value.tag = name
self.writer.add_summary(summary, epoch)
self.writer.flush()
1 change: 1 addition & 0 deletions deepcpg/evaluation.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@


def cor(y, z):
"""Computes Pearon's correlation."""
return np.corrcoef(y, z)[0, 1]


Expand Down
7 changes: 4 additions & 3 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@
# built documents.
#
# The short X.Y version.
version = '1.0.0'
version = '1.0.1'
# The full version, including alpha/beta/rc tags.
release = '1.0.0'
release = '1.0.1'

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand Down Expand Up @@ -130,7 +130,8 @@
# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
#
html_theme = 'alabaster'
html_theme = 'nature'
# nature, haiku

# Theme options are theme-specific and customize the look and feel of a theme
# further. For a list of options available for each theme, see the
Expand Down
5 changes: 4 additions & 1 deletion docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,13 @@ Interactive examples on how to use DeepCpG can be found `here <https://github.co

API documentation
-----------------
DeepCpG modules:

.. toctree::
:maxdepth: 2

models/index
lib/index
lib/models/index


Indices and tables
Expand Down
29 changes: 29 additions & 0 deletions docs/source/lib/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
.. _libdoc_deepcpg:

======================================
:mod:`callbacks` -- Training callbacks
======================================

.. automodule:: deepcpg.callbacks
:members:

===========================================
:mod:`evaluation` -- Performance evaluation
===========================================

.. automodule:: deepcpg.evaluation
:members:

==============================
:mod:`motifs` -- Motif related
==============================

.. automodule:: deepcpg.motifs
:members:

=========================
:mod:`utils` -- Utilities
=========================

.. automodule:: deepcpg.utils
:members:
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
.. _libdoc_model:

=====================================
:mod:`model` -- model: DeepCpG models
=====================================
==============================
:mod:`model` -- DeepCpG models
==============================

The models package provides functionalities for building and training models.

Model utils
===========
:mod:`model.utils` -- Model utilities
=====================================

.. automodule:: deepcpg.models.utils
:members:

CpG models
==========
:mod:`model.cpg` -- CpG models
==============================

.. automodule:: deepcpg.models.cpg
:members:

DNA models
==========
:mod:`model.dna` -- DNA models
==============================

.. automodule:: deepcpg.models.dna
:members:
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ numpy
pandas
pytest
keras
tensorflow
matplotlib
seaborn
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ def read(fname):
'pandas',
'pytest',
'keras',
'tensorflow',
'matplotlib',
'seaborn'],
keywords=['Deep learning',
Expand Down

0 comments on commit d008246

Please sign in to comment.