Comparar commits

...

15 Commits

Autor SHA1 Mensagem Data
Brian Broll 708ef3f48a WIP Minor changes for GenArch 2016-11-26 14:26:07 -06:00
Brian Broll 4b14c74733 WIP Changed code content to use python 2016-11-26 12:11:14 -06:00
Brian Broll cf6e6dd4e5 WIP Updated code editors to use python for comments and content 2016-11-26 12:10:22 -06:00
Brian Broll 88a57a5af9 WIP Fixed the boolean values to use True/False 2016-11-26 11:42:30 -06:00
Brian Broll d30d990330 WIP Updated nn-parser and nn for pytorch layers 2016-11-26 11:12:02 -06:00
Brian Broll 96720c3140 WIP Added some basic layer parsing support
name, baseType, defaults, and types (for the defaults). Still need
to verify named args work though (and more of the types work)...
2016-11-25 16:22:53 -06:00
Brian Broll 211623ea88 Added expand all nodes option when right clicking the background. Fixes #892 (#897)
* WIP #892 Added basic support for expanding all nodes

* WIP #892 Added the WIDGET_CLASS for use w/ $.contextMenu

* WIP 892 Updated the menu item node names
2016-11-20 08:48:23 -06:00
Brian Broll fac7964c9d Added height rule to op int editor. Fixes #895 (#896) 2016-11-16 19:44:05 -06:00
Brian Broll 63e6ddd82b Updated library version check. Fixes #893 (#894) 2016-11-16 18:09:08 -06:00
Brian Broll 964ebc9714 Added generic container support. Fixes #476 (#891)
* WIP #476 Update 'Container' category and added 'addLayers' set

* WIP #476 Added ContainerLayerDecorator

* WIP #476 Embedded arch editor in decorator

* WIP #476 Shrink the nested layers. Hide on condense

* WIP #476 Fixed positioning of nested layers

* WIP #476 Added background click handling

* WIP #476 alternate colors w/ nested containers

* WIP #476 Fixed nesting viz and layer prompt

* WIP #476 Refactored nested layers

* WIP #476 Added box on hover for nested layers

* WIP #476 Fixed the nested layer hover box position/size

* WIP #476 added button event handling

* WIP #476 Some nested layer creation support

* WIP #476 Fixed nested layer deletion

* WIP #476 prompt layer on first creation

* WIP #476 Fixed horizontal positioning of nested layers

* WIP #476 Fixed nested layer removal

* WIP #476 Fixed reordering nested layers

* WIP #476 Added basic button styling

* WIP #476 Added hint text

* WIP #476 nested layer delete icon

* WIP #476 Fixed hover and added first button

* WIP #476 Fixed the position of the nested layers (w/ attrs)

* WIP #476 more position adjustments

* WIP #476 Fixed add nested layer not updating

* WIP #476 Load nested children eagerly

* WIP #476 Minor aesthetic tweaks

* WIP #476 Fixed attribute field editing (width messing up)

* WIP #476 Added support for container code generation

* WIP #476 Added generic container support to importer

* WIP #476 Moved Concat to 'Simple'

Concat is only implicitly a container in deepforge (the contained
nodes are inferred by the graph structure rather than physically
nested w/in the node)

* WIP #476 Fixed minor code climate issues

* WIP Protected against null id on project unload

* WIP #476 Fixed 'push' of undefined bug in import tests

* WIP #476 Updated tests

* WIP #476 Only reset attr field size if attribute changed

* WIP #476 re-open error fixed

* WIP #476 update territory on creation

* WIP #476 Updated the nested editor height calculation

* WIP #476 Added resnet import example
2016-11-15 18:54:26 -06:00
Brian Broll 8ba2b397bb Replaced 'fs' w/ graceful-fs. Fixes #888 (#889) 2016-11-14 20:17:53 -06:00
Brian Broll 1960be5fec Replaced 'fs' w/ graceful-fs. Fixes #888 2016-11-13 07:41:34 -06:00
Brian Broll e431763a97 Change process dir to project root on start. Fixes #886 (#887) 2016-11-08 17:18:14 -06:00
Brian Broll 24d10fd0c7 Added more logs and error handlers. Fixes #884 (#885)
* Added more logs and error handlers. Fixes #884

