Skip to content

Commit 8490679

Browse files
committed
Add support for Keras >=2.2.0
1 parent b50cc27 commit 8490679

File tree

8 files changed

+42
-25
lines changed

8 files changed

+42
-25
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
__pycache__/*
99
.cache/*
1010
.ipynb_checkpoints
11+
.pytest_cache
1112

1213
# Project files
1314
.ropeproject

README.rst

+5
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ Table of contents
5555
News
5656
====
5757

58+
* **181201**: DeepCpG 1.0.7 released!
5859
* **180224**: DeepCpG 1.0.6 released!
5960
* **171112**: Keras 2 is now the main Keras version (release 1.0.5).
6061
* **170412**: New `notebook <./examples/notebooks/stats/index.ipynb>`_ on predicting inter-cell statistics!
@@ -213,6 +214,10 @@ Content
213214
Changelog
214215
=========
215216

217+
1.0.7
218+
-----
219+
* Add support for Keras >=2.2.0.
220+
216221
1.0.6
217222
-----
218223
* Add support for Keras 2.1.4 and Tensorflow 1.5.0

deepcpg/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = '1.0.6'
1+
__version__ = '1.0.7'

deepcpg/models/utils.py

+12-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
from os import path as pt
88

9+
import keras
910
from keras import backend as K
1011
from keras import models as km
1112
from keras import layers as kl
@@ -410,6 +411,16 @@ def copy_weights(src_model, dst_model, must_exist=True):
410411
return copied
411412

412413

414+
def is_input_layer(layer):
415+
"""Test if `layer` is an input layer."""
416+
return isinstance(layer, keras.engine.input_layer.InputLayer)
417+
418+
419+
def is_output_layer(layer, model):
420+
"""Test if `layer` is an output layer."""
421+
return layer.name in model.output_names
422+
423+
413424
class Model(object):
414425
"""Abstract model call.
415426
@@ -445,7 +456,7 @@ def _build(self, input, output):
445456
model = km.Model(input, output, name=self.name)
446457
if self.scope:
447458
for layer in model.layers:
448-
if layer not in model.input_layers:
459+
if not is_input_layer(layer):
449460
layer.name = '%s/%s' % (self.scope, layer.name)
450461
return model
451462

docs/source/conf.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,9 @@
7272
# built documents.
7373
#
7474
# The short X.Y version.
75-
version = '1.0.6'
75+
version = '1.0.7'
7676
# The full version, including alpha/beta/rc tags.
77-
release = '1.0.6'
77+
release = '1.0.7'
7878

7979
# The language for content autogenerated by Sphinx. Refer to documentation
8080
# for a list of supported languages.

scripts/dcpg_snp.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,9 @@ def main(self, name, opts):
144144

145145
# Get DNA layer.
146146
dna_layer = None
147-
for i, name in enumerate(model.input_names):
148-
if name == 'dna':
149-
dna_layer = model.input_layers[i]
147+
for layer in model.layers:
148+
if layer.name == 'dna':
149+
dna_layer = layer
150150
break
151151
if not dna_layer:
152152
raise ValueError('The provided model is not a DNA model!')

scripts/dcpg_train.py

+17-17
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474
from deepcpg import data as dat
7575
from deepcpg import metrics as met
7676
from deepcpg import models as mod
77+
from deepcpg.models.utils import is_input_layer, is_output_layer
7778
from deepcpg.data import hdf, OUTPUT_SEP
7879
from deepcpg.utils import format_table, make_dir, EPS
7980

@@ -86,7 +87,7 @@
8687

8788

8889
def remove_outputs(model):
89-
while model.layers[-1] in model.output_layers:
90+
while is_output_layer(model.layers[-1], model):
9091
model.layers.pop()
9192
model.outputs = [model.layers[-1].output]
9293
model.layers[-1].outbound_nodes = []
@@ -97,7 +98,7 @@ def rename_layers(model, scope=None):
9798
if not scope:
9899
scope = model.scope
99100
for layer in model.layers:
100-
if layer in model.input_layers or layer.name.startswith(scope):
101+
if is_input_layer(layer) or layer.name.startswith(scope):
101102
continue
102103
layer.name = '%s/%s' % (scope, layer.name)
103104

@@ -595,7 +596,7 @@ def build_model(self):
595596
remove_outputs(stem)
596597

597598
outputs = mod.add_output_layers(stem.outputs[0], output_names)
598-
model = Model(stem.inputs, outputs, stem.name)
599+
model = Model(inputs=stem.inputs, outputs=outputs, name=stem.name)
599600
return model
600601

601602
def set_trainability(self, model):
@@ -622,17 +623,18 @@ def set_trainability(self, model):
622623
table['layer'] = []
623624
table['trainable'] = []
624625
for layer in model.layers:
625-
if layer not in model.input_layers + model.output_layers:
626-
if not hasattr(layer, 'trainable'):
627-
continue
628-
for regex in not_trainable:
629-
if re.match(regex, layer.name):
630-
layer.trainable = False
631-
for regex in trainable:
632-
if re.match(regex, layer.name):
633-
layer.trainable = True
634-
table['layer'].append(layer.name)
635-
table['trainable'].append(layer.trainable)
626+
if is_input_layer(layer) or is_output_layer(layer, model):
627+
continue
628+
if not hasattr(layer, 'trainable'):
629+
continue
630+
for regex in not_trainable:
631+
if re.match(regex, layer.name):
632+
layer.trainable = False
633+
for regex in trainable:
634+
if re.match(regex, layer.name):
635+
layer.trainable = True
636+
table['layer'].append(layer.name)
637+
table['trainable'].append(layer.trainable)
636638
print('Layer trainability:')
637639
print(format_table(table))
638640
print()
@@ -713,9 +715,7 @@ def main(self, name, opts):
713715
mod.save_model(model, os.path.join(opts.out_dir, 'model.json'))
714716

715717
log.info('Computing output statistics ...')
716-
output_names = []
717-
for output_layer in model.output_layers:
718-
output_names.append(output_layer.name)
718+
output_names = model.output_names
719719

720720
output_stats = OrderedDict()
721721

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ def read(fname):
99

1010

1111
setup(name='deepcpg',
12-
version='1.0.6',
12+
version='1.0.7',
1313
description='Deep learning for predicting CpG methylation',
1414
long_description=read('README.rst'),
1515
author='Christof Angermueller',

0 commit comments

Comments
 (0)