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

Refactor tensorflow import backend #499

Merged
merged 8 commits into from
Dec 12, 2018

Conversation

abhigyan7
Copy link
Contributor

This PR includes a clean, modular code base for tensorflow import. I have split the import logic into two files, much like with the keras and caffe import ones.
All the examples inside example/tensorflow work exactly like they used to.

Copy link
Member

@Ram81 Ram81 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@haabhi Nice effort, can you address the comments

if activation_op.type == 'Relu':
layer_type = 'ReLU'

if activation_op.type == 'LeakyRelu':
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this not in elif ?

layer_params['alpha'] = 1
layer_type = 'ELU'

elif activation_op.type == 'Softplus':
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For all layers below this can't we directly assign activation_op.type?

conv2d_op = next((x for x in layer_ops if x.type == 'Conv2D'), None)

layer_params = {}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove newline

def import_conv2d(layer_ops):

conv2d_op = next((x for x in layer_ops if x.type == 'Conv2D'), None)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove newline



def import_conv3d(layer_ops):

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be good to have comments in every method


def import_deconvolution(layer_ops):
deconv_op = next((x for x in layer_ops if x.type == 'Conv2DBackpropInput'), None)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove unnecessary newlines

layer_params = {}

if '3D' in depthwise_conv_op.type:
return
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should throw some sort of error in such case so that user knows what was the issue


def import_batchnorm(layer_ops):
layer_params = {}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please follow same styles for newlines, I mean add newlines by following some style guidelines

@abhigyan7
Copy link
Contributor Author

@Ram81
I did a rebase to combine two of my commits into one, and it looks like I combined the previous commit with a5fa3f0 . Should I open a new PR fixing this and then close this one? Will this be an issue when merging?

@Ram81
Copy link
Member

Ram81 commented Dec 11, 2018

@haabhi while merging we will squash the commits anyway so if all your changes are present in the PR then it shouldn't be an issue.

@abhigyan7
Copy link
Contributor Author

@Ram81 Made the changes. I have added docstrings and normal comments where things were not very clear. As for new lines, I have deleted a lot of them and grouped related lines tightly and separated them with single blank lines.

@abhigyan7
Copy link
Contributor Author

@Ram81 updated the layer addition tutorial to match these changes.

Copy link
Member

@Ram81 Ram81 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@haabhi nice work, can you please make the requested changes



def get_input_layers(layer_ops):
''' return the name of the layers directly preceeding the layer of layer_ops.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you move the comment to new line

''' return the name of the layers directly preceeding the layer of layer_ops.
layer_ops is a list of all ops of the layer we want the inputs of.
'''
ret = []
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please rename the variable

placeholder_op = layer_ops[0]
layer_params = {}
layer_dim = [int(dim.size) for dim in placeholder_op.get_attr('shape').dim]
# make batch size 1 if it is -1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add newlines where necessary

- Create a function name import_<layer_name> that takes one parameter, layer_ops, that is a list of all ops in the layer being imported.
- Get layer parameters from the operations in layer_ops and build a dictionary mapping parameter names to values.
- Get a list of input layers to the layer being processed using `get_input_layers(layer_ops)`.
- Create and return a json layer for your layer, calling `jsonLayer` with your layer_type, parameters, input layers and output_layers(optional).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change this to Create and return a json layer for new layer replace your with new in the statement

Copy link
Member

@Ram81 Ram81 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@Ram81 Ram81 merged commit 0bb88a5 into Cloud-CV:master Dec 12, 2018
rahulsnkr pushed a commit to rahulsnkr/Fabrik that referenced this pull request Dec 19, 2018
* Refactor tensorflow import code

* Remove unnecessary newlines and make code concise

* Update documentation for adding new layers to tensorflow import

* Minor changes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants