-
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
Created a function to_data_format to abstract the shape and data_format handling. #10781
Created a function to_data_format to abstract the shape and data_format handling. #10781
Conversation
Good idea, @gabrieldemarmiesse. However, a |
Sure thing. |
keras/utils/generic_utils.py
Outdated
@@ -532,3 +532,51 @@ def slice_arrays(arrays, start=None, stop=None): | |||
return arrays[start:stop] | |||
else: | |||
return [None] | |||
|
|||
|
|||
def to_data_format(values, data_format, skip=1): |
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.
May I suggest the following signature:
pattern = [batch_size, steps, height, width, dimensions]
transposed_shape = transpose_shape(shape, target_format=data_format, spatial_axes=(2, 3))
I think that would be more readable and explicit than "to_data_format" and "skip".
Also, it would be more readable to explicitly pass keyword arguments when calling the function, e.g.
transpose_shape(shape, target_format=data_format, spatial_axes=(2, 3))
rather than
transpose_shape(shape, data_format, (2, 3))
I changed the signature to:
I don't think If you still think that this should be called with |
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
The keras codebase has this pattern which occurs quite frequently:
I believe some refactoring could be done, and it could lead to more readable and less error-prone code.
I made a function for it, I didn't use it in all the places that I could though. I wanted to keep this PR small. I will replace more code in the future if this PR is merged.
Related Issues
PR Overview
to_data_format
.More refactoring using this function will come in future PRs.