Skip to content

Commit

Permalink
Updated GenArch for custom layers. Fixes #157
Browse files Browse the repository at this point in the history
WIP #157 Updated 'standalone' default to true

WIP #157 Fixed code-climate issues

WIP #157 Fixed bad default
  • Loading branch information
brollb committed Jun 17, 2016
1 parent fb22c50 commit a9eac24
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 49 deletions.
41 changes: 36 additions & 5 deletions src/plugins/GenerateArchitecture/GenerateArchitecture.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,33 +43,47 @@ define([
GenerateArchitecture.prototype.constructor = GenerateArchitecture;

GenerateArchitecture.prototype.main = function () {
this.addCustomLayersToMeta();
this.LayerDict = createLayerDict(this.core, this.META);
this.uniqueId = 2;
this._oldTemplateSettings = _.templateSettings;
return PluginBase.prototype.main.apply(this, arguments);
};

GenerateArchitecture.prototype.addCustomLayersToMeta = function () {
var metaDict = this.core.getAllMetaNodes(this.rootNode);

Object.keys(metaDict).map(id => metaDict[id])
// Get all custom layers
.filter(node => this.core.isTypeOf(node, this.META.Layer))
// Add them to the meta
.forEach(node => this.META[this.core.getAttribute(node, 'name')] = node);
};

GenerateArchitecture.prototype.createOutputFiles = function (tree) {
var layers = tree[Constants.CHILDREN],
//initialLayers,
result = {},
code;
code = 'require \'nn\'\n\n';

//initialLayers = layers.filter(layer => layer[Constants.PREV].length === 0);
// Add an index to each layer
layers.forEach((l, index) => l[INDEX] = index);
code = this.genArchCode(layers);

// Define custom layers
if (this.getCurrentConfig().standalone) {
code += this.genLayerDefinitions(layers);
}

code += this.genArchCode(layers);

result[tree.name + '.lua'] = code;
_.templateSettings = this._oldTemplateSettings; // FIXME: Fix this in SimpleNodes
return result;
};

GenerateArchitecture.prototype.genArchCode = function (layers) {
// Create a 'null' start layer

return [
'require \'nn\'',
this.createSequential(layers[0], 'net').code,
'\nreturn net'
].join('\n');
Expand Down Expand Up @@ -174,5 +188,22 @@ define([
return !(value === undefined || value === null || value === '');
};

GenerateArchitecture.prototype.genLayerDefinitions = function(layers) {
var code = '',
customLayerId = this.core.getPath(this.META.CustomLayer);

code += '-------------- Custom Layer Definitions --------------\n\n';
code += layers
.filter(layer => { // Get the custom layers
var node = this.META[layer.name];
return this.core.getMixinPaths(node).indexOf(customLayerId) !== -1;
})
.map(layer => layer.code) // add their 'code' attributes
.join('\n');

code += '\n\n-------------- Network --------------\n';

return code;
};
return GenerateArchitecture;
});
11 changes: 10 additions & 1 deletion src/plugins/GenerateArchitecture/metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,14 @@
},
"disableServerSideExecution": false,
"disableBrowserSideExecution": false,
"configStructure": []
"configStructure": [
{
"name": "standalone",
"displayName": "Standalone",
"description": "Prepend custom layer definitions",
"value": false,
"valueType": "boolean",
"readOnly": false
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,6 @@ define([

// Set the color
desc.color = '#9e9e9e';
// TODO
return desc;
};

Expand Down
9 changes: 2 additions & 7 deletions src/visualizers/panels/LayerEditor/LayerEditorPanel.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,15 @@
/*globals define, _, WebGMEGlobal*/
/*jshint browser: true*/
/**
* Generated by VisualizerGenerator 1.7.0 from webgme on Thu Jun 16 2016 08:47:07 GMT-0500 (CDT).
*/

define([
'js/PanelBase/PanelBaseWithHeader',
'js/PanelManager/IActivePanel',
'widgets/TextEditor/TextEditorWidget',
//'panels/TextEditor/TextEditorControl'
'./LayerEditorControl'
], function (
PanelBaseWithHeader,
IActivePanel,
LayerEditorWidget,
//TextEditorControl
TextEditorWidget,
LayerEditorControl
) {
'use strict';
Expand Down Expand Up @@ -49,7 +44,7 @@ define([
//set Widget title
this.setTitle('');

this.widget = new LayerEditorWidget(this.logger, this.$el);
this.widget = new TextEditorWidget(this.logger, this.$el);

this.widget.setTitle = function (title) {
self.setTitle(title);
Expand Down
18 changes: 0 additions & 18 deletions src/visualizers/widgets/LayerEditor/LayerEditorWidget.js

This file was deleted.

10 changes: 0 additions & 10 deletions src/visualizers/widgets/LayerEditor/styles/LayerEditorWidget.css

This file was deleted.

This file was deleted.

0 comments on commit a9eac24

Please sign in to comment.