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

Fix: Extended Support for Layer Import for TF and keras (#293) #296

Merged
merged 6 commits into from Feb 4, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 12 additions & 1 deletion caffe_app/views/import_prototxt.py
Expand Up @@ -469,6 +469,16 @@ def ContrastiveLoss(layer):
return params


def Concat(layer):
params = {}
if (layer.concat_param.axis is not None):
params['axis'] = layer.concat_param.axis
else:
# default value for axis of concat in caffe
params['axis'] = 1
return params


# ********** Python Layer **********
def Python(layer):
params = {}
Expand Down Expand Up @@ -541,7 +551,8 @@ def Python(layer):
'Python': Python,
'LRN': LRN,
'LSTM': Recurrent,
'RNN': Recurrent
'RNN': Recurrent,
'Concat': Concat
}


Expand Down
24 changes: 24 additions & 0 deletions ide/static/js/data.js
Expand Up @@ -1935,6 +1935,24 @@ export default {
value: true,
type: 'checkbox',
required: false
},
rate: {
name: 'Dropout Ratio',
value: 0.5,
type: 'float',
required: false
},
seed: {
name: 'Seed',
value: 42,
type: 'number',
required: false
},
trainable: {
name: 'Trainable',
value: false,
type: 'checkbox',
required: false
}
},
props: {
Expand Down Expand Up @@ -3146,6 +3164,12 @@ export default {
value: true,
type: 'checkbox',
required: false
},
axis: {
name: 'Axis',
value: -1,
type: 'number',
required: false
}
},
props: {
Expand Down
13 changes: 11 additions & 2 deletions keras_app/views/layers_import.py
Expand Up @@ -53,7 +53,14 @@ def Activation(layer):


def Dropout(layer):
return jsonLayer('Dropout', {}, layer)
params = {}
if (layer.rate is not None):
params['rate'] = layer.rate
if (layer.seed is not None):
params['seed'] = layer.seed
if (layer.trainable is not None):
params['trainable'] = layer.trainable
return jsonLayer('Dropout', params, layer)


def Flatten(layer):
Expand Down Expand Up @@ -370,7 +377,9 @@ def Embed(layer):

# ********** Merge Layers **********
def Concat(layer):
return jsonLayer('Concat', {}, layer)
params = {}
params['axis'] = layer.axis
return jsonLayer('Concat', params, layer)


def Eltwise(layer):
Expand Down
16 changes: 16 additions & 0 deletions tensorflow_app/views/import_graphdef.py
Expand Up @@ -245,9 +245,19 @@ def import_graph_def(request):
pass

elif layer['type'][0] == 'Concat':
if 'axis' in node.node_def.attr:
layer['params']['axis'] = node.get_attr('axis')
pass

elif layer['type'][0] == 'LRN':
if ('alpha' in node.node_def.attr):
layer['params']['alpha'] = node.get_attr('alpha')
if ('beta' in node.node_def.attr):
layer['params']['beta'] = node.get_attr('beta')
if ('local_size' in node.node_def.attr):
layer['params']['local_size'] = node.get_attr('depth_radius')
if ('bias' in node.node_def.attr):
layer['params']['k'] = node.get_attr('bias')
pass

elif layer['type'][0] == 'Softmax':
Expand All @@ -257,6 +267,12 @@ def import_graph_def(request):
pass

elif layer['type'][0] == 'Dropout':
if ('rate' in node.node_def.attr):
layer['params']['rate'] = node.get_attr('rate')
if ('seed' in node.node_def.attr):
layer['params']['seed'] = node.get_attr('seed')
if ('training' in node.node_def.attr):
layer['params']['trainable'] = node.get_attr('training')
pass
net = {}
batch_norms = []
Expand Down