This repository was archived by the owner on Jun 23, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 650
Making keras-contrib compatible with tf.keras #387
Merged
gabrieldemarmiesse
merged 80 commits into
keras-team:master
from
gabrieldemarmiesse:tf_keras_again
Feb 15, 2019
Merged
Changes from all commits
Commits
Show all changes
80 commits
Select commit
Hold shift + click to select a range
07c17fe
Changed travis
gabrieldemarmiesse f80d8e0
Added the script to convert
gabrieldemarmiesse a70847d
fix indentation.
gabrieldemarmiesse 97219b5
Trying fewer changes.
gabrieldemarmiesse 746f9a2
Added the ignore in pytest.
gabrieldemarmiesse 19b0734
fix order of replacement.
gabrieldemarmiesse a09fabc
Merge branch 'master' into tf_keras_again
gabrieldemarmiesse 67924a3
Removed the hacky replace.
gabrieldemarmiesse 49619b0
Used the normal backend for normalize data format.
gabrieldemarmiesse c251865
Merge branch 'master' into tf_keras_again
gabrieldemarmiesse 9724487
Merge branch 'master' into tf_keras_again
gabrieldemarmiesse 752f1ef
Making really sure we don't get keras_contrib.
gabrieldemarmiesse 7025a6d
Ignore backend tests for tf.keras.
gabrieldemarmiesse cc68fa6
Merge branch 'master' into tf_keras_again
gabrieldemarmiesse 564af63
Merge branch 'master' into tf_keras_again
gabrieldemarmiesse 33058bb
fixed some imports and ignored test for tf_keras.
gabrieldemarmiesse ee99fa9
used pip install to install tf-keras.
gabrieldemarmiesse 3d167a3
Maybe the option is not at the right place.
gabrieldemarmiesse dbe92e7
Trying a separate file.
gabrieldemarmiesse ae27d1b
import the contrib backend.
gabrieldemarmiesse 79bb6d8
Moved to the setup.py
gabrieldemarmiesse 98b507d
Merge branch 'master' into tf_keras_again
gabrieldemarmiesse 4ca208a
Let's not use import *
gabrieldemarmiesse 9b6b0dd
Added compute_output_shape.
gabrieldemarmiesse 82aa1dc
Merge branch 'master' into tf_keras_again
gabrieldemarmiesse cbbf06d
Used a more recent version of tf.
gabrieldemarmiesse 9e380e8
Used custom layer to ensure it works with tf.keras.
gabrieldemarmiesse a0f86a5
Fixing return forgotten.
gabrieldemarmiesse 8a6b5cf
Changed line endings to unix.
gabrieldemarmiesse 543a744
moving to a separate file.
gabrieldemarmiesse a10f4f0
Added verbose option.
gabrieldemarmiesse 7f28ce0
Made a more robust check.
gabrieldemarmiesse 612c2a3
hopefully all bug fixed.
gabrieldemarmiesse 8a3ffe3
Let's not use the setup.py to convert to tf.keras.
gabrieldemarmiesse 33b8150
Hacked my way through
gabrieldemarmiesse abafa3a
fixed stupid mistake.
gabrieldemarmiesse 9dbe097
Merge branch 'master' into tf_keras_again
gabrieldemarmiesse 9c623f3
Merge branch 'master' into tf_keras_again
gabrieldemarmiesse cb6131f
Some pep8 fixes.
gabrieldemarmiesse 516cc14
Fixed imports in tensorboard.
gabrieldemarmiesse 7427849
Fixed import again.
gabrieldemarmiesse 114be91
Added some xfails.
gabrieldemarmiesse ac931af
Merge branch 'master' into tf_keras_again
gabrieldemarmiesse fc2dd4d
Fixed the padam error.
gabrieldemarmiesse 4ec19d3
Hopefully fixed tensorboard
gabrieldemarmiesse edcc433
Adding an xfail.
gabrieldemarmiesse 0cf37de
Added some xfail.
gabrieldemarmiesse 79a3490
Fixed pep8 and removed xfail.
75db9e9
Merge branch 'master' into tf_keras_again
f4203ae
Used skipif.
e04ab3f
Removed useless diff.
99fb7ba
Merge branch 'master' into tf_keras_again
a2152c5
Merge branch 'master' into tf_keras_again
f8058c1
Simplified the base layer.
bbe1641
Added the back and forth conversion for tf.keras.
d1a9aaf
Removed Useless function in base_layer.
2fa39d3
Simplified the hack to work with tensorshapes.
4e33f67
Fix pep8
4064e11
Removed small diff.
0e598b0
Put the script in the setup.py.
8eec1f8
Removed the import changes from the setup.py.
b262f9f
Clarified the docstring of `to_tuple`.
9d02f74
Added install details.
a15a01b
/bin/bash: q: command not found
gabrieldemarmiesse 95310a2
Typos.
dd1e3c6
Merge branch 'master' into tf_keras_again
8757f67
Changed the hard reset to a git stash.
701f5eb
Adding to_tuple to capsule.py.
c7505ad
skipping when tf.keras.
b7c9769
Removing unused imports.
9fdc858
Merge branch 'master' into tf_keras_again
gabrieldemarmiesse 5e37a62
Merge branch 'tf_keras_again' of github.com:gabrieldemarmiesse/keras-…
gabrieldemarmiesse 7d662fa
Revert some changes.
gabrieldemarmiesse 45318fa
Forgot the to_tuple.
gabrieldemarmiesse b3366c7
Removed custom objects.
gabrieldemarmiesse 3d7fb42
Removed git reset.
gabrieldemarmiesse 775020c
Added a test.
gabrieldemarmiesse e637aab
Fixed typo.
gabrieldemarmiesse b959b8c
Some fixes here and there.
gabrieldemarmiesse 4472d24
Pep8
gabrieldemarmiesse File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
import os | ||
import sys | ||
|
||
list_conversions = [('import keras.', 'import tensorflow.keras.'), | ||
('import keras ', 'from tensorflow import keras '), | ||
('import keras\n', 'from tensorflow import keras\n'), | ||
('from keras.', 'from tensorflow.keras.'), | ||
('from keras ', 'from tensorflow.keras ')] | ||
|
||
|
||
def replace_imports_in_text(string, revert): | ||
if revert: | ||
list_imports_to_change = [x[::-1] for x in list_conversions] | ||
else: | ||
list_imports_to_change = list_conversions | ||
|
||
text_updated = string | ||
for old_str, new_str in list_imports_to_change: | ||
text_updated = text_updated.replace(old_str, new_str) | ||
return text_updated | ||
|
||
|
||
def replace_imports_in_file(file_path, revert): | ||
if not file_path.endswith('.py'): | ||
return False | ||
if os.path.abspath(file_path) == os.path.abspath(__file__): | ||
return False | ||
with open(file_path, 'r') as f: | ||
text = f.read() | ||
|
||
text_updated = replace_imports_in_text(text, revert) | ||
|
||
with open(file_path, 'w+') as f: | ||
f.write(text_updated) | ||
|
||
return text_updated != text | ||
|
||
|
||
def convert_codebase(revert): | ||
nb_of_files_changed = 0 | ||
keras_dir = os.path.dirname(os.path.abspath(__file__)) | ||
for root, dirs, files in os.walk(keras_dir): | ||
for name in files: | ||
if replace_imports_in_file(os.path.join(root, name), revert): | ||
nb_of_files_changed += 1 | ||
print('Changed imports in ' + str(nb_of_files_changed) + ' files.') | ||
print('Those files were found in the directory ' + keras_dir) | ||
|
||
|
||
def convert_to_tf_keras(): | ||
"""Convert the codebase to tf.keras""" | ||
convert_codebase(False) | ||
|
||
|
||
def convert_to_keras_team_keras(): | ||
"""Convert the codebase from tf.keras to keras-team/keras""" | ||
convert_codebase(True) | ||
|
||
|
||
def test_replace_imports(): | ||
python_code = """ | ||
import keras | ||
from keras import backend as K | ||
import os | ||
import keras_contrib | ||
import keras_contrib.layers as lay | ||
import keras.layers | ||
from keras.layers import Dense | ||
|
||
if K.backend() == 'tensorflow': | ||
import tensorflow as tf | ||
function = tf.max | ||
""" | ||
|
||
expected_code = """ | ||
from tensorflow import keras | ||
from tensorflow.keras import backend as K | ||
import os | ||
import keras_contrib | ||
import keras_contrib.layers as lay | ||
import tensorflow.keras.layers | ||
from tensorflow.keras.layers import Dense | ||
|
||
if K.backend() == 'tensorflow': | ||
import tensorflow as tf | ||
function = tf.max | ||
""" | ||
|
||
code_with_replacement = replace_imports_in_text(python_code, False) | ||
assert expected_code == code_with_replacement | ||
assert python_code == replace_imports_in_text(code_with_replacement, True) | ||
|
||
|
||
if __name__ == '__main__': | ||
if '--revert' in sys.argv: | ||
convert_to_keras_team_keras() | ||
else: | ||
convert_to_tf_keras() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,23 @@ | ||
from setuptools import setup | ||
from setuptools import find_packages | ||
import os | ||
|
||
|
||
setup(name='keras_contrib', | ||
if os.environ.get('USE_TF_KERAS', None) == '1': | ||
name = 'tf_keras_contrib' | ||
install_requires = [] | ||
else: | ||
name = 'keras_contrib' | ||
install_requires = ['keras'] | ||
|
||
setup(name=name, | ||
version='2.0.8', | ||
description='Keras Deep Learning for Python, Community Contributions', | ||
author='Fariz Rahman', | ||
author_email='[email protected]', | ||
url='https://github.com/farizrahman4u/keras-contrib', | ||
license='MIT', | ||
install_requires=['keras'], | ||
install_requires=install_requires, | ||
extras_require={ | ||
'h5py': ['h5py'], | ||
'visualize': ['pydot>=1.2.0'], | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.