-
Notifications
You must be signed in to change notification settings - Fork 19.6k
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
Refactoring: Used the function normalize_data_format
to remove some code.
#10690
Refactoring: Used the function normalize_data_format
to remove some code.
#10690
Conversation
normalize_data_format
to remove some code.normalize_data_format
to remove some code.
…the implementation to keras/backend/common.py.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR.
keras/utils/conv_utils.py
Outdated
@@ -8,6 +8,9 @@ | |||
import numpy as np | |||
from .. import backend as K | |||
|
|||
# Legacy import | |||
from ..backend import normalize_data_format |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not part of the public API, you don't need to import it here.
@@ -99,6 +99,7 @@ | |||
'deserialize', | |||
'get', | |||
'set_image_dim_ordering', | |||
'normalize_data_format', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not part of the public API, it shouldn't be documented.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed. This is why it's in the EXCLUDE
set here.
keras/backend/cntk_backend.py
Outdated
@@ -4,7 +4,8 @@ | |||
|
|||
import cntk as C | |||
import numpy as np | |||
from .common import floatx, epsilon, image_dim_ordering, image_data_format | |||
from .common import floatx, epsilon | |||
from .common import image_data_format, normalize_data_format |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use one import per line from now on.
keras/backend/common.py
Outdated
@@ -147,6 +147,37 @@ def set_image_data_format(data_format): | |||
_IMAGE_DATA_FORMAT = str(data_format) | |||
|
|||
|
|||
def normalize_data_format(value): | |||
"""Check that the value correspond to a valid data format. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Checks
keras/backend/common.py
Outdated
"""Check that the value correspond to a valid data format. | ||
|
||
# Arguments | ||
value: string or None. `'channels_first'` or `'channels_last'`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Capitalize start of argument descriptions ("String or...")
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks
Summary
Quite a lot of code can be removed by doing this. Would you want me to split it into multiple smaller PRs?
Related Issues
PR Overview
To solve the issue of cyclical imports, I moved the
normalized_data_format
inbackend/common.py
. I think it makes sense for the implementation to be there overall since it's tightly connected to the data_format given by the backend. I left the other implementation to avoid breaking anything.