* Suppressed extra logs during testing
2016-11-08 17:16:13 -06:00
Brian Broll b4d1e39d06 Handled failed subprocess error on seed creation. Fixes #882 (#883) 2016-11-01 16:36:15 -04:00
57 arquivos alterados com 3437 adições e 3677 exclusões
+6
Ver Arquivo
@@ -4,11 +4,17 @@
var gmeConfig = require('./config'),
webgme = require('webgme'),
path = require('path'),
fs = require('fs'),
rm_rf = require('rimraf'),
gracefulFs = require('graceful-fs'),
myServer;
process.chdir(__dirname);
webgme.addToRequireJsPaths(gmeConfig);
// Patch the 'fs' module to fix 'too many files open' error
gracefulFs.gracefulify(fs);
// Clear seed hash info
['nn', 'pipeline'].map(lib => path.join(__dirname, 'src', 'seeds', lib, 'hash.txt'))
.forEach(file => rm_rf.sync(file));
+7
Ver Arquivo
@@ -16,8 +16,15 @@
"MyPipelines": "PipelineIndex"
}
},
"PipelineEditor": {
"itemName": "operation"
},
"ExecutionView": {
"itemName": "job"
},
"ArchEditor": {
"hotkeys": "none",
"itemName": "layer",
"LayerColors": {}
},
"BreadcrumbHeader": {
+2
Ver Arquivo
@@ -19,6 +19,7 @@
"exists-file": "^2.1.0",
"express": "^4.14.0",
"lodash.difference": "^4.1.2",
"graceful-fs": "^4.1.10",
"lodash.merge": "^4.5.1",
"mongodb": "^2.2.10",
"nodemon": "^1.9.2",
@@ -33,6 +34,7 @@
"webgme-simple-nodes": "^2.1.0"
},
"devDependencies": {
"brython": "^3.2.7",
"chai": "^3.0.0",
"jszip": "^2.5.0",
"mocha": "^2.2.5",
+4
Ver Arquivo
@@ -11,6 +11,9 @@
}
}(this, function() {
return {
CONTAINED_LAYER_SET: 'addLayers',
CONTAINED_LAYER_INDEX: 'index',
LINE_OFFSET: 'lineOffset',
// DeepForge metadata creation in dist execution
@@ -37,6 +40,7 @@
OUTPUT: 'Output'
},
// Heartbeat constants (ExecPulse router)
PULSE: {
DEAD: 0,
ALIVE: 1,
+97 -348
Ver Arquivo
@@ -1,378 +1,127 @@
/* globals define*/
(function(root, factory){
if(typeof define === 'function' && define.amd) {
define(['./lua'], function(luajs){
return (root.LayerParser = factory(luajs));
// TODO: Load the brython script
define(['./lua'], function(brython){
return (root.LayerParser = factory(brython, console.assert));
});
} else if(typeof module === 'object' && module.exports) {
var luajs = require('./lua');
module.exports = (root.LayerParser = factory(luajs));
var brython = require('./node-brython'),
assert = require('assert');
module.exports = (root.LayerParser = factory(brython, assert));
}
}(this, function(luajs) {
}(this, function(brython, assert) {
var LayerParser = {};
//////////////////////// Setters ////////////////////////
var returnsSelf = function(fnNode){
var stats = fnNode.block.stats,
last = stats[stats.length-1];
function build_ast(src) {
brython.$py_module_path['__main__']='./'
return brython.py2js(src,'__main__', '__main__', '__builtins__')
}
if (last.type === 'stat.return') {
return last.nret[0].type === 'variable' && last.nret[0].val === 'self';
}
return false;
};
var isAttrSetter = function(node){
if (node.type === 'stat.assignment' && node.lefts.length === 1) {
var left = node.lefts[0];
return left.type === 'expr.index' && left.self.val === 'self';
}
return false;
};
var getSettingAttrName = function(node){
if (isAttrSetter(node)) {
var left = node.lefts[0];
return left.key.val;
}
return null;
};
var getSettingAttrValue = function(node){
if (isAttrSetter(node)) {
return node.right;
}
return null;
};
var isSetterMethod = function(curr, parent, className){
if (parent && parent.type === 'stat.method') {
// is it a fn w/ two statements (stats)
if (parent.self.val === className && curr.type === 'function' &&
curr.block.stats.length === 2) {
// Is the first statement setting a value?
return returnsSelf(curr) && getSettingAttrName(curr.block.stats[0]); // does it return itself?
// The provided tree gives us contexts which can have associated 'C'
function traverse(node, fn) {
var i;
if (node.children) {
for (i = node.children.length; i--;) {
traverse(node.children[i], fn);
fn(node.children[i]);
}
}
return false;
};
var isFnArg = function(method, name) {
return method.args.indexOf(name) !== -1;
};
var getSetterSchema = function(node, method) {
var setterType,
setterFn,
value = getSettingAttrValue(node);
if (value[0].type === 'variable' && isFnArg(method.func, value[0].val)) {
setterType = 'arg';
setterFn = method.key.val;
} else {
setterType = 'const';
setterFn = {};
setterFn[value[0].val] = method.key.val;
}
return {
setterType,
setterFn
};
};
//////////////////////// Setters END ////////////////////////
var isInitFn = function(node, className) {
if (node.type === 'stat.method' && node.self.val === className) {
return node.key.val === '__init';
}
return false;
};
var getClassAttrDefs = function(method) {
var fn = method.func,
dict = {},
attr,
right,
value;
luajs.codegen.traverse(curr => {
if (isAttrSetter(curr)) {
// Store the value if it is set to a constant
attr = curr.lefts[0].key.val;
right = curr.right[0];
if (right.type.indexOf('const.') !== -1) {
value = right.val;
if (right.type === 'const.nil') {
value = null;
}
dict[attr] = value;
}
}
})(fn);
return dict;
};
var getAttrsAndVals = function(method) {
// Given a method, get the 'self' attributes and the default values
var fn = method.func,
dict = {},
varName,
value,
varUsageCnt = {};
// Get the variables that are used only once (or updating themselves)
luajs.codegen.traverse(curr => {
if (curr.type === 'variable') {
varUsageCnt[curr.val] = varUsageCnt[curr.val] ?
varUsageCnt[curr.val] + 1 : 1;
}
})(method);
luajs.codegen.traverse(curr => {
// If the variable is only used once and is 'or'-ed w/ a constant
// during this use, we can infer that this is the default value
if (curr.type === 'expr.op' && curr.op === 'op.or' &&
curr.left.type === 'variable' && curr.right.type.indexOf('const') !== -1) {
varName = curr.left.val;
if (varUsageCnt[varName] === 1) {
value = curr.right.type === 'const.nil' ? null : curr.right;
dict[varName] = value;
}
}
})(fn);
return dict;
};
var copyNodeValues = function(attrs, from, to) {
var value;
for (var i = attrs.length; i--;) {
value = from[attrs[i]] || null;
if (value) {
value = (value && value.hasOwnProperty('val')) ? value.val : value;
to[attrs[i]] = value;
if (node.C && node.C.tree) {
for (i = node.C.tree.length; i--;) {
traverse(node.C.tree[i], fn);
fn(node.C.tree[i]);
}
}
return to;
};
}
var getTypeCheckInfo = function(cond) {
var caller,
method,
target,
expType;
var types = {},
layers = [],
pCtx,
classNode,
params;
// Check for torch.isTypeOf:
if (cond.type === 'expr.call' && cond.func.type === 'expr.index') {
caller = cond.func.self.val;
method = cond.func.key.val;
function isClass(node) {
return node.type === 'class';
}
if (cond.type === 'expr.call' && caller === 'torch') {
target = cond.args[0].val;
if (method === 'isTypeOf' && target) {
expType = cond.args[1].val;
return {
target,
type: expType
};
}
}
} else if (cond.type === 'expr.op') { // torch.type() === ''
// Check right side, too!
var sides = [cond.left, cond.right],
side,
otherSide;
function isInitFn(node) {
return node.type === 'def' && node.name === '__init__';
}
for (var i = sides.length; i--;) {
side = sides[i];
otherSide = sides[(i+1)%2];
if (side.type === 'expr.call' && side.func.type === 'expr.index') {
// Is it torch?
caller = side.func.self.val;
method = side.func.key.val;
if (caller === 'torch' && method === 'type') {
if (side.args[0].type === 'variable') {
target = side.args[0].val;
if (otherSide.type === 'const.string') {
expType = otherSide.val;
function getBaseClass(node) {
assert(node.type === 'class');
return node.args.tree[0].tree[0].tree[0].value;
}
return {
target: target,
type: expType
};
function findTorchLayers(root) {
var defaults = {},
layers = [],
defTypes,
args,
def;
traverse(root, node => {
// Get the class for the given function
if (isInitFn(node)) {
// TODO: What if there is no constructor? Is this a potential problem?
pCtx = node.parent.node.parent;
classNode = pCtx.C.tree[0];
if (isClass(classNode)) {
// remove the 'self' variable
// TODO: May need to update this for kwargs
// (use positional_list)
args = node.tree[1].tree;
defaults = {};
params = node.args.slice(1);
defTypes = {};
for (var i = args.length; i--;) {
if (args[i].tree[0]) {
def = args[i].tree[0].tree[0];
if (def.type === 'int') {
defaults[params[i-1]] = parseInt.apply(null, def.value.reverse());
} else {
defaults[params[i-1]] = def.value;
}
if (/^(True|False)$/.test(defaults[params[i-1]])) {
defTypes[params[i-1]] = 'boolean';
} else {
defTypes[params[i-1]] = def.type;
}
}
}
layers.push({
name: classNode.name,
baseType: getBaseClass(classNode),
//doc: classNode.doc_string || '',
defaults: defaults,
types: defTypes,
setters: {},
params: params
});
}
}
return null;
}
};
var isError = function(stat) {
var fn;
if (stat.type === 'stat.expr' && stat.expr.type === 'expr.call') {
fn = stat.expr.func.val;
return fn === 'error';
}
return false;
};
var inferParamTypes = function(node, paramDefs) {
var types = {},
check,
cond;
// Infer from assertions
luajs.codegen.traverse(curr => {
// check for 'assert's that check type
if (curr.type === 'expr.call' && curr.func.val === 'assert') {
cond = curr.args[0];
check = getTypeCheckInfo(cond);
if (check) {
types[check.target] = check.type;
}
} else if (curr.type === 'stat.if' && curr.cond.op === 'uop.not') {
// if statements throwing errors on type mismatch
cond = curr.cond.operand; // non-negated version
// Check that it throws an error on true
if (curr.tblock.stats.some(isError)) {
check = getTypeCheckInfo(cond);
if (check) {
types[check.target] = check.type;
}
}
}
})(node);
// Infer from defaults
Object.keys(paramDefs).forEach(param => {
var val = paramDefs[param];
if (val) { // initialized to 'null' doesn't help us...
types[param] = val.type.replace('const.', '');
}
});
return types;
};
return layers;
}
var findTorchClass = function(ast){
var torchClassArgs, // args for `torch.class(...)`
name = '',
alias,
baseType,
params,
setters = {},
defaults = {},
paramDefs,
attrDefs;
if(ast.type == 'function'){
ast.block.stats.forEach(function(func){
if(func.type == 'stat.local' && func.right && func.right[0] &&
func.right[0].func && func.right[0].func.self &&
func.right[0].func.self.val == 'torch' &&
func.right[0].func.key.val == 'class'){
torchClassArgs = func.right[0].args.map(arg => arg.val);
name = torchClassArgs[0];
if(name !== ''){
name = name.replace('nn.', '');
alias = func.names[0] || name;
if (torchClassArgs.length > 1) {
baseType = torchClassArgs[1].replace('nn.', '');
}
}
}
});
}
// Get the setters, defaults and type info (inferred)
var setterNames,
schema,
types,
values;
luajs.codegen.traverse((curr, parent) => {
var firstLine,
attrName;
// Record the setter functions
if (isSetterMethod(curr, parent, alias)) {
firstLine = curr.block.stats[0];
// just use the attribute attrName for now...
attrName = getSettingAttrName(firstLine);
// merge schemas
schema = getSetterSchema(firstLine, parent);
if (setters[attrName] && setters[attrName].setterType === 'const') { // merge
for (var val in schema.setterFn) {
setters[attrName].setterFn[val] = schema.setterFn[val];
}
} else {
setters[attrName] = schema;
}
} else if (isInitFn(curr, alias)) { // Record the defaults
paramDefs = getAttrsAndVals(curr);
attrDefs = getClassAttrDefs(curr);
types = inferParamTypes(curr, paramDefs);
// get ctor args
params = curr.func.args;
if(params.length === 0 && curr.func.varargs){
params.push('params');
}
}
})(ast);
// Get the defaults for the params from defs
if (paramDefs && params) {
copyNodeValues(params, paramDefs, defaults);
}
// Get the defaults for the setters from attrDefs
if (attrDefs) {
setterNames = Object.keys(setters);
copyNodeValues(setterNames, attrDefs, defaults);
}
// Remove any const setters w/ only one value and no default
setterNames = Object.keys(setters);
for (var i = setterNames.length; i--;) {
schema = setters[setterNames[i]];
if (schema.setterType === 'const') {
values = Object.keys(schema.setterFn);
if (values.length === 1 &&
// boolean setters can have the default value inferred
values[0] !== 'true' && values[0] !== 'false' &&
!defaults[setterNames[i]]) {
delete setters[setterNames[i]];
}
}
}
return {
name,
baseType,
params,
setters,
types,
defaults
};
};
LayerParser.parse = function(text) {
// Try to find the class definitions...
//
// Need to create:
//
// setters: (I don't think these are used in pytorch!
// types:
// type:
//////////////////////// Setters ////////////////////////
LayerParser.parse = function(src) {
try {
var ast = luajs.parser.parse(text);
return findTorchClass(ast);
brython.$py_module_path['__main__']='./';
var ast = brython.py2js(src,'__main__', '__main__', '__builtins__');
var layers = findTorchLayers(ast);
return layers;
} catch (e) {
return null;
}
+176
Ver Arquivo
@@ -0,0 +1,176 @@
/*
Author: Billy Earney
Date: 04/19/2013
License: MIT
Description: This file can work as a "bridge" between nodejs and brython
so that client side brython code can be executed on the server side.
Will brython replace Cython one day? Only time will tell.
:)
*/
var fs = require('fs'),
path = require('path'),
brythonSrcPath = path.join(__dirname, '..', '..', 'node_modules', 'brython', 'www', 'src', 'brython.js');
document={};
document.getElementsByTagName = () => [{src: ''}];
window={};
window.location = {href: ''};
window.navigator={}
window.confirm = () => true;
window.console = console;
document.$py_src = {}
document.$debug = 0
self={};
__BRYTHON__={}
__BRYTHON__.$py_module_path = {}
__BRYTHON__.$py_module_alias = {}
__BRYTHON__.$py_next_hash = -Math.pow(2,53)
__BRYTHON__.exception_stack = []
__BRYTHON__.scope = {}
__BRYTHON__.modules = {}
// Read and eval library
jscode = fs.readFileSync(brythonSrcPath, 'utf8');
eval(jscode);
//function node_import(module,alias,names) {
function $import_single(module) {
var search_path=['../src/libs', '../src/Lib'];
var ext=['.js', '.py'];
var mods=[module, module+'/__init__'];
for(var i=0, _len_i = search_path.length; i < _len_i; i++) {
for (var j=0, _len_j = ext.length; j < _len_j; j++) {
for (var k=0, _len_k = mods.length; k < _len_k; k++) {
var path=search_path[i]+'/'+mods[k]+ext[j]
//console.log("searching for " + path);
var module_contents;
try {
module_contents=fs.readFileSync(path, 'utf8')
} catch(err) {}
if (module_contents !== undefined) {
console.log("imported " + module)
//console.log(module_contents);
if (ext[j] == '.js') {
return $import_js_module(module,alias,names,path,module_contents)
}
return $import_py_module(module,alias,names,path,module_contents)
}
}
}
}
console.log("error time!");
res = Error()
res.name = 'NotFoundError'
res.message = "No module named '"+module+"'"
throw res
}
$compile_python=function(module_contents,module) {
var root = __BRYTHON__.py2js(module_contents,module)
var body = root.children
root.children = []
// use the module pattern : module name returns the results of an anonymous function
var mod_node = new $Node('expression')
//if(names!==undefined){alias='$module'}
new $NodeJSCtx(mod_node,'$module=(function()')
root.insert(0,mod_node)
mod_node.children = body
// search for module-level names : functions, classes and variables
var mod_names = []
for(var i=0, _len_i = mod_node.children.length; i < _len_i;i++){
var node = mod_node.children[i]
// use function get_ctx()
// because attribute 'context' is renamed by make_dist...
var ctx = node.get_ctx().tree[0]
if(ctx.type==='def'||ctx.type==='class'){
if(mod_names.indexOf(ctx.name)===-1){mod_names.push(ctx.name)}
} else if(ctx.type==='from') {
for (var j=0, _len_j = ctx.names.length; j < _len_j; j++) {
var name=ctx.names[j];
if (name === '*') {
// just pass, we don't want to include '*'
} else if (ctx.aliases[name] !== undefined) {
if (mod_names.indexOf(ctx.aliases[name])===-1){
mod_names.push(ctx.aliases[name])
}
} else {
if (mod_names.indexOf(ctx.names[j])===-1){
mod_names.push(ctx.names[j])
}
}
}
}else if(ctx.type==='assign'){
var left = ctx.tree[0]
if(left.type==='expr'&&left.tree[0].type==='id'&&left.tree[0].tree.length===0){
var id_name = left.tree[0].value
if(mod_names.indexOf(id_name)===-1){mod_names.push(id_name)}
}
}
}
// create the object that will be returned when the anonymous function is run
var ret_code = 'return {'
for(var i=0, _len_i = mod_names.length; i < _len_i;i++){
ret_code += mod_names[i]+':'+mod_names[i]+','
}
ret_code += '__getattr__:function(attr){return this[attr]},'
ret_code += '__setattr__:function(attr,value){this[attr]=value}'
ret_code += '}'
var ret_node = new $Node('expression')
new $NodeJSCtx(ret_node,ret_code)
mod_node.add(ret_node)
// add parenthesis for anonymous function execution
var ex_node = new $Node('expression')
new $NodeJSCtx(ex_node,')()')
root.add(ex_node)
try{
var js = root.to_js()
return js;
}catch(err){
eval('throw '+err.name+'(err.message)')
}
return undefined;
}
function build_ast(src) {
__BRYTHON__.$py_module_path['__main__']='./'
return __BRYTHON__.py2js(src,'__main__', '__main__', '__builtins__')
}
function execute_python_script(filename) {
_py_src=fs.readFileSync(filename, 'utf8')
var root = build_ast(_py_src)
var js = root.to_js()
//eval(js);
}
//console.log("try to execute compile script");
__BRYTHON__.$py_module_path = __BRYTHON__.$py_module_path || {}
__BRYTHON__.$py_module_alias = __BRYTHON__.$py_module_alias || {}
__BRYTHON__.exception_stack = __BRYTHON__.exception_stack || []
__BRYTHON__.scope = __BRYTHON__.scope || {}
__BRYTHON__.imported = __BRYTHON__.imported || {}
__BRYTHON__.modules = __BRYTHON__.modules || {}
__BRYTHON__.compile_python=$compile_python
__BRYTHON__.debug = 0
__BRYTHON__.$options = {}
__BRYTHON__.$options.debug = 0
// other import algs don't work in node
//import_funcs=[node_import]
if (!module.parent) {
var filename=process.argv[2];
execute_python_script(filename)
}
module.exports = __BRYTHON__;
+2 -2
Ver Arquivo
@@ -46,7 +46,7 @@ define([
minValue;
nodes = this.graph.nodes().map(id => this.graph.node(id));
minValue = Math.min.apply(null, nodes.map(node => node[dim]));
minValue = nodes.length ? Math.min.apply(null, nodes.map(node => node[dim] || 0)) : 0;
return maxValue-minValue;
};
@@ -55,7 +55,7 @@ define([
};
ThumbnailWidget.prototype.getSvgHeight = function() {
return this.getSvgDistanceDim('y');
return this.height - 25;
};
ThumbnailWidget.prototype.getViewBox = function() {
@@ -0,0 +1,39 @@
/*globals define, _*/
/*jshint browser: true, camelcase: false*/
define([
'js/Decorators/DecoratorBase',
'./EasyDAG/ContainerLayerDecorator.EasyDAGWidget'
], function (
DecoratorBase,
ContainerLayerDecoratorEasyDAGWidget
) {
'use strict';
var ContainerLayerDecorator,
__parent__ = DecoratorBase,
__parent_proto__ = DecoratorBase.prototype,
DECORATOR_ID = 'ContainerLayerDecorator';
ContainerLayerDecorator = function (params) {
var opts = _.extend({loggerName: this.DECORATORID}, params);
__parent__.apply(this, [opts]);
this.logger.debug('ContainerLayerDecorator ctor');
};
_.extend(ContainerLayerDecorator.prototype, __parent_proto__);
ContainerLayerDecorator.prototype.DECORATORID = DECORATOR_ID;
/*********************** OVERRIDE DecoratorBase MEMBERS **************************/
ContainerLayerDecorator.prototype.initializeSupportedWidgetMap = function () {
this.supportedWidgetMap = {
EasyDAG: ContainerLayerDecoratorEasyDAGWidget
};
};
return ContainerLayerDecorator;
});
@@ -0,0 +1,25 @@
.condense .nested-layers {
display: none;
}
.nested-layers .hover-box {
stroke: black;
stroke-dasharray: 4, 4;
stroke-opacity: 0;
}
.nested-layers .unhovered .button {
opacity: 0;
}
.nested-layers .hovered .button {
opacity: 1;
}
.nested-layers .unhovered .hover-box {
stroke-opacity: 0;
}
.nested-layers .hovered .hover-box {
stroke-opacity: 0;
}
@@ -0,0 +1,428 @@
/*globals define, _, */
/*jshint browser: true, camelcase: false*/
define([
'decorators/LayerDecorator/EasyDAG/LayerDecorator.EasyDAGWidget',
'js/Constants',
'deepforge/Constants',
'./NestedLayer',
'widgets/EasyDAG/Buttons',
'css!./ContainerLayerDecorator.EasyDAGWidget.css'
], function (
LayerDecorator,
GME_CONSTANTS,
CONSTANTS,
NestedLayer,
Buttons
) {
'use strict';
var ContainerLayerDecorator,
ZOOM = 0.8,
DECORATOR_ID = 'ContainerLayerDecorator';
// Container layer nodes need to be able to nest the containedLayers
// in order inside of themselves when expanded
ContainerLayerDecorator = function (options) {
this.nestedLayers = {};
LayerDecorator.call(this, options);
this.$nested = this.$el.append('g')
.attr('class', 'nested-layers');
// If clicked, deselect the given nested layer
this.$el.on('click', () => {
if (this.expanded) {
Object.keys(this.nestedLayers).forEach(id => {
this.nestedLayers[id].widget.onBackgroundClick();
});
}
});
this.onNestedRefresh = _.debounce(this.updateExpand.bind(this), 50);
// Add event handlers
NestedLayer.prototype.addLayerBefore = function(layerId) {
var decorator = this._parent,
index = decorator._node.containedLayers.indexOf(this.id);
return decorator.addLayerAt(layerId, index - 1);
};
NestedLayer.prototype.addLayerAfter = function(layerId) {
var decorator = this._parent,
index = decorator._node.containedLayers.indexOf(this.id);
return decorator.addLayerAt(layerId, index + 1);
};
NestedLayer.prototype.isLast = function() {
var index = this._parent._node.containedLayers.length - 1;
return this._parent._node.containedLayers[index] === this.id;
};
NestedLayer.prototype.isFirst = function() {
return this._parent._node.containedLayers[0] === this.id;
};
NestedLayer.prototype.moveLayerForward = function() {
return this.moveLayer(true);
};
NestedLayer.prototype.moveLayerBackward = function() {
return this.moveLayer();
};
NestedLayer.prototype.moveLayer = function(forward) {
var decorator = this._parent,
index = decorator._node.containedLayers.indexOf(this.id),
client = decorator.client,
msg;
decorator._node.containedLayers.splice(index, 1);
if (forward) {
index = Math.max(0, index - 1);
} else {
index++;
}
decorator._node.containedLayers.splice(index, 0, this.id);
msg = `Swapping nested layers at ${index} and ${forward ? index-1 : index+1}`;
client.startTransaction(msg);
decorator._updateNestedIndices();
client.completeTransaction();
};
NestedLayer.prototype.onLastNodeRemoved = function() {
var decorator = this._parent,
index = decorator._node.containedLayers.indexOf(this.id),
msg = `Removing nested layer of ${decorator._node.name} at position ${index}`;
decorator.client.startTransaction(msg);
decorator.client.deleteNode(this.id);
decorator.client.completeTransaction();
};
this.updateNestedTerritory();
};
_.extend(ContainerLayerDecorator.prototype, LayerDecorator.prototype);
ContainerLayerDecorator.prototype.DECORATOR_ID = DECORATOR_ID;
ContainerLayerDecorator.prototype._updateNestedIndices = function() {
this._node.containedLayers.forEach((layerId, index) => {
// Set the layer's member registry to it's index
this.client.setMemberRegistry(
this._node.id,
layerId,
CONSTANTS.CONTAINED_LAYER_SET,
CONSTANTS.CONTAINED_LAYER_INDEX,
index
);
});
};
ContainerLayerDecorator.prototype.addLayerAt = function(baseId, index) {
var client = this.client,
parentId = this._node.id,
archNode,
newId,
msg;
// Get the index of the given layer
index = Math.max(index, 0);
archNode = client.getAllMetaNodes()
.find(node => node.getAttribute('name') === 'Architecture');
// Create a new Architecture node in the given node
msg = `Adding layer to ${this._node.name} at position ${index}`;
client.startTransaction(msg);
newId = client.createNode({
parentId: parentId,
baseId: archNode.getId()
});
// Create the selected layer
client.createNode({
parentId: newId,
baseId: baseId
});
client.addMember(parentId, newId, CONSTANTS.CONTAINED_LAYER_SET);
this._node.containedLayers.splice(index, 0, newId);
this._updateNestedIndices();
client.completeTransaction();
};
ContainerLayerDecorator.prototype.condense = function() {
// hide the nested layers
this.$el.attr('class', 'centering-offset condense');
this.removeCreateNestedBtn();
return LayerDecorator.prototype.condense.apply(this, arguments);
};
ContainerLayerDecorator.prototype.updateNestedTerritory = function() {
// Add the nested layers and update
if (!this._nestedTerritoryUI) {
this._nestedTerritoryUI = this.client.addUI(this, this._containedEvents.bind(this));
}
this._territory = {};
this._node.containedLayers.forEach(id => this._territory[id] = {children: 0});
this.client.updateTerritory(this._nestedTerritoryUI, this._territory);
};
ContainerLayerDecorator.prototype._containedEvents = function(events) {
for (var i = events.length; i--;) {
switch (events[i].etype) {
case GME_CONSTANTS.TERRITORY_EVENT_LOAD:
if (!this.nestedLayers[events[i].eid]) {
this.createNestedWidget(events[i].eid);
}
break;
case GME_CONSTANTS.TERRITORY_EVENT_UNLOAD:
this.removeNestedWidget(events[i].eid);
break;
}
}
if (events.length > 1) { // if more than just 'complete' event
this.updateExpand();
}
};
ContainerLayerDecorator.prototype.update = function(node) {
var attrsUpdated = false,
attrs = this._attributes;
this._node = node;
// Update the attributes
this.setAttributes();
attrsUpdated = !_.isEqual(attrs, this._attributes);
// Check for a new nested layer
var hasNewLayers = this._node.containedLayers
.filter(id => !this.nestedLayers[id])
.length > 0;
if (hasNewLayers) {
this.updateNestedTerritory();
} else {
// Update the order of the nested layers
if (this._selected) {
this.expand();
} else {
this.condense();
}
}
// Only reset fieldsWidth if the attribute has gotten larger
if (attrsUpdated) {
this.fieldsWidth = null;
}
};
ContainerLayerDecorator.prototype.updateExpand = function() {
if (this.expanded) {
this.expand();
}
};
ContainerLayerDecorator.prototype.createNestedWidget = function(id) {
if (!this.$nested) {
this.$nested = this.$el.append('g')
.attr('class', 'nested-layers');
}
this.nestedLayers[id] = new NestedLayer({
$container: this.$nested,
parent: this,
client: this.client,
logger: this.logger,
onRefresh: this.onNestedRefresh,
id: id
});
return this.nestedLayers[id];
};
ContainerLayerDecorator.prototype.removeNestedWidget = function(id) {
this.nestedLayers[id].destroy();
delete this.nestedLayers[id];
this.updateExpand();
};
ContainerLayerDecorator.prototype._renderInfo = function(top, width) {
var isAnUpdate = this.expanded,
y = top;
// Add the attribute fields
this.clearFields();
this.$attributes = this.$el.append('g')
.attr('fill', '#222222');
if (!isAnUpdate) {
this.$attributes.attr('opacity', 0);
}
y = this.createAttributeFields(y, width);
y = this.createPointerFields(y, width);
if (y !== top) {
y += this.ROW_HEIGHT/2;
}
return y;
};
ContainerLayerDecorator.prototype.expand = function() {
// This should be rendered with the attributes
var height,
width,
// Attributes
initialY = 25,
isAnUpdate = this.expanded,
NAME_MARGIN = 15,
nestedMargin = 15, // minimum
margin = 5,
y = margin + initialY,
x = margin,
i;
// Shift name down
this.$name.attr('y', 20);
// Add the nested children
var ids = this._node.containedLayers.filter(id => this.nestedLayers[id]),
totalNestedWidth = 0,
maxNestedHeight = 0,
fieldWidth,
widget;
if (ids.length === 0) {
maxNestedHeight = CreateNestedBtn.SIZE * 2;
} else {
for (i = 0; i < ids.length; i++) {
widget = this.nestedLayers[ids[i]].widget;
totalNestedWidth += widget.getSvgWidth() * ZOOM;
maxNestedHeight = Math.max(widget.getSvgHeight() * ZOOM, maxNestedHeight);
// Update the buttons (in case of reorder)
this.nestedLayers[ids[i]].refreshButtons();
}
}
fieldWidth = this.fieldsWidth + 3 * NAME_MARGIN;
width = Math.max(
this.nameWidth + 2 * NAME_MARGIN,
this.size.width,
fieldWidth,
totalNestedWidth + (ids.length + 1) * nestedMargin
);
// Render attributes
y = this._renderInfo(y, fieldWidth);
y += nestedMargin;
// Update width, height
height = y + maxNestedHeight + nestedMargin;
// Equally space the nested widgets
nestedMargin = (width - totalNestedWidth)/(ids.length + 1);
x = nestedMargin - width/2;
for (i = 0; i < ids.length; i++) {
this.nestedLayers[ids[i]].$el
.attr('transform', `translate(${x}, ${y}) scale(${ZOOM})`);
x += this.nestedLayers[ids[i]].widget.getSvgWidth() * ZOOM + nestedMargin;
}
this.removeCreateNestedBtn();
if (ids.length === 0) {
// Add the 'create nested layer' button if no nested layers
this.$createNestedBtn = new CreateNestedBtn({
context: this,
$pEl: this.$el,
y: y + CreateNestedBtn.SIZE
});
}
this.$body
.transition()
.attr('x', -width/2)
.attr('y', 0)
.attr('rx', 0)
.attr('ry', 0)
.attr('width', width)
.attr('height', height)
.each('end', () => {
if (!isAnUpdate) {
this.$attributes.attr('opacity', 1);
this.$el.attr('class', 'centering-offset expand');
}
});
if (this.height !== height || this.width !== width) {
this.height = height;
this.width = width;
this.expanded = true;
this.$el
.attr('transform', `translate(${this.width/2}, 0)`);
this.onResize();
}
};
ContainerLayerDecorator.prototype.removeCreateNestedBtn = function() {
if (this.$createNestedBtn) {
this.$createNestedBtn.remove();
this.$createNestedBtn = null;
}
};
ContainerLayerDecorator.prototype.destroyNested = function() {
Object.keys(this.nestedLayers).forEach(id => this.nestedLayers[id].destroy());
this.nestedLayers = {};
if (this.$nested) {
this.$nested.remove();
this.$nested = this.$el.append('g')
.attr('class', 'nested-layers');
}
};
ContainerLayerDecorator.prototype.destroy = function() {
LayerDecorator.prototype.destroy.call(this);
if (this._nestedTerritoryUI) {
this.client.removeUI(this._nestedTerritoryUI);
this._nestedTerritoryUI = null;
}
this.destroyNested();
};
var CreateNestedBtn = function(params) {
params.title = 'Add nested layer';
Buttons.Add.call(this, params);
};
CreateNestedBtn.SIZE = Buttons.Add.SIZE;
CreateNestedBtn.prototype = Object.create(Buttons.Add.prototype);
CreateNestedBtn.prototype._onClick = function() {
// Call addLayerAfter and prompt for a layer
this.promptLayer()
.then(layerId => this.addLayerAt(layerId, 0));
};
ContainerLayerDecorator.prototype.expandAll = function() {
this.expand();
// For each of the nested layers, expand all their nodes
Object.keys(this.nestedLayers)
.forEach(id => this.nestedLayers[id].widget.expandAllNodes());
};
ContainerLayerDecorator.prototype.condenseAll = function() {
this.condense();
// For each of the nested layers, expand all their nodes
Object.keys(this.nestedLayers)
.forEach(id => this.nestedLayers[id].widget.expandAllNodes(true));
};
return ContainerLayerDecorator;
});
@@ -0,0 +1,175 @@
/*globals define, _ */
define([
'panels/ArchEditor/ArchEditorControl',
'widgets/ArchEditor/ArchEditorWidget',
'widgets/EasyDAG/Buttons'
], function(
ArchEditor,
ArchEditorWidget,
Buttons
) {
var nop = () => {};
var NestedLayer = function(opts) {
this.$el = opts.$container.append('g')
.attr('class', 'nested-layer');
this.id = opts.id;
this._parent = opts.parent;
this.logger = opts.logger;
this.refreshButtons = _.debounce(this.updateButtons.bind(this), 100);
this.$outline = this.$el.append('rect') // for hover detection
.attr('fill-opacity', 0)
.attr('x', 0)
.attr('y', 0);
this.$content = this.$el.append('g');
this.initHover();
this.widget = new ArchEditorWidget({
logger: this.logger.fork('ArchWidget'),
autoCenter: false,
svg: this.$content
});
this.widget.setTitle =
this.widget.updateEmptyMsg = nop;
this.onRefresh = opts.onRefresh;
this.widget.refreshExtras = this.onWidgetRefresh.bind(this);
this.control = new ArchEditor({
logger: this.logger.fork('ArchControl'),
client: opts.client,
embedded: true,
widget: this.widget
});
this.control._onUnload = () => {
ArchEditor.prototype._onUnload.apply(this.control, arguments);
// If it was the last node, remove it
var node = this.control._client.getNode(this.id);
if (node.getChildrenIds().length === 0) {
this.onLastNodeRemoved();
}
};
// hack :(
this.control.$btnModelHierarchyUp = {
show: nop,
hide: nop
};
this.widget.active = true;
this.control.selectedObjectChanged(this.id);
};
NestedLayer.prototype.initHover = function() {
this.$hover = this.$el.append('g')
.attr('class', 'hover-items');
this.$el.on('mouseenter', this.onHover.bind(this));
this.$el.on('mouseleave', this.onUnhover.bind(this));
// Buttons
this.$leftBtn = new Buttons.Add({
hide: true,
icon: this.isFirst() ? 'plus' : 'chevron-left',
$pEl: this.$hover
});
this.$rightBtn = new Buttons.Add({
hide: true,
icon: this.isLast() ? 'plus' : 'chevron-right',
$pEl: this.$hover
});
this.$deleteBtn = new Buttons.DeleteOne({
hide: true,
title: 'Delete',
$pEl: this.$hover
});
this.$leftBtn._onClick = this.clickLeft.bind(this);
this.$rightBtn._onClick = this.clickRight.bind(this);
this.$deleteBtn._onClick = () => this.onLastNodeRemoved();
this.$leftHint = this.$leftBtn.$el.append('title');
this.$rightHint = this.$rightBtn.$el.append('title');
this.refreshButtons();
};
NestedLayer.prototype.updateButtons = function() {
this.$leftBtn.icon = this.isFirst() ? 'plus' : 'chevron-left';
this.$rightBtn.icon = this.isLast() ? 'plus' : 'chevron-right';
this.$leftHint.text(this.isFirst() ?
'Add nested layer' :
'Move nested layer left'
);
this.$rightHint.text(this.isLast() ?
'Add nested layer' :
'Move nested layer right'
);
this.$leftBtn.render();
this.$rightBtn.render();
};
NestedLayer.prototype.clickLeft = function() {
if (this.isFirst()) {
this.promptLayer()
.then(layerId => this.addLayerBefore(layerId));
} else {
this.moveLayerForward();
}
this.onUnhover();
};
NestedLayer.prototype.promptLayer = function() {
var nodes = this.widget.getValidInitialNodes();
return this.widget.promptLayer(nodes)
.then(selected => selected.node.id);
};
NestedLayer.prototype.clickRight = function() {
if (this.isLast()) {
this.promptLayer()
.then(layerId => this.addLayerAfter(layerId));
} else {
this.moveLayerBackward();
}
this.onUnhover();
};
NestedLayer.prototype.onHover = function() {
this.refreshButtons();
this.$hover.attr('class', 'hover-items hovered');
};
NestedLayer.prototype.onUnhover = function() {
this.$hover.attr('class', 'hover-items unhovered');
};
NestedLayer.prototype.onWidgetRefresh = function() {
var width = this.widget.getSvgWidth(),
height = this.widget.getSvgHeight();
this.$outline
.attr('width', width)
.attr('height', height);
this.$leftBtn.$el.attr('transform', `translate(0, ${height/2})`);
this.$rightBtn.$el
.attr('transform', `translate(${width}, ${height/2})`);
this.onRefresh();
};
NestedLayer.prototype.destroy = function() {
this.control.destroy();
this.widget.destroy();
this.$el.remove();
};
return NestedLayer;
});
+1 -1
Ver Arquivo
@@ -92,7 +92,7 @@ define([
this.logger.info(`${tuple[0]} version info:\n${projVersion} ` +
`(project)\n${latest} (latest)`);
return latest !== projVersion;
return projVersion < latest;
});
return Q.all(tuples.map(tuple => this.uploadSeed.apply(this, tuple)));
+9 -3
Ver Arquivo
@@ -205,9 +205,10 @@ define([
};
// Some helper methods w/ attribute handling
var LUA_TO_GME = {
var PYTHON_TO_GME = {
boolean: 'boolean',
number: 'float',
float: 'float',
int: 'integer',
string: 'string'
};
@@ -301,7 +302,7 @@ define([
attrs.forEach(name => {
desc = {};
defVal = defaults.hasOwnProperty(name) ? defaults[name] : '';
type = LUA_TO_GME[types[name]];
type = PYTHON_TO_GME[types[name]];
if (type) {
desc.type = type;
}
@@ -376,6 +377,11 @@ define([
// Set the min, max
schema.max = +schema.max;
}
// Add the enum for booleans so we use python style True/False
if (schema.type === 'boolean') {
schema.enum = ['True', 'False'];
schema.type = 'string';
}
// Create the attribute and set the schema
this.core.setAttributeMeta(node, name, schema);
-1
Ver Arquivo
@@ -17,7 +17,6 @@
"value": "all",
"valueItems": [
"nn",
"rnn",
"all"
],
"valueType": "string",
+3 -6
Ver Arquivo
@@ -1,13 +1,10 @@
/*globals define*/
define([
'text!./nn.json',
'text!./rnn.json'
'text!./nn.json'
], function(
nn,
rnn
nn
) {
return {
nn: nn,
rnn: rnn
nn: nn
};
});
Diferenças do arquivo suprimidas por serem muito extensas Carregar Diff
-178
Ver Arquivo
@@ -1,178 +0,0 @@
[
{
"name": "CopyGrad",
"baseType": "Identity",
"setters": {},
"defaults": {},
"type": "RNN"
},
{
"name": "FastLSTM",
"baseType": "LSTM",
"params": [
"inputSize",
"outputSize",
"rho",
"eps",
"momentum",
"affine"
],
"setters": {},
"types": {
"eps": "number",
"momentum": "number"
},
"defaults": {
"momentum": 0.1,
"eps": 0.1
},
"type": "RNN"
},
{
"name": "LSTM",
"baseType": "AbstractRecurrent",
"params": [
"inputSize",
"outputSize",
"rho",
"cell2gate"
],
"setters": {},
"types": {
"rho": "number"
},
"defaults": {
"rho": 9999
},
"type": "RNN"
},
{
"name": "LinearNoBias",
"baseType": "Linear",
"params": [
"inputSize",
"outputSize"
],
"setters": {},
"types": {},
"defaults": {},
"type": "Simple"
},
{
"name": "LookupTableMaskZero",
"baseType": "LookupTable",
"params": [
"nIndex",
"nOutput"
],
"setters": {},
"types": {},
"defaults": {},
"type": "RNN"
},
{
"name": "NormStabilizer",
"baseType": "AbstractRecurrent",
"params": [
"beta"
],
"setters": {},
"defaults": {},
"type": "RNN"
},
{
"name": "Recurrent",
"baseType": "AbstractRecurrent",
"params": [
"start",
"input",
"feedback",
"transfer",
"rho",
"merge"
],
"setters": {},
"types": {
"start": "nn.Module",
"transfer": "nn.Module",
"feedback": "nn.Module",
"input": "nn.Module"
},
"defaults": {},
"type": "RNN"
},
{
"name": "SAdd",
"baseType": "Module",
"params": [
"addend",
"negate"
],
"setters": {},
"types": {},
"defaults": {},
"type": "RNN"
},
{
"name": "SeqBRNN",
"baseType": "Container",
"params": [
"inputDim",
"hiddenDim",
"batchFirst"
],
"setters": {},
"types": {},
"defaults": {},
"type": "RNN"
},
{
"name": "SeqGRU",
"baseType": "Module",
"params": [
"inputSize",
"outputSize"
],
"setters": {},
"types": {},
"defaults": {},
"type": "RNN"
},
{
"name": "SeqLSTM",
"baseType": "Module",
"params": [
"inputsize",
"hiddensize",
"outputsize"
],
"setters": {},
"types": {},
"defaults": {},
"type": "RNN"
},
{
"name": "SeqLSTMP",
"baseType": "SeqLSTM",
"params": [
"inputsize",
"hiddensize",
"outputsize"
],
"setters": {},
"types": {},
"defaults": {},
"type": "RNN"
},
{
"name": "SeqReverseSequence",
"baseType": "Module",
"params": [
"dim"
],
"setters": {},
"types": {},
"defaults": {},
"type": "RNN"
}
]
@@ -6,13 +6,15 @@ define([
'SimpleNodes/Constants',
'deepforge/layer-args',
'deepforge/utils',
'deepforge/Constants',
'underscore',
'text!./metadata.json'
], function (
PluginBase,
Constants,
SimpleNodeConstants,
createLayerDict,
utils,
Constants,
_,
metadata
) {
@@ -65,13 +67,13 @@ define([
};
GenerateArchitecture.prototype.createOutputFiles = function (tree) {
var layers = tree[Constants.CHILDREN],
var layers = tree[SimpleNodeConstants.CHILDREN],
result = {},
code = '';
this.definitions = [
'require \'nn\'',
'require \'rnn\''
'import torch',
'import torch.nn as nn'
];
// Add an index to each layer
@@ -83,6 +85,7 @@ define([
code += this.genLayerDefinitions(layers);
}
// TODO: Define the network w/ 'class ARCHITECTURE_NAME'
this.logger.debug('Generating architecture code...');
code += this.genArchCode(layers);
this.logger.debug('Prepending hoisted code...');
@@ -125,12 +128,57 @@ define([
};
GenerateArchitecture.prototype.createLayer = function (layer) {
var args = this.createArgString(layer);
return `nn.${layer.name}${args}`;
var args = this.createArgString(layer),
def = `nn.${layer.name}${args}`,
type = layer.base.base.name,
addedIds,
node,
name,
children,
id;
// Check if it is a container and has the 'addLayers' set
// If so, it should sort them by their registry 'index' and add
// each nested architecture's code to the given container
if (type === 'Container') {
// Get the members of the 'addLayers' set
addedIds = {};
id = layer[SimpleNodeConstants.NODE_PATH];
node = this._nodeCache[id];
this.core.getMemberPaths(node, Constants.CONTAINED_LAYER_SET)
.forEach(id => addedIds[id] = true);
// Get the (sorted) children
children = layer[SimpleNodeConstants.CHILDREN]
.map(child => { // get (child, index) tuples
var index;
id = child[SimpleNodeConstants.NODE_PATH];
index = this.core.getMemberRegistry(node, Constants.CONTAINED_LAYER_SET, id, Constants.CONTAINED_LAYER_INDEX);
return [child, index];
})
.filter(pair => pair[1] !== undefined) // remove non-members
.sort((a, b) => a[1] < b[1] ? -1 : 1) // sort by 'index'
.map(pair => pair[0]);
var addedLayerDefs = '',
firstLayer;
for (var i = 0; i < children.length; i++) {
id = children[i][SimpleNodeConstants.NODE_PATH];
// Get the children!
firstLayer = children[i][SimpleNodeConstants.CHILDREN][0];
name = this.getVarName(utils.abbr(layer.name + '_' + i));
addedLayerDefs += this.createSequential(firstLayer, name).code;
def += `:add(${name})`;
}
this.hoist(addedLayerDefs);
}
return def;
};
GenerateArchitecture.prototype.createSequential = function (layer, name) {
var next = layer[Constants.NEXT][0],
var next = layer[SimpleNodeConstants.NEXT][0],
args,
snippet,
snippets,
@@ -142,7 +190,7 @@ define([
while (layer) {
// if there is only one successor, just add the given layer
if (layer[Constants.PREV].length > 1) { // sequential layers are over
if (layer[SimpleNodeConstants.PREV].length > 1) { // sequential layers are over
next = layer; // the given layer will be added by the caller
break;
} else { // add the given layer
@@ -151,11 +199,11 @@ define([
}
while (layer && layer[Constants.NEXT].length > 1) { // concat/parallel
while (layer && layer[SimpleNodeConstants.NEXT].length > 1) { // concat/parallel
// if there is a fork, recurse and add a concat layer
this.logger.debug(`detected fork of size ${layer[Constants.NEXT].length}`);
snippets = layer[Constants.NEXT].map(nlayer =>
this.logger.debug(`detected fork of size ${layer[SimpleNodeConstants.NEXT].length}`);
snippets = layer[SimpleNodeConstants.NEXT].map(nlayer =>
this.createSequential(nlayer, this.getVarName('net')));
code += '\n' + snippets.map(snippet => snippet.code).join('\n');
@@ -183,7 +231,7 @@ define([
`concat_${layer[INDEX]}:add(${snippet.name})`)
.join('\n') + `\n\n${name}:add(concat_${layer[INDEX]})`;
next = layer[Constants.NEXT][0];
next = layer[SimpleNodeConstants.NEXT][0];
} else {
next = null; // no next layers
}
@@ -203,7 +251,7 @@ define([
}
layer = next;
next = layer && layer[Constants.NEXT][0];
next = layer && layer[SimpleNodeConstants.NEXT][0];
}
return {
@@ -218,14 +266,14 @@ define([
var content = layer[arg];
if (typeof content === 'object') { // layer as arg
if (content[Constants.CHILDREN].length) {
if (content[SimpleNodeConstants.CHILDREN].length) {
// Generate the code for the children of layer[arg]
var name = this.getVarName(utils.abbr(arg)),
layers;
this.logger.debug(`Adding layer arg for ${arg} (${layer.name})`);
try {
layers = this.genRawArchCode(layer[arg][Constants.CHILDREN], name);
layers = this.genRawArchCode(layer[arg][SimpleNodeConstants.CHILDREN], name);
} catch (e) {
this.logger.error(`Layer arg creation failed: ${e}`);
return null;
@@ -244,7 +292,7 @@ define([
GenerateArchitecture.prototype.createArgString = function (layer) {
var setters = this.LayerDict[layer.name].setters,
setterNames = Object.keys(this.LayerDict[layer.name].setters),
base = layer[Constants.BASE],
base = layer[SimpleNodeConstants.BASE],
desc,
fn,
layerCode,
+119 -17
Ver Arquivo
@@ -3,10 +3,12 @@
define([
'deepforge/layer-args',
'common/util/assert',
'deepforge/Constants',
'deepforge/lua'
], function(
createLayerDict,
assert,
Constants,
lua
) {
'use strict';
@@ -93,6 +95,7 @@ define([
connsFrom[id] = [];
}
connsFrom[id].push(conn, dst);
return conn;
};
// nn drawing library
@@ -194,56 +197,131 @@ define([
return self;
};
// Each container will have `inputs` and `outputs`
Layer.prototype._getAllNodes = function() {
return [this._node()];
};
var Container = function() {
Layer.apply(this, arguments);
this._nestedIndex = 0;
};
Container.prototype = Object.create(Layer.prototype);
Container.prototype.add = function(self, tlayer) {
var layer = tlayer.get('_node'),
container = this._node(),
children,
arch;
// Add a nested 'Architecture' node
arch = core.createNode({
parent: container,
base: META.Architecture
});
// Add this node to the 'addLayers' set
core.addMember(container, Constants.CONTAINED_LAYER_SET, arch);
// Assign it an appropriate 'index' value
core.setMemberRegistry(
container,
Constants.CONTAINED_LAYER_SET,
core.getPath(arch),
Constants.CONTAINED_LAYER_INDEX,
this._nestedIndex++
);
// Move the added node(s)/conns to this architecture node
children = layer._getAllNodes();
for (var i = children.length; i--;) {
core.moveNode(children[i], arch);
}
layer._parent = arch;
return self;
};
// Implicit Containers are sequential and concat containers;
// these containers are visually implied in deepforge (although
// they are explicitly defined in torch)
var ImplicitContainer = function() {
// inputs and outputs are webgme nodes
this._inputs = [];
this._outputs = [];
this._children = [];
this._connections = [];
};
Container.prototype.add = function() {
// Implicit containers will have to record their 'children'.
// When an implicit container is added to an actual container,
// the container will set it's '_parent' value. If any additional
// layers are added to the implicit container after, they will
// need to be moved to the parent of the implicit container
ImplicitContainer.prototype.add = function() {
logger.error('Add is not overridden!');
};
var Sequential = function(/*attrs, args*/) {
Container.call(this);
ImplicitContainer.prototype._getAllNodes = function() {
var nodes = this._children.map(layer => layer._getAllNodes())
.reduce((l1, l2) => l1.concat(l2), []);
return this._connections.concat(nodes);
};
Sequential.prototype = new Container();
var Sequential = function(/*attrs, args*/) {
ImplicitContainer.call(this);
};
Sequential.prototype = new ImplicitContainer();
Sequential.prototype.add = function(self, tlayer) {
var layer = tlayer.get('_node'),
nodes = layer._inputs;
nodes = layer._inputs,
connections = [];
// If this._inputs is empty, add the layer to the inputs list
if (this._inputs.length === 0) { // first node
this._inputs = this._inputs.concat(nodes);
} else {
// connect all inputs of the added node to the current outputs
// add the connection to the list of allNodes
this._outputs.forEach(src =>
nodes.forEach(dst => connect(src, dst))
nodes.forEach(dst => connections.push(connect(src, dst)))
);
}
this._outputs = layer._outputs;
this._children.push(layer);
this._connections = this._connections.concat(connections);
// If _parent is set, move the nodes and connection to the _parent node
if (this._parent) {
nodes = layer._getAllNodes().concat(connections);
for (var i = nodes.length; i--;) {
core.moveNode(nodes[i], this._parent);
}
}
return self;
};
var Concat = function(attrs, args) {
Container.call(this);
ImplicitContainer.call(this);
// Create a concat node and add it to this._outputs
var concat = new Layer('Concat', attrs, args);
this._outputs.push(concat._node());
this._children.push(concat);
};
Concat.prototype = new Container();
Concat.prototype = new ImplicitContainer();
Concat.prototype.add = function(self, tlayer) {
// Connect the tlayer outputs to this._outputs
var layer = tlayer.get('_node'),
concatLayer = this._outputs[0];
concatLayer = this._outputs[0],
connections = [],
nodes;
layer._outputs.forEach(output => connect(output, concatLayer));
layer._outputs.forEach(output =>
connections.push(connect(output, concatLayer)));
// Connect the incomingly connected node to tlayer
// TODO: This might not work if adding layers after this container is
@@ -251,14 +329,23 @@ define([
// Add the layer's inputs to the inputs
this._inputs = this._inputs.concat(layer._inputs);
this._children.push(layer);
this._connections = this._connections.concat(connections);
if (this._parent) {
nodes = layer._getAllNodes().concat(connections);
for (var i = nodes.length; i--;) {
core.moveNode(nodes[i], this._parent);
}
}
return self;
};
// Special layers (with special functions - like 'add')
var LAYERS = {
Concat: Concat,
Sequential: Sequential
};
var CONTAINERS,
LAYERS = {
Concat: Concat,
Sequential: Sequential
};
var getValue = function(txt) {
if (txt === 'true') {
@@ -311,6 +398,9 @@ define([
if (LAYERS[type]) {
node = new LAYERS[type](args, attrs);
} else if (CONTAINERS[type]) {
node = new Container(type, args, attrs);
res.set('add', node.add.bind(node)); // add the 'add' method
} else { // Call generic Layer with type name
node = new Layer(type, args, attrs);
}
@@ -352,11 +442,23 @@ define([
return;
}
// TODO: Create the nn object
// Mocking the nn layers (as defined in the metamodel)
var nn = lua.newContext()._G,
names = Object.keys(LayerDict);
names = Object.keys(LayerDict),
base,
baseName;
// For each layer, check the name of the base type. If it is 'Container',
// then it should be added to the CONTAINERS dictionary. This will change how
// it is handled in 'CreateLayer'
CONTAINERS = {};
for (var i = names.length; i--;) {
base = core.getBase(META[names[i]]);
baseName = core.getAttribute(base, 'name');
if (baseName === 'Container') {
CONTAINERS[names[i]] = true;
}
nn.set(names[i], CreateLayer.bind(null, names[i]));
}
@@ -124,6 +124,10 @@ define([
this.logger.info(`Updating ${seedName} seed`);
job.on('error', _err => {
err = _err;
if (err.code === 'ENOENT') {
return deferred.reject('"webgme" command not found. Is webgme-cli installed on the server?');
}
return deferred.reject(err);
});
job.on('exit', code => {
+22 -8
Ver Arquivo
@@ -44,13 +44,17 @@ function initialize(middlewareOpts) {
router.get('/:project/:branch/:job', function (req, res/*, next*/) {
// Retrieve the job logs for the given job
logManager.getLog(req.params).then(log => {
res.set('Content-Type', 'text/plain');
res.send(log);
});
logger.info(`Requested logs for ${req.params.job} in ${req.params.project}`);
logManager.getLog(req.params)
.then(log => {
res.set('Content-Type', 'text/plain');
res.send(log);
})
.catch(err => logger.error(`Log retrieval failed: ${err}`));
});
router.get('/metadata/:project/:branch/:job', function (req, res/*, next*/) {
logger.info(`Requested metadata for ${req.params.job} in ${req.params.project}`);
return mongo.findOne(req.params)
.then(info => {
var lineCount = info ? info.lineCount : -1;
@@ -58,7 +62,8 @@ function initialize(middlewareOpts) {
return res.json({
lineCount: lineCount
});
});
})
.catch(err => logger.error(`Metadata retrieval failed: ${err}`));
});
router.patch('/:project/:branch/:job', function (req, res/*, next*/) {
@@ -86,16 +91,25 @@ function initialize(middlewareOpts) {
});
router.delete('/:project/:branch/:job', function (req, res/*, next*/) {
logger.info(`Request to delete logs for ${req.params.job} in ${req.params.project}`);
logManager.delete(req.params)
.then(() => mongo.findOneAndDelete(req.params))
.then(() => res.status(204).send('delete successful'));
.then(() => {
logger.info('Job log deletion successful!');
res.status(204).send('delete successful');
})
.catch(err => logger.error(`Job log deletion failed: ${err}`));
});
router.post('/migrate/:project/:srcBranch/:dstBranch', function (req, res/*, next*/) {
var jobs = req.body.jobs;
logger.info(`Migrating logs from ${req.params.srcBranch} to ${req.params.dstBranch} in ${req.params.project}`);
logManager.migrate(req.params, jobs)
.then(() => res.send('migration successful'))
.fail(err => logger.error(err));
.then(() => {
logger.info('Log migration successful!');
res.send('migration successful');
})
.fail(err => logger.error(`migration failed: ${err}`));
});
logger.debug('ready');
Arquivo binário não exibido.
Arquivo binário não exibido.
Arquivo binário não exibido.
+1 -1
Ver Arquivo
@@ -1 +1 @@
0.4.0
1.0.3
Arquivo binário não exibido.
+1 -1
Ver Arquivo
@@ -1 +1 @@
0.4.0
0.4.1
Arquivo binário não exibido.
@@ -21,10 +21,11 @@ define([
var ArchEditorControl,
DEFAULT_CONFIG = {
DefaultColor: '#ffb74d',
DefaultColor: '#80cbc4',
LayerColors: {
Containers: '#ffb74d',
Convolution: '#2196f3',
Container: '#ffb74d',
NestedContainer: '#ffe0b2',
Convolution: '#42a5f5',
Simple: '#ff9100',
Transfer: '#80deea',
Misc: '#ce93d8'
@@ -46,6 +47,8 @@ define([
};
ArchEditorControl.prototype.selectedObjectChanged = function(id) {
this.nestedLevel = typeof id === 'string' ?
Math.floor(id.split('/').length/2) % 2 : 0;
ThumbnailControl.prototype.selectedObjectChanged.call(this, id);
DeepForge.last.Architecture = id;
@@ -97,11 +100,32 @@ define([
desc.layerType = layerType.getAttribute(nodePropertyNames.Attributes.name);
color = this._config.LayerColors[desc.layerType];
if (desc.layerType === 'Container' && this.nestedLevel) {
color = this._config.LayerColors.NestedContainer;
}
if (!color) {
this._logger.warn(`No color found for ${desc.layerType}`);
color = this._config.DefaultColor;
}
desc.color = color;
if (desc.layerType === 'Container') {
desc.containedLayers = node.getMemberIds(Constants.CONTAINED_LAYER_SET)
.map(layerId => {
var index = node.getMemberRegistry(
Constants.CONTAINED_LAYER_SET,
layerId,
Constants.CONTAINED_LAYER_INDEX
);
return [layerId, index];
})
.sort((a, b) => a[1] < b[1] ? -1 : 1)
.map(tuple => tuple[0]);
// Set the decorator to ContainerLayerDecorator
desc.Decorator = this._client.decoratorManager
.getDecoratorForWidget('ContainerLayerDecorator', 'EasyDAG');
}
}
}
}
@@ -15,7 +15,7 @@ define([
'use strict';
var NO_CODE_MESSAGE = '-- <%= name %> is not an editable layer!',
var NO_CODE_MESSAGE = '<%= name %> is not an editable layer!',
LayerEditorControl;
LayerEditorControl = function (options) {
@@ -45,10 +45,10 @@ define([
// Retrieve the template from the mixin
template = node.getMixinPaths()
.map(id => this._client.getNode(id).getAttribute('code'))
.find(code => !!code) || NO_CODE_MESSAGE;
.find(code => !!code) || this.comment(NO_CODE_MESSAGE);
}
} else {
template = NO_CODE_MESSAGE;
template = this.comment(NO_CODE_MESSAGE);
}
if (template) {
@@ -31,13 +31,16 @@ define([
'Transfer',
'Convolution',
'RNN',
'Containers',
'Container',
'Misc'
];
ArchEditorWidget = function (logger, container) {
ThumbnailWidget.call(this, logger, container);
this.$el.addClass(WIDGET_CLASS);
ArchEditorWidget = function () {
var container = arguments[1];
if (container) {
container.addClass(WIDGET_CLASS);
}
ThumbnailWidget.apply(this, arguments);
this._emptyMsg = 'Click to add a new layer';
};
@@ -46,16 +49,29 @@ define([
ArchEditorWidget.prototype.ItemClass = Layer;
ArchEditorWidget.prototype.SelectionManager = SelectionManager;
ArchEditorWidget.prototype.getComponentId = function() {
return 'ArchEditor';
};
ArchEditorWidget.prototype.setupItemCallbacks = function() {
var widget = this;
ThumbnailWidget.prototype.setupItemCallbacks.apply(this, arguments);
// Add the hover button functions
this.ItemClass.prototype.showHoverButtons = function() {
var layer = this;
widget.showHoverButtons(layer);
this._widget.showHoverButtons(layer);
};
this.ItemClass.prototype.hideHoverButtons = function() {
this._widget.hideHoverButtons();
};
this.ItemClass.prototype.isHoverAllowed = function() {
return !this._widget.isConnecting();
};
this.ItemClass.prototype.promptInitialLayer = function() {
var nodes = this._widget.getValidInitialNodes();
return this._widget.promptLayer(nodes)
.then(selected => selected.node.id);
};
this.ItemClass.prototype.hideHoverButtons = this.hideHoverButtons.bind(this);
this.ItemClass.prototype.isHoverAllowed = () => !this.isConnecting();
};
ArchEditorWidget.prototype.showHoverButtons = function(layer) {
@@ -186,5 +202,20 @@ define([
};
};
ArchEditorWidget.prototype.updateNode = function(desc) {
var item = this.items[desc.id];
item.update(desc);
this.refreshUI();
};
ArchEditorWidget.prototype.expandAllNodes = function(reverse) {
var itemIds = Object.keys(this.items),
method = reverse ? 'condenseAll' : 'expandAll';
for (var i = itemIds.length; i--;) {
this.items[itemIds[i]][method]();
}
};
return ArchEditorWidget;
});
+11
Ver Arquivo
@@ -25,6 +25,7 @@ define([
node: desc,
parentEl: this.$el
});
this.decorator.promptLayer = this.promptInitialLayer.bind(this);
this.width = this.decorator.width;
this.height = this.decorator.height;
@@ -59,5 +60,15 @@ define([
}
};
Layer.prototype.expandAll = function() {
var method = this.decorator.expandAll || this.decorator.expand;
method.call(this.decorator);
};
Layer.prototype.condenseAll = function() {
var method = this.decorator.condenseAll || this.decorator.condense;
method.call(this.decorator);
};
return Layer;
});
@@ -19,9 +19,7 @@ define([
_.extend(ClassCodeEditorWidget.prototype, TextEditorWidget.prototype);
ClassCodeEditorWidget.prototype.getHeader = function(desc) {
return [
`-- The class definition for ${desc.name}`
].join('\n');
return this.comment(`The class definition for ${desc.name}`);
};
ClassCodeEditorWidget.prototype.updateNode = function() {
@@ -26,13 +26,13 @@ define([
DeserializeEditorWidget.prototype.getHeader = function(desc) {
this._name = desc.name;
return [
`-- The deserialization function for ${desc.name}`,
'-- Globals:',
'-- `path` - target filename to load',
'--',
`-- return the loaded ${desc.name}`
].join('\n');
return this.comment([
`The deserialization function for ${desc.name}`,
'Globals:',
' `path` - target filename to load',
'',
`return the loaded ${desc.name}`
].join('\n'));
};
DeserializeEditorWidget.prototype.getNameRegex = function() {
@@ -17,9 +17,11 @@ define([
) {
'use strict';
var ExecutionViewWidget;
var ExecutionViewWidget,
WIDGET_CLASS = 'execution-view';
ExecutionViewWidget = function (logger, container) {
container.addClass(WIDGET_CLASS);
EasyDAGWidget.call(this, logger, container);
this.isSnapshot = true;
this.originName = null;
@@ -30,6 +32,10 @@ define([
ExecutionViewWidget.prototype.SelectionManager = SelectionManager;
ExecutionViewWidget.prototype.getComponentId = function() {
return 'ExecutionView';
};
ExecutionViewWidget.prototype.setExecutionNode = function(execNode) {
this.isSnapshot = execNode.isSnapshot;
this.originTime = execNode.createdAt;
@@ -32,24 +32,24 @@ define([
OperationCodeEditorWidget.prototype.getHeader = function (desc) {
// Add comment about the inputs, attributes and references
var inputs = desc.inputs.map(pair => `-- ${pair[0]} (${pair[1]})`).join('\n'),
refs = desc.references.map(name => `-- ${name}`).join('\n'),
var inputs = desc.inputs.map(pair => `${pair[0]} (${pair[1]})`).join('\n'),
refs = desc.references.map(name => `${name}`).join('\n'),
header = [
`-- Editing "${desc.name}" Implementation`
`Editing "${desc.name}" Implementation`
];
if (inputs.length) {
header.push('--');
header.push('-- Defined variables:');
header.push('');
header.push('Defined variables:');
header.push(inputs);
}
if (refs) {
header.push(refs);
}
header.push('--');
header.push('-- The following will be executed when the operation is run:');
header.push('');
header.push('The following will be executed when the operation is run:');
return header.join('\n');
return this.comment(header.join('\n'));
};
OperationCodeEditorWidget.prototype.canAddReturnTmpl = function (desc) {
@@ -25,8 +25,8 @@ define([
NEW_PRIM_ID = '__NEW_PRIM__';
OperationInterfaceEditorWidget = function (logger, container) {
container.addClass(WIDGET_CLASS);
EasyDAG.call(this, logger, container);
this.$el.addClass(WIDGET_CLASS);
};
_.extend(OperationInterfaceEditorWidget.prototype, EasyDAG.prototype);
@@ -1,10 +1,3 @@
/**
* This file is for any css that you may want for this visualizer.
*
* Ideally, you would use the scss file also provided in this directory
* and then generate this file automatically from that. However, you can
* simply write css if you prefer
*/
.operation-interface-editor {
outline: none; }
height: 100%;
}
@@ -38,9 +38,9 @@ define([
};
PipelineEditorWidget = function (logger, container, execCntr) {
container.addClass(WIDGET_CLASS);
ThumbnailWidget.call(this, logger, container);
this._emptyMsg = 'Click to add an operation';
this.$el.addClass(WIDGET_CLASS);
this.portIdToNode = {};
this.PORT_STATE = STATE.DEFAULT;
this.srcPortToConnectArgs = null;
@@ -60,6 +60,10 @@ define([
PipelineEditorWidget.prototype.onCreateInitialNode =
PipelineControl.prototype.onCreateInitialNode;
PipelineEditorWidget.prototype.getComponentId = function() {
return 'PipelineEditor';
};
PipelineEditorWidget.prototype.setupItemCallbacks = function() {
ThumbnailWidget.prototype.setupItemCallbacks.call(this);
this.ItemClass.prototype.connectPort =
@@ -199,7 +203,11 @@ define([
this.PORT_STATE = STATE.CONNECTING;
};
PipelineEditorWidget.prototype.onDeselect =
PipelineEditorWidget.prototype.onDeselect = function() {
this.resetPortState();
return ThumbnailWidget.prototype.onDeselect.apply(this, arguments);
};
PipelineEditorWidget.prototype.resetPortState = function() {
// Reset connecting state
this._itemsShowingPorts.forEach(item => item.hidePorts());
@@ -41,11 +41,5 @@ define([
}
};
SelectionManager.prototype.deselect = function() {
EasyDAGSelectionManager.prototype.deselect.call(this);
// Update the widget's 'port connecting' state
this._widget.onDeselect();
};
return SelectionManager;
});
@@ -23,12 +23,12 @@ define([
SerializeEditorWidget.prototype.getHeader = function(desc) {
this._name = desc.name;
return [
`-- The serialization function for ${desc.name}`,
'-- Globals:',
'-- `path` - target filename',
`-- \`data\` - the ${desc.name} to store`
].join('\n');
return this.comment([
`The serialization function for ${desc.name}`,
'Globals:',
' `path` - target filename',
` \`data\` - the ${desc.name} to store`
].join('\n'));
};
SerializeEditorWidget.prototype.getNameRegex = function () {
@@ -14,11 +14,16 @@ define([
'use strict';
var TextEditorWidget,
WIDGET_CLASS = 'text-editor';
WIDGET_CLASS = 'text-editor',
LINE_COMMENT = {
python: '#',
lua: '--'
};
TextEditorWidget = function (logger, container) {
this._logger = logger.fork('Widget');
this.language = this.language || 'python';
this._el = container;
this._el.css({height: '100%'});
this.$editor = $('<div/>');
@@ -74,8 +79,8 @@ define([
TextEditorWidget.prototype.getSessionOptions = function () {
return {
mode: 'ace/mode/lua',
tabSize: 3,
mode: 'ace/mode/' + this.language,
tabSize: 4,
useSoftTabs: true
};
};
@@ -90,8 +95,16 @@ define([
};
// Adding/Removing/Updating items
TextEditorWidget.prototype.comment = function (text) {
var prefix = LINE_COMMENT[this.language] + ' ';
return text.replace(
new RegExp('^(' + LINE_COMMENT[this.language] + ')?','mg'),
prefix
);
};
TextEditorWidget.prototype.getHeader = function (desc) {
return `-- Editing "${desc.name}"`;
return this.comment(`Editing "${desc.name}"`);
};
TextEditorWidget.prototype.addNode = function (desc) {
@@ -123,6 +123,7 @@ describe('ExecutePipeline', function () {
return manager.initializePlugin(pluginName)
.then(plugin_ => {
plugin = plugin_;
plugin.startExecHeartBeat = () => {};
return manager.configurePlugin(plugin, {}, context);
})
.then(() => node = plugin.activeNode)
@@ -89,6 +89,7 @@ describe('GenerateArchitecture', function () {
//['/o', 'basic.lua'],
//['/8', 'basic-transfers.lua'],
//['/M', 'concat-parallel.lua'],
['/Q', 'basiccontainer.lua'],
['/4', 'requiredOmitted.lua'],
['/e', 'googlenet.lua'],
['/X', 'overfeat.lua']
+16
Ver Arquivo
@@ -0,0 +1,16 @@
require 'nn'
require 'rnn'
local P0 = nn.Sequential()
P0:add(nn.View(2,5,10):setNumInputDims(20))
local P1 = nn.Sequential()
P1:add(nn.Linear(50, 200))
P1:add(nn.ReLU())
P1:add(nn.Linear(100, 210))
local net = nn.Sequential()
net:add(nn.Linear(100, 200))
net:add(nn.Parallel(100, 200):add(P0):add(P1))
net:add(nn.Sqrt(3))
return net
+213
Ver Arquivo
@@ -0,0 +1,213 @@
--
-- Copyright (c) 2016, Facebook, Inc.
-- All rights reserved.
--
-- This source code is licensed under the BSD-style license found in the
-- LICENSE file in the root directory of this source tree. An additional grant
-- of patent rights can be found in the PATENTS file in the same directory.
--
-- The ResNet model definition
--
local nn = require 'nn'
require 'cunn'
local Convolution = nn.SpatialConvolution
local Avg = nn.SpatialAveragePooling
local ReLU = nn.ReLU
local Max = nn.SpatialMaxPooling
local SBatchNorm = nn.SpatialBatchNormalization
local function createModel(opt)
local depth = opt.depth
local shortcutType = opt.shortcutType or 'B'
local iChannels
-- The shortcut layer is either identity or 1x1 convolution
local function shortcut(nInputPlane, nOutputPlane, stride)
local useConv = shortcutType == 'C' or
(shortcutType == 'B' and nInputPlane ~= nOutputPlane)
if useConv then
-- 1x1 convolution
return nn.Sequential()
:add(Convolution(nInputPlane, nOutputPlane, 1, 1, stride, stride))
:add(SBatchNorm(nOutputPlane))
elseif nInputPlane ~= nOutputPlane then
-- Strided, zero-padded identity shortcut
return nn.Sequential()
:add(nn.SpatialAveragePooling(1, 1, stride, stride))
:add(nn.Concat(2)
:add(nn.Identity())
:add(nn.MulConstant(0)))
else
return nn.Identity()
end
end
-- The basic residual layer block for 18 and 34 layer network, and the
-- CIFAR networks
local function basicblock(n, stride)
local nInputPlane = iChannels
iChannels = n
local s = nn.Sequential()
s:add(Convolution(nInputPlane,n,3,3,stride,stride,1,1))
s:add(SBatchNorm(n))
s:add(ReLU(true))
s:add(Convolution(n,n,3,3,1,1,1,1))
s:add(SBatchNorm(n))
return nn.Sequential()
:add(nn.ConcatTable()
:add(s)
:add(shortcut(nInputPlane, n, stride)))
:add(nn.CAddTable(true))
:add(ReLU(true))
end
-- The bottleneck residual layer for 50, 101, and 152 layer networks
local function bottleneck(n, stride)
local nInputPlane = iChannels
iChannels = n * 4
local s = nn.Sequential()
s:add(Convolution(nInputPlane,n,1,1,1,1,0,0))
s:add(SBatchNorm(n))
s:add(ReLU(true))
s:add(Convolution(n,n,3,3,stride,stride,1,1))
s:add(SBatchNorm(n))
s:add(ReLU(true))
s:add(Convolution(n,n*4,1,1,1,1,0,0))
s:add(SBatchNorm(n * 4))
return nn.Sequential()
:add(nn.ConcatTable()
:add(s)
:add(shortcut(nInputPlane, n * 4, stride)))
:add(nn.CAddTable(true))
:add(ReLU(true))
end
-- Creates count residual blocks with specified number of features
local function layer(block, features, count, stride)
local s = nn.Sequential()
for i=1,count do
s:add(block(features, i == 1 and stride or 1))
end
return s
end
local model = nn.Sequential()
if opt.dataset == 'imagenet' then
-- Configurations for ResNet:
-- num. residual blocks, num features, residual block function
local cfg = {
[18] = {{2, 2, 2, 2}, 512, basicblock},
[34] = {{3, 4, 6, 3}, 512, basicblock},
[50] = {{3, 4, 6, 3}, 2048, bottleneck},
[101] = {{3, 4, 23, 3}, 2048, bottleneck},
[152] = {{3, 8, 36, 3}, 2048, bottleneck},
}
assert(cfg[depth], 'Invalid depth: ' .. tostring(depth))
local def, nFeatures, block = table.unpack(cfg[depth])
iChannels = 64
print(' | ResNet-' .. depth .. ' ImageNet')
-- The ResNet ImageNet model
model:add(Convolution(3,64,7,7,2,2,3,3))
model:add(SBatchNorm(64))
model:add(ReLU(true))
model:add(Max(3,3,2,2,1,1))
model:add(layer(block, 64, def[1]))
model:add(layer(block, 128, def[2], 2))
model:add(layer(block, 256, def[3], 2))
model:add(layer(block, 512, def[4], 2))
model:add(Avg(7, 7, 1, 1))
model:add(nn.View(nFeatures):setNumInputDims(3))
model:add(nn.Linear(nFeatures, 1000))
elseif opt.dataset == 'cifar10' then
-- Model type specifies number of layers for CIFAR-10 model
assert((depth - 2) % 6 == 0, 'depth should be one of 20, 32, 44, 56, 110, 1202')
local n = (depth - 2) / 6
iChannels = 16
print(' | ResNet-' .. depth .. ' CIFAR-10')
-- The ResNet CIFAR-10 model
model:add(Convolution(3,16,3,3,1,1,1,1))
model:add(SBatchNorm(16))
model:add(ReLU(true))
model:add(layer(basicblock, 16, n))
model:add(layer(basicblock, 32, n, 2))
model:add(layer(basicblock, 64, n, 2))
model:add(Avg(8, 8, 1, 1))
model:add(nn.View(64):setNumInputDims(3))
model:add(nn.Linear(64, 10))
elseif opt.dataset == 'cifar100' then
-- Model type specifies number of layers for CIFAR-100 model
assert((depth - 2) % 6 == 0, 'depth should be one of 20, 32, 44, 56, 110, 1202')
local n = (depth - 2) / 6
iChannels = 16
print(' | ResNet-' .. depth .. ' CIFAR-100')
-- The ResNet CIFAR-100 model
model:add(Convolution(3,16,3,3,1,1,1,1))
model:add(SBatchNorm(16))
model:add(ReLU(true))
model:add(layer(basicblock, 16, n))
model:add(layer(basicblock, 32, n, 2))
model:add(layer(basicblock, 64, n, 2))
model:add(Avg(8, 8, 1, 1))
model:add(nn.View(64):setNumInputDims(3))
model:add(nn.Linear(64, 100))
else
error('invalid dataset: ' .. opt.dataset)
end
-- The following initialization code has been
-- commented out for importing into deepforge
--
--local function ConvInit(name)
--for k,v in pairs(model:findModules(name)) do
--local n = v.kW*v.kH*v.nOutputPlane
--v.weight:normal(0,math.sqrt(2/n))
--if nn.version >= 4000 then
--v.bias = nil
--v.gradBias = nil
--else
--v.bias:zero()
--end
--end
--end
--local function BNInit(name)
--for k,v in pairs(model:findModules(name)) do
--v.weight:fill(1)
--v.bias:zero()
--end
--end
--ConvInit('nn.SpatialConvolution')
--ConvInit('nn.SpatialConvolution')
--BNInit('fbnn.SpatialBatchNormalization')
--BNInit('nn.SpatialBatchNormalization')
--BNInit('nn.SpatialBatchNormalization')
----for k,v in pairs(model:findModules('nn.Linear')) do
--v.bias:zero()
--end
--model:cuda()
--if opt.nn == 'deterministic' then
--model:apply(function(m)
--if m.setMode then m:setMode(1,1,1) end
--end)
--end
--model:get(1).gradInput = nil
return model
end
return createModel({
dataset = 'imagenet',
depth = 18
});
@@ -0,0 +1,16 @@
require 'nn'
require 'rnn'
local P0 = nn.Sequential()
P0:add(nn.View(2,5,10):setNumInputDims(20))
local P1 = nn.Sequential()
P1:add(nn.Linear(50, 200))
P1:add(nn.ReLU())
P1:add(nn.Linear(100, 210))
local net = nn.Sequential()
net:add(nn.Linear(100, 200))
net:add(nn.Parallel(100, 200):add(P0):add(P1))
net:add(nn.Sqrt(3))
return net
+187 -199
Ver Arquivo
@@ -1,32 +1,67 @@
- type: ReLU
id: /V/1
- type: SpatialMaxPooling
id: /Z/0
next:
- /V/M
- /Z/E
attributes:
padW: ''
padH: ''
ctor_arg_order: 'kW,kH,dW,dH,padW,padH'
dH: 2
dW: 2
kH: 3
kW: 3
- type: ReLU
id: /Z/6
next:
- /Z/A
attributes:
p: ''
ctor_arg_order: p
- type: ReLU
id: /Z/9
next:
- /Z/0
attributes:
ctor_arg_order: p
p: true
- type: Linear
id: /V/29
next:
- /V/s
- type: LogSoftMax
id: /Z/L
next: []
attributes:
bias: ''
ctor_arg_order: 'inputSize,outputSize,bias'
outputSize: 10
inputSize: 4096
- type: Dropout
id: /V/3
ctor_arg_order: ''
- type: SpatialConvolution
id: /Z/l
next:
- /V/Q
- /Z/i
attributes:
v1: ''
inplace: ''
ctor_arg_order: 'p,v1,inplace'
p: 0.5
ctor_arg_order: 'nInputPlane,nOutputPlane,kW,kH,dW,dH,padW,padH'
padH: 2
padW: 2
dH: 4
dW: 4
kH: 11
kW: 11
nOutputPlane: 64
nInputPlane: 3
- type: SpatialBatchNormalization
id: /Z/i
next:
- /Z/H
attributes:
ctor_arg_order: 'nOutput,eps,momentum,affine'
eps: 0.001
nOutput: 64
- type: ReLU
id: /Z/H
next:
- /Z/J
attributes:
ctor_arg_order: p
p: true
- type: SpatialMaxPooling
id: /V/4
id: /Z/J
next:
- /V/o
- /Z/y
attributes:
padW: ''
padH: ''
@@ -36,9 +71,50 @@
kH: 3
kW: 3
- type: SpatialConvolution
id: /V/6
id: /Z/y
next:
- /V/Z
- /Z/j
attributes:
ctor_arg_order: 'nInputPlane,nOutputPlane,kW,kH,dW,dH,padW,padH'
padH: 2
padW: 2
dH: 1
dW: 1
kH: 5
kW: 5
nOutputPlane: 192
nInputPlane: 64
- type: SpatialBatchNormalization
id: /Z/j
next:
- /Z/T
attributes:
ctor_arg_order: 'nOutput,eps,momentum,affine'
eps: 0.001
nOutput: 192
- type: ReLU
id: /Z/T
next:
- /Z/V
attributes:
ctor_arg_order: p
p: true
- type: SpatialMaxPooling
id: /Z/V
next:
- /Z/z
attributes:
padW: ''
padH: ''
ctor_arg_order: 'kW,kH,dW,dH,padW,padH'
dH: 2
dW: 2
kH: 3
kW: 3
- type: SpatialConvolution
id: /Z/z
next:
- /Z/W
attributes:
ctor_arg_order: 'nInputPlane,nOutputPlane,kW,kH,dW,dH,padW,padH'
padH: 1
@@ -50,64 +126,24 @@
nOutputPlane: 384
nInputPlane: 192
- type: SpatialBatchNormalization
id: /V/8
id: /Z/W
next:
- /V/R
- /Z/u
attributes:
momentum: ''
affine: ''
ctor_arg_order: 'nOutput,eps,momentum,affine'
eps: 0.001
nOutput: 64
nOutput: 384
- type: ReLU
id: /V/F
id: /Z/u
next:
- /V/a
- /Z/g
attributes:
ctor_arg_order: p
p: true
- type: SpatialBatchNormalization
id: /V/G
next:
- /V/O
attributes:
momentum: ''
affine: ''
ctor_arg_order: 'nOutput,eps,momentum,affine'
eps: 0.001
nOutput: 192
- type: ReLU
id: /V/H
next:
- /V/N
attributes:
ctor_arg_order: p
p: true
- type: Dropout
id: /V/Im
next:
- /V/iP
attributes:
v1: ''
inplace: ''
ctor_arg_order: 'p,v1,inplace'
p: 0.5
- type: SpatialMaxPooling
id: /V/M
next:
- /V/xK
attributes:
padW: ''
padH: ''
ctor_arg_order: 'kW,kH,dW,dH,padW,padH'
dH: 2
dW: 2
kH: 3
kW: 3
- type: SpatialConvolution
id: /V/N
id: /Z/g
next:
- /V/g
- /Z/N
attributes:
ctor_arg_order: 'nInputPlane,nOutputPlane,kW,kH,dW,dH,padW,padH'
padH: 1
@@ -118,67 +154,25 @@
kW: 3
nOutputPlane: 256
nInputPlane: 384
- type: ReLU
id: /V/O
next:
- /V/k
attributes:
ctor_arg_order: p
p: true
- type: SpatialConvolution
id: /V/P
next:
- /V/8
attributes:
ctor_arg_order: 'nInputPlane,nOutputPlane,kW,kH,dW,dH,padW,padH'
padH: 2
padW: 2
dH: 4
dW: 4
kH: 11
kW: 11
nOutputPlane: 64
nInputPlane: 3
- type: Linear
id: /V/Q
next:
- /V/Qm
attributes:
bias: ''
ctor_arg_order: 'inputSize,outputSize,bias'
outputSize: 4096
inputSize: 4096
- type: BatchNormalization
id: /V/Qm
next:
- /V/t7
attributes:
momentum: ''
affine: ''
ctor_arg_order: 'nOutput,eps,momentum,affine'
eps: 0.001
nOutput: 4096
- type: ReLU
id: /V/R
next:
- /V/4
attributes:
ctor_arg_order: p
p: true
- type: SpatialBatchNormalization
id: /V/Z
id: /Z/N
next:
- /V/H
- /Z/I
attributes:
momentum: ''
affine: ''
ctor_arg_order: 'nOutput,eps,momentum,affine'
eps: 0.001
nOutput: 384
- type: SpatialConvolution
id: /V/a
nOutput: 256
- type: ReLU
id: /Z/I
next:
- /V/z
- /Z/ki
attributes:
ctor_arg_order: p
p: true
- type: SpatialConvolution
id: /Z/ki
next:
- /Z/x
attributes:
ctor_arg_order: 'nInputPlane,nOutputPlane,kW,kH,dW,dH,padW,padH'
padH: 1
@@ -189,94 +183,88 @@
kW: 3
nOutputPlane: 256
nInputPlane: 256
- type: BatchNormalization
id: /V/b
next:
- /V/t
attributes:
momentum: ''
affine: ''
ctor_arg_order: 'nOutput,eps,momentum,affine'
eps: 0.001
nOutput: 4096
- type: SpatialBatchNormalization
id: /V/g
id: /Z/x
next:
- /V/F
- /Z/9
attributes:
momentum: ''
affine: ''
ctor_arg_order: 'nOutput,eps,momentum,affine'
eps: 0.001
nOutput: 256
- type: Linear
id: /V/iP
- type: View
id: /Z/E
next:
- /V/b
- /Z/s
attributes:
ctor_arg_order: params
params: 9216
- type: Dropout
id: /Z/s
next:
- /Z/r
attributes:
v1: ''
inplace: ''
ctor_arg_order: 'p,v1,inplace,stochasticInference'
p: 0.5
- type: Linear
id: /Z/r
next:
- /Z/Rx
attributes:
bias: ''
ctor_arg_order: 'inputSize,outputSize,bias'
outputSize: 4096
inputSize: 9216
- type: SpatialMaxPooling
id: /V/k
- type: BatchNormalization
id: /Z/Rx
next:
- /V/6
- /Z/S
attributes:
padW: ''
padH: ''
ctor_arg_order: 'kW,kH,dW,dH,padW,padH'
dH: 2
dW: 2
kH: 3
kW: 3
- type: SpatialConvolution
id: /V/o
next:
- /V/G
attributes:
ctor_arg_order: 'nInputPlane,nOutputPlane,kW,kH,dW,dH,padW,padH'
padH: 2
padW: 2
dH: 1
dW: 1
kH: 5
kW: 5
nOutputPlane: 192
nInputPlane: 64
- type: LogSoftMax
id: /V/s
next: []
attributes:
ctor_arg_order: ''
- type: ReLU
id: /V/t
next:
- /V/3
attributes:
p: ''
ctor_arg_order: p
- type: ReLU
id: /V/t7
next:
- /V/29
attributes:
p: ''
ctor_arg_order: p
- type: View
id: /V/xK
next:
- /V/Im
attributes:
ctor_arg_order: params
params: 9216
- type: SpatialBatchNormalization
id: /V/z
next:
- /V/1
attributes:
momentum: ''
affine: ''
ctor_arg_order: 'nOutput,eps,momentum,affine'
momentum: 0.1
eps: 0.001
nOutput: 256
nOutput: 4096
- type: ReLU
id: /Z/S
next:
- /Z/D
attributes:
p: ''
ctor_arg_order: p
- type: Dropout
id: /Z/D
next:
- /Z/oM
attributes:
v1: ''
inplace: ''
ctor_arg_order: 'p,v1,inplace,stochasticInference'
p: 0.5
- type: Linear
id: /Z/oM
next:
- /Z/q
attributes:
bias: ''
ctor_arg_order: 'inputSize,outputSize,bias'
outputSize: 4096
inputSize: 4096
- type: BatchNormalization
id: /Z/q
next:
- /Z/6
attributes:
ctor_arg_order: 'nOutput,eps,momentum,affine'
momentum: 0.1
eps: 0.001
nOutput: 4096
- type: Linear
id: /Z/A
next:
- /Z/L
attributes:
bias: ''
ctor_arg_order: 'inputSize,outputSize,bias'
outputSize: 10
inputSize: 4096
+23
Ver Arquivo
@@ -0,0 +1,23 @@
- type: Sqrt
id: /Q/0
next: []
attributes:
ctor_arg_order: b
b: 3
- type: Linear
id: /Q/V
next:
- /Q/K
attributes:
bias: ''
ctor_arg_order: 'inputSize,outputSize,bias'
inputSize: 100
outputSize: 200
- type: Parallel
id: /Q/K
next:
- /Q/0
attributes:
ctor_arg_order: 'inputDimension,outputDimension'
inputDimension: 100
outputDimension: 200
+296 -320
Ver Arquivo
@@ -1,7 +1,55 @@
- type: SpatialConvolution
id: /J/1
id: /G/5
next:
- /J/G
- /G/x
attributes:
ctor_arg_order: 'nInputPlane,nOutputPlane,kW,kH,dW,dH,padW,padH'
padH: 0
padW: 0
dH: 1
dW: 1
kH: 1
kW: 1
nOutputPlane: 256
nInputPlane: 256
- type: ReLU
id: /G/8
next:
- /G/U
attributes:
ctor_arg_order: p
p: true
- type: SpatialBatchNormalization
id: /G/9
next:
- /G/T
attributes:
ctor_arg_order: 'nOutput,eps,momentum,affine'
eps: 0.001
nOutput: 1024
- type: SpatialConvolution
id: /G/56
next:
- /G/9
attributes:
ctor_arg_order: 'nInputPlane,nOutputPlane,kW,kH,dW,dH,padW,padH'
padH: 1
padW: 1
dH: 1
dW: 1
kH: 3
kW: 3
nOutputPlane: 1024
nInputPlane: 384
- type: LogSoftMax
id: /G/rn
next: []
attributes:
ctor_arg_order: ''
- type: SpatialConvolution
id: /G/y
next:
- /G/r
attributes:
ctor_arg_order: 'nInputPlane,nOutputPlane,kW,kH,dW,dH,padW,padH'
padH: 5
@@ -12,182 +60,25 @@
kW: 11
nOutputPlane: 96
nInputPlane: 3
- type: ReLU
id: /J/1n
next:
- /J/o
attributes:
ctor_arg_order: p
p: true
- type: SpatialConvolution
id: /J/4l
next:
- /J/xm
attributes:
ctor_arg_order: 'nInputPlane,nOutputPlane,kW,kH,dW,dH,padW,padH'
padH: 0
padW: 0
dH: 1
dW: 1
kH: 1
kW: 1
nOutputPlane: 1024
nInputPlane: 1024
- type: SpatialConvolution
id: /J/5
next:
- /J/St
attributes:
ctor_arg_order: 'nInputPlane,nOutputPlane,kW,kH,dW,dH,padW,padH'
padH: 0
padW: 0
dH: 1
dW: 1
kH: 1
kW: 1
nOutputPlane: 1024
nInputPlane: 1024
- type: SpatialBatchNormalization
id: /J/6
id: /G/r
next:
- /J/d
- /G/d
attributes:
momentum: ''
affine: ''
ctor_arg_order: 'nOutput,eps,momentum,affine'
eps: 0.001
nOutput: 96
- type: SpatialMaxPooling
id: /J/8
next:
- /J/g
attributes:
ctor_arg_order: 'kW,kH,dW,dH,padW,padH'
padH: 1
padW: 1
dH: 2
dW: 2
kH: 3
kW: 3
- type: Linear
id: /J/8r
next:
- /J/jq
attributes:
bias: ''
ctor_arg_order: 'inputSize,outputSize,bias'
outputSize: 1000
inputSize: 1024
- type: SpatialBatchNormalization
id: /J/95
next:
- /J/u
attributes:
momentum: ''
affine: ''
ctor_arg_order: 'nOutput,eps,momentum,affine'
eps: 0.001
nOutput: 256
- type: ReLU
id: /J/D
next:
- /J/p
attributes:
ctor_arg_order: p
p: true
- type: SpatialBatchNormalization
id: /J/E
next:
- /J/X
attributes:
momentum: ''
affine: ''
ctor_arg_order: 'nOutput,eps,momentum,affine'
eps: 0.001
nOutput: 96
- type: SpatialBatchNormalization
id: /J/F
next:
- /J/qt
attributes:
momentum: ''
affine: ''
ctor_arg_order: 'nOutput,eps,momentum,affine'
eps: 0.001
nOutput: 384
- type: SpatialBatchNormalization
id: /J/G
next:
- /J/s
attributes:
momentum: ''
affine: ''
ctor_arg_order: 'nOutput,eps,momentum,affine'
eps: 0.001
nOutput: 96
- type: ReLU
id: /J/KE
id: /G/d
next:
- /J/5
attributes:
ctor_arg_order: p
p: true
- type: ReLU
id: /J/N
next:
- /J/c
attributes:
ctor_arg_order: p
p: true
- type: ReLU
id: /J/O
next:
- /J/Z
- /G/L
attributes:
ctor_arg_order: p
p: true
- type: SpatialConvolution
id: /J/P
id: /G/L
next:
- /J/e
attributes:
ctor_arg_order: 'nInputPlane,nOutputPlane,kW,kH,dW,dH,padW,padH'
padH: 0
padW: 0
dH: 1
dW: 1
kH: 1
kW: 1
nOutputPlane: 256
nInputPlane: 256
- type: SpatialBatchNormalization
id: /J/St
next:
- /J/O
attributes:
momentum: ''
affine: ''
ctor_arg_order: 'nOutput,eps,momentum,affine'
eps: 0.001
nOutput: 1024
- type: SpatialConvolution
id: /J/T
next:
- /J/XE
attributes:
ctor_arg_order: 'nInputPlane,nOutputPlane,kW,kH,dW,dH,padW,padH'
padH: 1
padW: 1
dH: 1
dW: 1
kH: 3
kW: 3
nOutputPlane: 1024
nInputPlane: 384
- type: SpatialConvolution
id: /J/W
next:
- /J/E
- /G/t
attributes:
ctor_arg_order: 'nInputPlane,nOutputPlane,kW,kH,dW,dH,padW,padH'
padH: 0
@@ -198,62 +89,25 @@
kW: 1
nOutputPlane: 96
nInputPlane: 96
- type: ReLU
id: /J/X
- type: SpatialBatchNormalization
id: /G/t
next:
- /J/h
- /G/M
attributes:
ctor_arg_order: 'nOutput,eps,momentum,affine'
eps: 0.001
nOutput: 96
- type: ReLU
id: /G/M
next:
- /G/o
attributes:
ctor_arg_order: p
p: true
- type: SpatialBatchNormalization
id: /J/XE
next:
- /J/f
attributes:
momentum: ''
affine: ''
ctor_arg_order: 'nOutput,eps,momentum,affine'
eps: 0.001
nOutput: 1024
- type: SpatialBatchNormalization
id: /J/Xj
next:
- /J/1n
attributes:
momentum: ''
affine: ''
ctor_arg_order: 'nOutput,eps,momentum,affine'
eps: 0.001
nOutput: 384
- type: SpatialMaxPooling
id: /J/Y
next:
- /J/b
attributes:
ctor_arg_order: 'kW,kH,dW,dH,padW,padH'
padH: 1
padW: 1
dH: 2
dW: 2
kH: 3
kW: 3
- type: SpatialAveragePooling
id: /J/Z
next:
- /J/l
attributes:
padW: ''
padH: ''
count_include_pad: true
ctor_arg_order: 'kW,kH,dW,dH,padW,padH'
dH: 1
dW: 1
kH: 7
kW: 7
- type: SpatialConvolution
id: /J/a
id: /G/o
next:
- /J/Xj
- /G/O
attributes:
ctor_arg_order: 'nInputPlane,nOutputPlane,kW,kH,dW,dH,padW,padH'
padH: 0
@@ -262,12 +116,32 @@
dW: 1
kH: 1
kW: 1
nOutputPlane: 384
nInputPlane: 384
- type: SpatialConvolution
id: /J/b
nOutputPlane: 96
nInputPlane: 96
- type: SpatialBatchNormalization
id: /G/O
next:
- /J/q
- /G/8
attributes:
ctor_arg_order: 'nOutput,eps,momentum,affine'
eps: 0.001
nOutput: 96
- type: SpatialMaxPooling
id: /G/U
next:
- /G/P
attributes:
ctor_arg_order: 'kW,kH,dW,dH,padW,padH'
padH: 1
padW: 1
dH: 2
dW: 2
kH: 3
kW: 3
- type: SpatialConvolution
id: /G/P
next:
- /G/N
attributes:
ctor_arg_order: 'nInputPlane,nOutputPlane,kW,kH,dW,dH,padW,padH'
padH: 2
@@ -278,10 +152,40 @@
kW: 5
nOutputPlane: 256
nInputPlane: 96
- type: SpatialConvolution
id: /J/c
- type: SpatialBatchNormalization
id: /G/N
next:
- /J/95
- /G/Q
attributes:
ctor_arg_order: 'nOutput,eps,momentum,affine'
eps: 0.001
nOutput: 256
- type: ReLU
id: /G/Q
next:
- /G/5
attributes:
ctor_arg_order: p
p: true
- type: SpatialBatchNormalization
id: /G/x
next:
- /G/p
attributes:
ctor_arg_order: 'nOutput,eps,momentum,affine'
eps: 0.001
nOutput: 256
- type: ReLU
id: /G/p
next:
- /G/na
attributes:
ctor_arg_order: p
p: true
- type: SpatialConvolution
id: /G/na
next:
- /G/w
attributes:
ctor_arg_order: 'nInputPlane,nOutputPlane,kW,kH,dW,dH,padW,padH'
padH: 0
@@ -292,34 +196,37 @@
kW: 1
nOutputPlane: 256
nInputPlane: 256
- type: ReLU
id: /J/d
next:
- /J/Y
attributes:
ctor_arg_order: p
p: true
- type: SpatialBatchNormalization
id: /J/e
id: /G/w
next:
- /J/n
- /G/F
attributes:
momentum: ''
affine: ''
ctor_arg_order: 'nOutput,eps,momentum,affine'
eps: 0.001
nOutput: 256
- type: ReLU
id: /J/f
id: /G/F
next:
- /J/4l
- /G/E
attributes:
ctor_arg_order: p
p: true
- type: SpatialConvolution
id: /J/g
- type: SpatialMaxPooling
id: /G/E
next:
- /J/w
- /G/us
attributes:
ctor_arg_order: 'kW,kH,dW,dH,padW,padH'
padH: 1
padW: 1
dH: 2
dW: 2
kH: 3
kW: 3
- type: SpatialConvolution
id: /G/us
next:
- /G/D
attributes:
ctor_arg_order: 'nInputPlane,nOutputPlane,kW,kH,dW,dH,padW,padH'
padH: 1
@@ -330,56 +237,25 @@
kW: 3
nOutputPlane: 384
nInputPlane: 256
- type: SpatialConvolution
id: /J/h
- type: SpatialBatchNormalization
id: /G/D
next:
- /J/6
- /G/g
attributes:
ctor_arg_order: 'nInputPlane,nOutputPlane,kW,kH,dW,dH,padW,padH'
padH: 0
padW: 0
dH: 1
dW: 1
kH: 1
kW: 1
nOutputPlane: 96
nInputPlane: 96
- type: LogSoftMax
id: /J/jq
next: []
attributes:
ctor_arg_order: ''
- type: View
id: /J/l
next:
- /J/8r
attributes:
ctor_arg_order: params
params: -1
numInputDims: 3
ctor_arg_order: 'nOutput,eps,momentum,affine'
eps: 0.001
nOutput: 384
- type: ReLU
id: /J/n
id: /G/g
next:
- /J/8
- /G/9J
attributes:
ctor_arg_order: p
p: true
- type: SpatialMaxPooling
id: /J/o
next:
- /J/T
attributes:
ctor_arg_order: 'kW,kH,dW,dH,padW,padH'
padH: 1
padW: 1
dH: 2
dW: 2
kH: 3
kW: 3
- type: SpatialConvolution
id: /J/p
id: /G/9J
next:
- /J/F
- /G/1l
attributes:
ctor_arg_order: 'nInputPlane,nOutputPlane,kW,kH,dW,dH,padW,padH'
padH: 0
@@ -391,53 +267,153 @@
nOutputPlane: 384
nInputPlane: 384
- type: SpatialBatchNormalization
id: /J/q
id: /G/1l
next:
- /J/N
- /G/Jw
attributes:
momentum: ''
affine: ''
ctor_arg_order: 'nOutput,eps,momentum,affine'
eps: 0.001
nOutput: 256
- type: ReLU
id: /J/qt
next:
- /J/a
attributes:
ctor_arg_order: p
p: true
- type: ReLU
id: /J/s
next:
- /J/W
attributes:
ctor_arg_order: p
p: true
- type: ReLU
id: /J/u
next:
- /J/P
attributes:
ctor_arg_order: p
p: true
- type: SpatialBatchNormalization
id: /J/w
next:
- /J/D
attributes:
momentum: ''
affine: ''
ctor_arg_order: 'nOutput,eps,momentum,affine'
eps: 0.001
nOutput: 384
- type: SpatialBatchNormalization
id: /J/xm
- type: ReLU
id: /G/Jw
next:
- /J/KE
- /G/qA
attributes:
ctor_arg_order: p
p: true
- type: SpatialConvolution
id: /G/qA
next:
- /G/HW
attributes:
ctor_arg_order: 'nInputPlane,nOutputPlane,kW,kH,dW,dH,padW,padH'
padH: 0
padW: 0
dH: 1
dW: 1
kH: 1
kW: 1
nOutputPlane: 384
nInputPlane: 384
- type: SpatialBatchNormalization
id: /G/HW
next:
- /G/Ev
attributes:
ctor_arg_order: 'nOutput,eps,momentum,affine'
eps: 0.001
nOutput: 384
- type: ReLU
id: /G/Ev
next:
- /G/ky
attributes:
ctor_arg_order: p
p: true
- type: SpatialMaxPooling
id: /G/ky
next:
- /G/56
attributes:
ctor_arg_order: 'kW,kH,dW,dH,padW,padH'
padH: 1
padW: 1
dH: 2
dW: 2
kH: 3
kW: 3
- type: ReLU
id: /G/T
next:
- /G/zi
attributes:
ctor_arg_order: p
p: true
- type: SpatialConvolution
id: /G/zi
next:
- /G/J
attributes:
ctor_arg_order: 'nInputPlane,nOutputPlane,kW,kH,dW,dH,padW,padH'
padH: 0
padW: 0
dH: 1
dW: 1
kH: 1
kW: 1
nOutputPlane: 1024
nInputPlane: 1024
- type: SpatialBatchNormalization
id: /G/J
next:
- /G/Tq
attributes:
momentum: ''
affine: ''
ctor_arg_order: 'nOutput,eps,momentum,affine'
eps: 0.001
nOutput: 1024
- type: ReLU
id: /G/Tq
next:
- /G/jy
attributes:
ctor_arg_order: p
p: true
- type: SpatialConvolution
id: /G/jy
next:
- /G/3g
attributes:
ctor_arg_order: 'nInputPlane,nOutputPlane,kW,kH,dW,dH,padW,padH'
padH: 0
padW: 0
dH: 1
dW: 1
kH: 1
kW: 1
nOutputPlane: 1024
nInputPlane: 1024
- type: SpatialBatchNormalization
id: /G/3g
next:
- /G/cl
attributes:
ctor_arg_order: 'nOutput,eps,momentum,affine'
eps: 0.001
nOutput: 1024
- type: ReLU
id: /G/cl
next:
- /G/xs
attributes:
ctor_arg_order: p
p: true
- type: SpatialAveragePooling
id: /G/xs
next:
- /G/CK
attributes:
padW: ''
padH: ''
count_include_pad: true
ctor_arg_order: 'kW,kH,dW,dH,padW,padH'
dH: 1
dW: 1
kH: 7
kW: 7
- type: View
id: /G/CK
next:
- /G/b
attributes:
ctor_arg_order: params
params: -1
numInputDims: 3
- type: Linear
id: /G/b
next:
- /G/rn
attributes:
bias: ''
ctor_arg_order: 'inputSize,outputSize,bias'
outputSize: 1000
inputSize: 1024
+229
Ver Arquivo
@@ -0,0 +1,229 @@
- type: SpatialConvolution
id: /r/2
next:
- /r/C
attributes:
ctor_arg_order: 'nInputPlane,nOutputPlane,kW,kH,dW,dH,padW,padH'
padH: 3
padW: 3
dH: 2
dW: 2
kH: 7
kW: 7
nOutputPlane: 64
nInputPlane: 3
- type: ReLU
id: /r/3
next:
- /r/ry
attributes:
ctor_arg_order: p
p: true
- type: CAddTable
id: /r/4
next:
- /r/3
attributes:
ctor_arg_order: ip
ip: true
- type: ConcatTable
id: /r/6
next:
- /r/M
attributes:
ctor_arg_order: ''
- type: ReLU
id: /r/7
next:
- /r/6
attributes:
ctor_arg_order: p
p: true
- type: Linear
id: /r/Dp
next: []
attributes:
bias: ''
ctor_arg_order: 'inputSize,outputSize,bias'
outputSize: 1000
inputSize: 512
- type: SpatialBatchNormalization
id: /r/C
next:
- /r/S
attributes:
ctor_arg_order: 'nOutput,eps,momentum,affine'
nOutput: 64
- type: ReLU
id: /r/S
next:
- /r/P
attributes:
ctor_arg_order: p
p: true
- type: SpatialMaxPooling
id: /r/P
next:
- /r/k
attributes:
ctor_arg_order: 'kW,kH,dW,dH,padW,padH'
padH: 1
padW: 1
dH: 2
dW: 2
kH: 3
kW: 3
- type: ConcatTable
id: /r/k
next:
- /r/s
attributes:
ctor_arg_order: ''
- type: CAddTable
id: /r/s
next:
- /r/H
attributes:
ctor_arg_order: ip
ip: true
- type: ReLU
id: /r/H
next:
- /r/e
attributes:
ctor_arg_order: p
p: true
- type: ConcatTable
id: /r/e
next:
- /r/g
attributes:
ctor_arg_order: ''
- type: CAddTable
id: /r/g
next:
- /r/7
attributes:
ctor_arg_order: ip
ip: true
- type: CAddTable
id: /r/M
next:
- /r/Q
attributes:
ctor_arg_order: ip
ip: true
- type: ReLU
id: /r/Q
next:
- /r/N
attributes:
ctor_arg_order: p
p: true
- type: ConcatTable
id: /r/N
next:
- /r/Mf
attributes:
ctor_arg_order: ''
- type: CAddTable
id: /r/Mf
next:
- /r/a
attributes:
ctor_arg_order: ip
ip: true
- type: ReLU
id: /r/a
next:
- /r/ab
attributes:
ctor_arg_order: p
p: true
- type: ConcatTable
id: /r/ab
next:
- /r/CR
attributes:
ctor_arg_order: ''
- type: CAddTable
id: /r/CR
next:
- /r/i
attributes:
ctor_arg_order: ip
ip: true
- type: ReLU
id: /r/i
next:
- /r/H5
attributes:
ctor_arg_order: p
p: true
- type: ConcatTable
id: /r/H5
next:
- /r/4
attributes:
ctor_arg_order: ''
- type: ConcatTable
id: /r/ry
next:
- /r/t
attributes:
ctor_arg_order: ''
- type: CAddTable
id: /r/t
next:
- /r/9A
attributes:
ctor_arg_order: ip
ip: true
- type: ReLU
id: /r/9A
next:
- /r/Qu
attributes:
ctor_arg_order: p
p: true
- type: ConcatTable
id: /r/Qu
next:
- /r/q
attributes:
ctor_arg_order: ''
- type: CAddTable
id: /r/q
next:
- /r/o
attributes:
ctor_arg_order: ip
ip: true
- type: ReLU
id: /r/o
next:
- /r/G
attributes:
ctor_arg_order: p
p: true
- type: SpatialAveragePooling
id: /r/G
next:
- /r/b
attributes:
padW: ''
padH: ''
count_include_pad: true
ctor_arg_order: 'kW,kH,dW,dH,padW,padH'
dH: 1
dW: 1
kH: 7
kW: 7
- type: View
id: /r/b
next:
- /r/Dp
attributes:
ctor_arg_order: params
params: 512
numInputDims: 3
+287 -289
Ver Arquivo
@@ -1,302 +1,21 @@
- type: SpatialMaxPooling
id: /f/0
next:
- /f/y
attributes:
padW: ''
padH: ''
ctor_arg_order: 'kW,kH,dW,dH,padW,padH'
dH: 2
dW: 2
kH: 2
kW: 2
- type: View
id: /f/1V
next:
- /f/R
attributes:
ctor_arg_order: params
params: 25088
- type: Linear
id: /f/3
id: /K/5
next:
- /f/vo
attributes:
bias: ''
ctor_arg_order: 'inputSize,outputSize,bias'
outputSize: 1000
inputSize: 4096
- type: SpatialConvolution
id: /f/4
next:
- /f/ID
attributes:
ctor_arg_order: 'nInputPlane,nOutputPlane,kW,kH,dW,dH,padW,padH'
padH: 1
padW: 1
dH: 1
dW: 1
kH: 3
kW: 3
nOutputPlane: 512
nInputPlane: 512
- type: BatchNormalization
id: /f/4R
next:
- /f/V
attributes:
momentum: ''
affine: ''
ctor_arg_order: 'nOutput,eps,momentum,affine'
eps: 0.001
nOutput: 4096
- type: Threshold
id: /f/6
next:
- /f/J
attributes:
ip: ''
ctor_arg_order: 'th,v,ip'
v: 0.000001
th: 0
- type: SpatialConvolution
id: /f/C
next:
- /f/e
attributes:
ctor_arg_order: 'nInputPlane,nOutputPlane,kW,kH,dW,dH,padW,padH'
padH: 1
padW: 1
dH: 1
dW: 1
kH: 3
kW: 3
nOutputPlane: 512
nInputPlane: 256
- type: ReLU
id: /f/D
next:
- /f/X
attributes:
ctor_arg_order: p
p: true
- type: SpatialConvolution
id: /f/FN
next:
- /f/b
attributes:
ctor_arg_order: 'nInputPlane,nOutputPlane,kW,kH,dW,dH,padW,padH'
padH: 1
padW: 1
dH: 1
dW: 1
kH: 3
kW: 3
nOutputPlane: 512
nInputPlane: 512
- type: ReLU
id: /f/ID
next:
- /f/g
attributes:
ctor_arg_order: p
p: true
- type: BatchNormalization
id: /f/J
next:
- /f/eZ
attributes:
momentum: ''
affine: ''
ctor_arg_order: 'nOutput,eps,momentum,affine'
eps: 0.001
nOutput: 4096
- type: ReLU
id: /f/N
next:
- /f/0
attributes:
ctor_arg_order: p
p: true
- type: Linear
id: /f/R
next:
- /f/i
attributes:
bias: ''
ctor_arg_order: 'inputSize,outputSize,bias'
outputSize: 4096
inputSize: 25088
- type: SpatialMaxPooling
id: /f/U
next:
- /f/FN
attributes:
padW: ''
padH: ''
ctor_arg_order: 'kW,kH,dW,dH,padW,padH'
dH: 2
dW: 2
kH: 2
kW: 2
- type: Dropout
id: /f/V
next:
- /f/s
attributes:
v1: ''
inplace: ''
ctor_arg_order: 'p,v1,inplace'
p: 0.5
- type: SpatialConvolution
id: /f/W
next:
- /f/l
attributes:
ctor_arg_order: 'nInputPlane,nOutputPlane,kW,kH,dW,dH,padW,padH'
padH: 1
padW: 1
dH: 1
dW: 1
kH: 3
kW: 3
nOutputPlane: 512
nInputPlane: 512
- type: SpatialConvolution
id: /f/X
next:
- /f/j
attributes:
ctor_arg_order: 'nInputPlane,nOutputPlane,kW,kH,dW,dH,padW,padH'
padH: 1
padW: 1
dH: 1
dW: 1
kH: 3
kW: 3
nOutputPlane: 256
nInputPlane: 256
- type: ReLU
id: /f/Y
next:
- /f/q
attributes:
ctor_arg_order: p
p: true
- type: SpatialMaxPooling
id: /f/ZV
next:
- /f/C
attributes:
padW: ''
padH: ''
ctor_arg_order: 'kW,kH,dW,dH,padW,padH'
dH: 2
dW: 2
kH: 2
kW: 2
- type: ReLU
id: /f/b
next:
- /f/4
attributes:
ctor_arg_order: p
p: true
- type: ReLU
id: /f/e
next:
- /f/W
attributes:
ctor_arg_order: p
p: true
- type: Dropout
id: /f/eZ
next:
- /f/3
attributes:
v1: ''
inplace: ''
ctor_arg_order: 'p,v1,inplace'
p: 0.5
- type: SpatialMaxPooling
id: /f/g
next:
- /f/1V
attributes:
padW: ''
padH: ''
ctor_arg_order: 'kW,kH,dW,dH,padW,padH'
dH: 2
dW: 2
kH: 2
kW: 2
- type: Threshold
id: /f/i
next:
- /f/4R
attributes:
ip: ''
ctor_arg_order: 'th,v,ip'
v: 0.000001
th: 0
- type: ReLU
id: /f/j
next:
- /f/ZV
attributes:
ctor_arg_order: p
p: true
- type: ReLU
id: /f/l
next:
- /f/U
attributes:
ctor_arg_order: p
p: true
- type: SpatialConvolution
id: /f/n
next:
- /f/D
attributes:
ctor_arg_order: 'nInputPlane,nOutputPlane,kW,kH,dW,dH,padW,padH'
padH: 1
padW: 1
dH: 1
dW: 1
kH: 3
kW: 3
nOutputPlane: 256
nInputPlane: 128
- type: SpatialMaxPooling
id: /f/q
next:
- /f/n
attributes:
padW: ''
padH: ''
ctor_arg_order: 'kW,kH,dW,dH,padW,padH'
dH: 2
dW: 2
kH: 2
kW: 2
- type: Linear
id: /f/s
next:
- /f/6
- /K/r
attributes:
bias: ''
ctor_arg_order: 'inputSize,outputSize,bias'
outputSize: 4096
inputSize: 4096
- type: LogSoftMax
id: /f/vo
id: /K/3g
next: []
attributes:
ctor_arg_order: ''
- type: SpatialConvolution
id: /f/w
id: /K/z
next:
- /f/N
- /K/p
attributes:
ctor_arg_order: 'nInputPlane,nOutputPlane,kW,kH,dW,dH,padW,padH'
padH: 1
@@ -307,10 +26,29 @@
kW: 3
nOutputPlane: 64
nInputPlane: 3
- type: SpatialConvolution
id: /f/y
- type: ReLU
id: /K/p
next:
- /f/Y
- /K/G
attributes:
ctor_arg_order: p
p: true
- type: SpatialMaxPooling
id: /K/G
next:
- /K/O
attributes:
padW: ''
padH: ''
ctor_arg_order: 'kW,kH,dW,dH,padW,padH'
dH: 2
dW: 2
kH: 2
kW: 2
- type: SpatialConvolution
id: /K/O
next:
- /K/U
attributes:
ctor_arg_order: 'nInputPlane,nOutputPlane,kW,kH,dW,dH,padW,padH'
padH: 1
@@ -321,3 +59,263 @@
kW: 3
nOutputPlane: 128
nInputPlane: 64
- type: ReLU
id: /K/U
next:
- /K/B
attributes:
ctor_arg_order: p
p: true
- type: SpatialMaxPooling
id: /K/B
next:
- /K/c
attributes:
padW: ''
padH: ''
ctor_arg_order: 'kW,kH,dW,dH,padW,padH'
dH: 2
dW: 2
kH: 2
kW: 2
- type: SpatialConvolution
id: /K/c
next:
- /K/w
attributes:
ctor_arg_order: 'nInputPlane,nOutputPlane,kW,kH,dW,dH,padW,padH'
padH: 1
padW: 1
dH: 1
dW: 1
kH: 3
kW: 3
nOutputPlane: 256
nInputPlane: 128
- type: ReLU
id: /K/w
next:
- /K/P
attributes:
ctor_arg_order: p
p: true
- type: SpatialConvolution
id: /K/P
next:
- /K/K
attributes:
ctor_arg_order: 'nInputPlane,nOutputPlane,kW,kH,dW,dH,padW,padH'
padH: 1
padW: 1
dH: 1
dW: 1
kH: 3
kW: 3
nOutputPlane: 256
nInputPlane: 256
- type: ReLU
id: /K/K
next:
- /K/t
attributes:
ctor_arg_order: p
p: true
- type: SpatialMaxPooling
id: /K/t
next:
- /K/f
attributes:
padW: ''
padH: ''
ctor_arg_order: 'kW,kH,dW,dH,padW,padH'
dH: 2
dW: 2
kH: 2
kW: 2
- type: SpatialConvolution
id: /K/f
next:
- /K/I
attributes:
ctor_arg_order: 'nInputPlane,nOutputPlane,kW,kH,dW,dH,padW,padH'
padH: 1
padW: 1
dH: 1
dW: 1
kH: 3
kW: 3
nOutputPlane: 512
nInputPlane: 256
- type: ReLU
id: /K/I
next:
- /K/o
attributes:
ctor_arg_order: p
p: true
- type: SpatialConvolution
id: /K/o
next:
- /K/T
attributes:
ctor_arg_order: 'nInputPlane,nOutputPlane,kW,kH,dW,dH,padW,padH'
padH: 1
padW: 1
dH: 1
dW: 1
kH: 3
kW: 3
nOutputPlane: 512
nInputPlane: 512
- type: ReLU
id: /K/T
next:
- /K/J
attributes:
ctor_arg_order: p
p: true
- type: SpatialMaxPooling
id: /K/J
next:
- /K/X
attributes:
padW: ''
padH: ''
ctor_arg_order: 'kW,kH,dW,dH,padW,padH'
dH: 2
dW: 2
kH: 2
kW: 2
- type: SpatialConvolution
id: /K/X
next:
- /K/V
attributes:
ctor_arg_order: 'nInputPlane,nOutputPlane,kW,kH,dW,dH,padW,padH'
padH: 1
padW: 1
dH: 1
dW: 1
kH: 3
kW: 3
nOutputPlane: 512
nInputPlane: 512
- type: ReLU
id: /K/V
next:
- /K/g
attributes:
ctor_arg_order: p
p: true
- type: SpatialConvolution
id: /K/g
next:
- /K/W
attributes:
ctor_arg_order: 'nInputPlane,nOutputPlane,kW,kH,dW,dH,padW,padH'
padH: 1
padW: 1
dH: 1
dW: 1
kH: 3
kW: 3
nOutputPlane: 512
nInputPlane: 512
- type: ReLU
id: /K/W
next:
- /K/m
attributes:
ctor_arg_order: p
p: true
- type: SpatialMaxPooling
id: /K/m
next:
- /K/gg
attributes:
padW: ''
padH: ''
ctor_arg_order: 'kW,kH,dW,dH,padW,padH'
dH: 2
dW: 2
kH: 2
kW: 2
- type: View
id: /K/gg
next:
- /K/pB
attributes:
ctor_arg_order: params
params: 25088
- type: Linear
id: /K/pB
next:
- /K/Z
attributes:
bias: ''
ctor_arg_order: 'inputSize,outputSize,bias'
outputSize: 4096
inputSize: 25088
- type: Threshold
id: /K/Z
next:
- /K/S
attributes:
ip: ''
ctor_arg_order: 'th,v,ip'
v: 0.000001
th: 0
- type: BatchNormalization
id: /K/S
next:
- /K/W9
attributes:
ctor_arg_order: 'nOutput,eps,momentum,affine'
momentum: 0.1
eps: 0.001
nOutput: 4096
- type: Dropout
id: /K/W9
next:
- /K/5
attributes:
v1: ''
inplace: ''
ctor_arg_order: 'p,v1,inplace,stochasticInference'
p: 0.5
- type: Threshold
id: /K/r
next:
- /K/e
attributes:
ip: ''
ctor_arg_order: 'th,v,ip'
v: 0.000001
th: 0
- type: BatchNormalization
id: /K/e
next:
- /K/4q
attributes:
ctor_arg_order: 'nOutput,eps,momentum,affine'
momentum: 0.1
eps: 0.001
nOutput: 4096
- type: Dropout
id: /K/4q
next:
- /K/tp
attributes:
v1: ''
inplace: ''
ctor_arg_order: 'p,v1,inplace,stochasticInference'
p: 0.5
- type: Linear
id: /K/tp
next:
- /K/3g
attributes:
bias: ''
ctor_arg_order: 'inputSize,outputSize,bias'
outputSize: 1000
inputSize: 4096
+49 -140
Ver Arquivo
@@ -1,144 +1,53 @@
{
"RNN": [
"BiSequencer",
"BiSequencerLM",
"GRU",
"MaskZero",
"MaskZeroCriterion",
"Recurrence",
"Recurrent",
"RecurrentAttention",
"Recursor",
"Repeater",
"RepeaterCriterion",
"Sequencer",
"SequencerCriterion",
"TrimZero",
"Transfer": [
"PReLU",
"Softshrink",
"Softplus",
"LeakyReLU",
"Hardshrink",
"ELU",
"ReLU6",
"Hardtanh",
"RReLU",
"ReLU",
"Threshold"
],
"CopyGrad",
"FastLSTM",
"LSTM",
"LookupTableMaskZero",
"NormStabilizer",
"SAdd",
"SeqBRNN",
"SeqGRU",
"SeqLSTM",
"SeqLSTMP",
"SeqReverseSequence"
],
"Convolution": [
"TemporalConvolution",
"TemporalMaxPooling",
"TemporalSubSampling",
"LookupTable",
"SpatialConvolutionMM",
"SpatialConvolution",
"SpatialConvolutionMap",
"SpatialFullConvolutionMap",
"SpatialLPPooling",
"SpatialMaxPooling",
"SpatialAveragePooling",
"SpatialAdaptiveMaxPooling",
"SpatialSubSampling",
"SpatialUpSamplingNearest",
"SpatialZeroPadding",
"SpatialReflectionPadding",
"SpatialReplicationPadding",
"SpatialSubtractiveNormalization",
"SpatialCrossMapLRN",
"SpatialConvolutionLocal",
"SpatialDropout",
"SpatialDilatedConvolution",
"SpatialFractionalMaxPooling",
"SpatialDivisiveNormalization",
"SpatialContrastiveNormalization",
"SpatialBatchNormalization",
"SpatialFullConvolution",
"SpatialMaxUnpooling",
"VolumetricConvolution",
"VolumetricMaxPooling",
"VolumetricAveragePooling",
"VolumetricBatchNormalization",
"VolumetricDropout",
"Convolution": [
"ConvTranspose3d",
"Conv3d",
"ConvTranspose2d",
"Conv2d",
"Conv1d",
"VolumetricFullConvolution",
"VolumetricMaxUnpooling"
],
"Containers": [
"Concat"
],
"Criterion": [
"BCECriterion",
"WeightedMSECriterion",
"SmoothL1Criterion",
"MSECriterion",
"AbsCriterion",
"MultiCriterion",
"DistKLDivCriterion",
"HingeEmbeddingCriterion",
"CriterionTable",
"MultiMarginCriterion",
"MultiLabelMarginCriterion",
"L1HingeEmbeddingCriterion",
"CosineEmbeddingCriterion",
"MarginRankingCriterion",
"CrossEntropyCriterion",
"MarginCriterion",
"ClassNLLCriterion",
"ParallelCriterion",
"SpatialClassNLLCriterion",
"SoftMarginCriterion",
"MultiLabelSoftMarginCriterion"
],
"Simple": [
"Linear",
"LinearNoBias",
"SparseLinear",
"Dropout",
"Abs",
"Add",
"Mul",
"CMul",
"Max",
"Min",
"Mean",
"Sum",
"Euclidean",
"WeightedEuclidean",
"Identity",
"Copy",
"Narrow",
"Replicate",
"Reshape",
"View",
"Select",
"Exp",
"Square",
"Sqrt",
"Power",
"MM",
"AddConstant",
"MulConstant"
],
"Transfer": [
"Threshold",
"HardTanh",
"HardShrink",
"SoftShrink",
"SoftMax",
"SpatialSoftMax",
"SoftMin",
"SoftPlus",
"SoftSign",
"LogSigmoid",
"LogSoftMax",
"Sigmoid",
"Tanh",
"ReLU",
"ReLU6",
"PReLU",
"RReLU",
"LeakyReLU"
]
"FractionalMaxPool2d",
"LPPool2d",
"MaxUnpool3d",
"AvgPool3d",
"MaxPool3d",
"AvgPool2d",
"MaxUnpool2d",
"MaxPool2d",
"MaxPool1d",
"ReplicationPad3d",
"ReplicationPad2d",
"ReflectionPad2d"
],
"Simple": [
"Dropout3d",
"Dropout2d",
"Dropout",
"Linear",
"Embedding"
],
"Criterion": [
"MultiMarginLoss",
"MarginRankingLoss",
"CosineEmbeddingLoss",
"CrossMapLRN2d"
]
}
+44 -20
Ver Arquivo
@@ -28,7 +28,10 @@ if (exists.sync(configPath)) { // Check the deepforge config
config = JSON.parse(fs.readFileSync(configPath, 'utf8'));
torchPath = (config.torch && config.torch.dir) || (configDir + 'torch');
}
torchPath += `/install/share/lua/5.1/${outputName}/`;
// FIXME: Get the pytorch root path...
torchPath = process.env.HOME + '/projects/pytorch';
// check 'modules', 'parallel'
torchPath += '/torch/nn/';
console.log(`parsing ${outputName} from ${torchPath}`);
@@ -36,26 +39,37 @@ skipLayerList.forEach(name => SKIP_LAYERS[name] = true);
catNames.forEach(cat => // create layer -> category dictionary
categories[cat].forEach(lname => layerToCategory[lname] = cat)
);
var lookupType = function(name){
var layerType = layerToCategory[name];
var lookupType = function(layer){
var layerType;
if (layer.baseType === 'Container') {
layerType = 'Container';
} else {
layerType = layerToCategory[layer.name];
}
if (!layerType) { // try to infer
layerType = name.indexOf('Criterion') > -1 && 'Criterion';
layerType = layer.name.indexOf('Criterion') > -1 && 'Criterion';
}
return layerType || 'Misc';
};
fs.readdir(torchPath, function(err,files){
if(err) throw err;
var layers,
var parseLayerFiles = function(layerDir) {
var files = fs.readdirSync(layerDir),
layers,
layerByName = {};
layers = files.filter(filename => path.extname(filename) === '.lua')
.map(filename => fs.readFileSync(torchPath + filename, 'utf8'))
console.log('parsing', layerDir);
layers = files.filter(filename => path.extname(filename) === '.py' &&
filename[0] !== '_')
.map(filename => fs.readFileSync(layerDir + filename, 'utf8'))
.map(code => LayerParser.parse(code))
.filter(list => list !== null)
.reduce((l1, l2) => l1.concat(l2), [])
.filter(layer => !!layer && layer.name);
layers.forEach(layer => {
layer.type = lookupType(layer.name);
layer.type = lookupType(layer);
layerByName[layer.name] = layer;
});
@@ -97,17 +111,27 @@ fs.readdir(torchPath, function(err,files){
}
});
layers = layers.filter(layer => !SKIP_LAYERS[layer.name]);
return layers;
};
outputDst += outputName + '.json';
// eslint-disable-next-line no-console
console.log('Saved nn interface to ' + outputDst);
fs.writeFileSync(outputDst, JSON.stringify(layers, null, 2));
var layers = ['modules']
.map(dir => torchPath + dir + '/')
.map(path => parseLayerFiles(path))
.reduce((l1, l2) => l1.concat(l2))
.filter(layer => layer.name[0] !== '_'); // skip hidden/abstract layers
// Update the CreateTorchMeta index
var updateSchemas = `${__dirname}/../src/plugins/CreateTorchMeta/update-schemas.js`,
job = require('child_process').fork(updateSchemas);
job.on('close', code => {
process.exit(code);
});
// eslint-disable-next-line no-console
console.log('discovered', layers.length, 'layers');
outputDst += outputName + '.json';
// eslint-disable-next-line no-console
console.log('Saved nn interface to ' + outputDst);
fs.writeFileSync(outputDst, JSON.stringify(layers, null, 2));
// Update the CreateTorchMeta index
var updateSchemas = `${__dirname}/../src/plugins/CreateTorchMeta/update-schemas.js`,
job = require('child_process').fork(updateSchemas);
job.on('close', code => {
process.exit(code);
});
+104
Ver Arquivo
@@ -0,0 +1,104 @@
var brython = require('./node-brython'),
fs = require('fs'),
assert = require('assert'),
src = fs.readFileSync(process.env.HOME + '/projects/pytorch/torch/nn/modules/conv.py', 'utf8'),
root = build_ast(src);
function build_ast(src) {
brython.$py_module_path['__main__']='./'
return brython.py2js(src,'__main__', '__main__', '__builtins__')
}
// The provided tree gives us contexts which can have associated 'C'
function traverse (node, fn) {
var i;
if (node.children) {
for (i = node.children.length; i--;) {
traverse(node.children[i], fn);
fn(node.children[i]);
}
}
if (node.C && node.C.tree) {
for (i = node.C.tree.length; i--;) {
traverse(node.C.tree[i], fn);
fn(node.C.tree[i]);
}
}
}
var types = {},
layers = [],
pCtx,
classNode,
params;
function isClass(node) {
return node.type === 'class';
}
function isInitFn(node) {
return node.type === 'def' && node.name === '__init__';
}
function getBaseClass(node) {
assert(node.type === 'class');
return node.args.tree[0].tree[0].tree[0].value;
}
var defaults = {},
defTypes,
args,
def;
traverse(root, node => {
if (node.type) types[node.type] = true;
// Get the class for the given function
if (isInitFn(node)) {
pCtx = node.parent.node.parent;
classNode = pCtx.C.tree[0];
if (isClass(classNode)) {
// remove the 'self' variable
// TODO: May need to update this for kwargs
// (use positional_list)
args = node.tree[1].tree;
defaults = {};
params = node.args.slice(1);
defTypes = {};
for (var i = args.length; i--;) {
if (args[i].tree[0]) {
def = args[i].tree[0].tree[0];
console.log('setting type of ', params[i-1], 'to', def.type);
defTypes[params[i-1]] = def.type;
if (def.type === 'int') {
defaults[params[i-1]] = parseInt.apply(null, def.value.reverse());
} else {
defaults[params[i-1]] = def.value;
}
}
}
layers.push({
name: classNode.name,
baseType: getBaseClass(classNode),
//doc: classNode.doc_string || '',
defaults: defaults,
types: defTypes,
params: params
});
}
}
// TODO: What if there is no constructor? Is this a potential problem?
});
console.log('layers:', layers);
fs.writeFileSync('./testPyTorchLayers.json', JSON.stringify(layers, null, 2));
//console.log('layers:', layers.map(l => l.name));
// Try to find the class definitions...
//
// Need to create:
//
// setters: (I don't think these are used in pytorch!
// types:
// defaults:
// type:
+3
Ver Arquivo
@@ -287,6 +287,9 @@
},
"LayerDecorator": {
"src": "src/decorators/LayerDecorator"
},
"ContainerLayerDecorator": {
"src": "src/decorators/ContainerLayerDecorator"
}
},
"seeds": {