Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG: allow to import keras from tensorflow #532

Merged
merged 7 commits into from
Jun 12, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
BUG: allow to import keras from tensorflow
glemaitre committed Jan 19, 2019
commit 7ce170ffbdc8b643eebf6bc843c326534f512270
8 changes: 8 additions & 0 deletions doc/whats_new/v0.5.rst
Original file line number Diff line number Diff line change
@@ -22,3 +22,11 @@ Maintenance

- Make it possible to ``import imblearn`` and access submodule.
:issue:`500` by :user:`Guillaume Lemaitre <glemaitre>`.


Bug
...

- Allow to import ``keras`` directly from ``tensorflow`` in the
:mod:`imblearn.keras`.
:issue:`352` by :user:`Guillaume Lemaitre <glemaitre>`.
13 changes: 10 additions & 3 deletions imblearn/keras/_generator.py
Original file line number Diff line number Diff line change
@@ -5,12 +5,19 @@
# avoid the error when importing the package raise the error at the moment of
# creating the instance.
try:
import keras
# try to import keras from tensorflow
from tensorflow import keras
ParentClass = keras.utils.Sequence
HAS_KERAS = True
except ImportError:
ParentClass = object
HAS_KERAS = False
try:
# if no present in tensorflow, try to import keras directly
import keras
ParentClass = keras.utils.Sequence
HAS_KERAS = True
except ImportError:
ParentClass = object
HAS_KERAS = False

from scipy.sparse import issparse