Skip to content

Commit

Permalink
layer level attribute for layers and add support in models (#144)
Browse files Browse the repository at this point in the history
  • Loading branch information
syt123450 committed Nov 29, 2018
1 parent 2cb4ce3 commit d2a00a4
Show file tree
Hide file tree
Showing 42 changed files with 91 additions and 42 deletions.
16 changes: 15 additions & 1 deletion src/layer/abstract/Layer.js
Expand Up @@ -250,6 +250,20 @@ function Layer( config ) {

this.layerType = undefined;

/**
* The place for Layer in model, measured by y-axis in 3d scene.
* For Sequential model:
* the "layerLevel" will be the same as "layerIndex".
* the layerLevel will be unique for all layers.
* For Functional model:
* the "layerLevel" may be the same for several layers.
* these layers has different "layerIndex".
*
* @type { Int }
*/

this.layerLevel = undefined;

// Load layer config.

this.loadBasicLayerConfig( config );
Expand Down Expand Up @@ -497,7 +511,7 @@ Layer.prototype = {
* @param { int } layerIndex, this layer's order in model
*/

assemble: function( layerIndex ) {
assemble: function( layerIndex, layerLevel ) {

},

Expand Down
2 changes: 1 addition & 1 deletion src/layer/abstract/MergedLayer.js
Expand Up @@ -117,7 +117,7 @@ MergedLayer.prototype = Object.assign( Object.create( Layer.prototype ), {
* @param { int } layerIndex, this layer's order in model
*/

assemble: function( layerIndex ) {
assemble: function( layerIndex, layerLevel ) {

},

Expand Down
3 changes: 2 additions & 1 deletion src/layer/abstract/MergedLayer1d.js
Expand Up @@ -219,9 +219,10 @@ MergedLayer1d.prototype = Object.assign( Object.create( MergedLayer.prototype ),
* @param { int } layerIndex, this layer's order in model
*/

assemble: function( layerIndex ) {
assemble: function( layerIndex, layerLevel ) {

this.layerIndex = layerIndex;
this.layerLevel = layerLevel;

// Validate whether user's input merged elements can be merged in this kind of merge operation.

Expand Down
3 changes: 2 additions & 1 deletion src/layer/abstract/MergedLayer2d.js
Expand Up @@ -116,9 +116,10 @@ MergedLayer2d.prototype = Object.assign( Object.create( MergedLayer.prototype ),

},

assemble: function( layerIndex ) {
assemble: function( layerIndex, layerLevel ) {

this.layerIndex = layerIndex;
this.layerLevel = layerLevel;

// Validate whether user's input merged elements can be merged in this kind of merge operation.

Expand Down
3 changes: 2 additions & 1 deletion src/layer/abstract/MergedLayer3d.js
Expand Up @@ -170,9 +170,10 @@ MergedLayer3d.prototype = Object.assign( Object.create( MergedLayer.prototype ),
* @param { int } layerIndex, this layer's order in model
*/

assemble: function( layerIndex ) {
assemble: function( layerIndex, layerLevel ) {

this.layerIndex = layerIndex;
this.layerLevel = layerLevel;

// Validate whether user's input merged elements can be merged in this kind of merge operation.

Expand Down
2 changes: 1 addition & 1 deletion src/layer/abstract/NativeLayer.js
Expand Up @@ -110,7 +110,7 @@ NativeLayer.prototype = Object.assign( Object.create( Layer.prototype ), {
* @param { int } layerIndex, this layer's order in model
*/

assemble: function( layerIndex ) {
assemble: function( layerIndex, layerLevel ) {

},

Expand Down
2 changes: 1 addition & 1 deletion src/layer/abstract/NativeLayer1d.js
Expand Up @@ -1055,7 +1055,7 @@ NativeLayer1d.prototype = Object.assign( Object.create( NativeLayer.prototype ),
* @param { int } layerIndex, this layer's order in model.
*/

assemble: function( layerIndex ) {
assemble: function( layerIndex, layerLevel ) {

},

Expand Down
2 changes: 1 addition & 1 deletion src/layer/abstract/NativeLayer2d.js
Expand Up @@ -687,7 +687,7 @@ NativeLayer2d.prototype = Object.assign( Object.create( NativeLayer.prototype ),
* @param { int } layerIndex, this layer's order in model.
*/

assemble: function( layerIndex ) {
assemble: function( layerIndex, layerLevel ) {

},

Expand Down
2 changes: 1 addition & 1 deletion src/layer/abstract/NativeLayer3d.js
Expand Up @@ -729,7 +729,7 @@ NativeLayer3d.prototype = Object.assign( Object.create( NativeLayer.prototype ),
* @param { int } layerIndex, this layer's order in model
*/

assemble: function( layerIndex ) {
assemble: function( layerIndex, layerLevel ) {

},

Expand Down
3 changes: 2 additions & 1 deletion src/layer/input/GreyscaleInput.js
Expand Up @@ -138,9 +138,10 @@ GreyscaleInput.prototype = Object.assign( Object.create( NativeLayer.prototype )
* @param { int } layerIndex, this layer's order in model
*/

assemble: function( layerIndex ) {
assemble: function( layerIndex, layerLevel ) {

this.layerIndex = layerIndex;
this.layerLevel = layerLevel;

},

Expand Down
3 changes: 2 additions & 1 deletion src/layer/input/Input1d.js
Expand Up @@ -137,9 +137,10 @@ Input1d.prototype = Object.assign( Object.create( NativeLayer.prototype ), {
* @param { int } layerIndex, this layer's order in model
*/

assemble: function( layerIndex ) {
assemble: function( layerIndex, layerLevel ) {

this.layerIndex = layerIndex;
this.layerLevel = layerLevel;

},

Expand Down
3 changes: 2 additions & 1 deletion src/layer/input/RGBInput.js
Expand Up @@ -178,9 +178,10 @@ RGBInput.prototype = Object.assign( Object.create( NativeLayer.prototype ), {
* @param { int } layerIndex, this layer's order in model
*/

assemble: function( layerIndex ) {
assemble: function( layerIndex, layerLevel ) {

this.layerIndex = layerIndex;
this.layerLevel = layerLevel;

},

Expand Down
3 changes: 2 additions & 1 deletion src/layer/intermediate/Activation1d.js
Expand Up @@ -52,9 +52,10 @@ Activation1d.prototype = Object.assign( Object.create( NativeLayer1d.prototype )
* @param { int } layerIndex, this layer's order in model
*/

assemble: function( layerIndex ) {
assemble: function( layerIndex, layerLevel ) {

this.layerIndex = layerIndex;
this.layerLevel = layerLevel;

this.inputShape = this.lastLayer.outputShape;

Expand Down
3 changes: 2 additions & 1 deletion src/layer/intermediate/Activation2d.js
Expand Up @@ -52,9 +52,10 @@ Activation2d.prototype = Object.assign( Object.create( NativeLayer2d.prototype )
* @param { int } layerIndex, this layer's order in model
*/

assemble: function( layerIndex ) {
assemble: function( layerIndex, layerLevel ) {

this.layerIndex = layerIndex;
this.layerLevel = layerLevel;

this.inputShape = this.lastLayer.outputShape;

Expand Down
3 changes: 2 additions & 1 deletion src/layer/intermediate/Activation3d.js
Expand Up @@ -52,9 +52,10 @@ Activation3d.prototype = Object.assign( Object.create( NativeLayer3d.prototype )
* @param { int } layerIndex, this layer's order in model
*/

assemble: function( layerIndex ) {
assemble: function( layerIndex, layerLevel ) {

this.layerIndex = layerIndex;
this.layerLevel = layerLevel;

this.inputShape = this.lastLayer.outputShape;

Expand Down
3 changes: 2 additions & 1 deletion src/layer/intermediate/BasicLayer1d.js
Expand Up @@ -44,9 +44,10 @@ BasicLayer1d.prototype = Object.assign( Object.create( NativeLayer1d.prototype )
* @param { int } layerIndex, this layer's order in model
*/

assemble: function( layerIndex ) {
assemble: function( layerIndex, layerLevel ) {

this.layerIndex = layerIndex;
this.layerLevel = layerLevel;

// Unit length is the same as last layer, use unit length to calculate actualWidth which is used to create three.js object.

Expand Down
3 changes: 2 additions & 1 deletion src/layer/intermediate/BasicLayer2d.js
Expand Up @@ -45,9 +45,10 @@ BasicLayer2d.prototype = Object.assign( Object.create( NativeLayer2d.prototype )
* @param { int } layerIndex, this layer's order in model
*/

assemble: function( layerIndex ) {
assemble: function( layerIndex, layerLevel ) {

this.layerIndex = layerIndex;
this.layerLevel = layerLevel;

// Unit length is the same as last layer, use unit length to calculate actualWidth and actualHeight which are used to create three.js object.

Expand Down
3 changes: 2 additions & 1 deletion src/layer/intermediate/BasicLayer3d.js
Expand Up @@ -45,9 +45,10 @@ BasicLayer3d.prototype = Object.assign( Object.create( NativeLayer3d.prototype )
* @param { int } layerIndex, this layer's order in model
*/

assemble: function ( layerIndex ) {
assemble: function( layerIndex, layerLevel ) {

this.layerIndex = layerIndex;
this.layerLevel = layerLevel;

// Unit length is the same as last layer, use unit length to calculate actualWidth and actualHeight which are used to create three.js object.

Expand Down
3 changes: 2 additions & 1 deletion src/layer/intermediate/Conv1d.js
Expand Up @@ -103,9 +103,10 @@ Conv1d.prototype = Object.assign( Object.create( NativeLayer2d.prototype ), {
* @param { int } layerIndex, this layer's order in model
*/

assemble: function( layerIndex ) {
assemble: function( layerIndex, layerLevel ) {

this.layerIndex = layerIndex;
this.layerLevel = layerLevel;

this.inputShape = this.lastLayer.outputShape;

Expand Down
3 changes: 2 additions & 1 deletion src/layer/intermediate/Conv2d.js
Expand Up @@ -107,9 +107,10 @@ Conv2d.prototype = Object.assign( Object.create( NativeLayer3d.prototype ), {
* @param { int } layerIndex, this layer's order in model
*/

assemble: function ( layerIndex ) {
assemble: function( layerIndex, layerLevel ) {

this.layerIndex = layerIndex;
this.layerLevel = layerLevel;

this.inputShape = this.lastLayer.outputShape;

Expand Down
3 changes: 2 additions & 1 deletion src/layer/intermediate/Conv2dTranspose.js
Expand Up @@ -107,9 +107,10 @@ Conv2dTranspose.prototype = Object.assign( Object.create( NativeLayer3d.prototyp
* @param { int } layerIndex, this layer's order in model
*/

assemble: function( layerIndex ) {
assemble: function( layerIndex, layerLevel ) {

this.layerIndex = layerIndex;
this.layerLevel = layerLevel;

this.inputShape = this.lastLayer.outputShape;

Expand Down
3 changes: 2 additions & 1 deletion src/layer/intermediate/Cropping1d.js
Expand Up @@ -61,9 +61,10 @@ Cropping1d.prototype = Object.assign( Object.create( NativeLayer2d.prototype ),
* @param { int } layerIndex, this layer's order in model
*/

assemble: function( layerIndex ) {
assemble: function( layerIndex, layerLevel ) {

this.layerIndex = layerIndex;
this.layerLevel = layerLevel;

this.inputShape = this.lastLayer.outputShape;

Expand Down
3 changes: 2 additions & 1 deletion src/layer/intermediate/Cropping2d.js
Expand Up @@ -62,9 +62,10 @@ Cropping2d.prototype = Object.assign( Object.create( NativeLayer3d.prototype ),
* @param { int } layerIndex, this layer's order in model
*/

assemble: function( layerIndex ) {
assemble: function( layerIndex, layerLevel ) {

this.layerIndex = layerIndex;
this.layerLevel = layerLevel;

this.inputShape = this.lastLayer.outputShape;

Expand Down
3 changes: 2 additions & 1 deletion src/layer/intermediate/Dense.js
Expand Up @@ -44,9 +44,10 @@ Dense.prototype = Object.assign( Object.create( NativeLayer1d.prototype ), {
* @param { int } layerIndex, this layer's order in model
*/

assemble: function( layerIndex ) {
assemble: function( layerIndex, layerLevel ) {

this.layerIndex = layerIndex;
this.layerLevel = layerLevel;

// Unit length is the same as last layer, use unit length to calculate actualWidth which is used to create three.js object.

Expand Down
3 changes: 2 additions & 1 deletion src/layer/intermediate/DepthwiseConv2d.js
Expand Up @@ -79,9 +79,10 @@ DepthwiseConv2d.prototype = Object.assign( Object.create( NativeLayer3d.prototyp
* @param { int } layerIndex, this layer's order in model
*/

assemble: function ( layerIndex ) {
assemble: function( layerIndex, layerLevel ) {

this.layerIndex = layerIndex;
this.layerLevel = layerLevel;

this.inputShape = this.lastLayer.outputShape;

Expand Down
3 changes: 2 additions & 1 deletion src/layer/intermediate/Flatten.js
Expand Up @@ -44,9 +44,10 @@ Flatten.prototype = Object.assign( Object.create( NativeLayer1d.prototype ), {
* @param { int } layerIndex, this layer's order in model
*/

assemble: function( layerIndex ) {
assemble: function( layerIndex, layerLevel ) {

this.layerIndex = layerIndex;
this.layerLevel = layerLevel;

let units = 1;

Expand Down
3 changes: 2 additions & 1 deletion src/layer/intermediate/GlobalPooling1d.js
Expand Up @@ -49,9 +49,10 @@ GlobalPooling1d.prototype = Object.assign( Object.create( NativeLayer2d.prototyp
* @param { int } layerIndex, this layer's order in model
*/

assemble: function( layerIndex ) {
assemble: function( layerIndex, layerLevel ) {

this.layerIndex = layerIndex;
this.layerLevel = layerLevel;

this.inputShape = this.lastLayer.outputShape;
this.depth = this.inputShape[ 1 ];
Expand Down
3 changes: 2 additions & 1 deletion src/layer/intermediate/GlobalPooling2d.js
Expand Up @@ -50,9 +50,10 @@ GlobalPooling2d.prototype = Object.assign( Object.create( NativeLayer3d.prototyp
* @param { int } layerIndex, this layer's order in model
*/

assemble: function( layerIndex ) {
assemble: function( layerIndex, layerLevel ) {

this.layerIndex = layerIndex;
this.layerLevel = layerLevel;

this.depth = this.lastLayer.depth;

Expand Down
3 changes: 2 additions & 1 deletion src/layer/intermediate/Padding1d.js
Expand Up @@ -62,9 +62,10 @@ Padding1d.prototype = Object.assign( Object.create( NativeLayer2d.prototype ), {
* @param { int } layerIndex, this layer's order in model
*/

assemble: function( layerIndex ) {
assemble: function( layerIndex, layerLevel ) {

this.layerIndex = layerIndex;
this.layerLevel = layerLevel;

this.inputShape = this.lastLayer.outputShape;

Expand Down
3 changes: 2 additions & 1 deletion src/layer/intermediate/Padding2d.js
Expand Up @@ -66,9 +66,10 @@ Padding2d.prototype = Object.assign( Object.create( NativeLayer3d.prototype ), {
* @param { int } layerIndex, this layer's order in model
*/

assemble: function( layerIndex ) {
assemble: function( layerIndex, layerLevel ) {

this.layerIndex = layerIndex;
this.layerLevel = layerLevel;

// Calculate layer's shape from last layer and user's configuration.

Expand Down
3 changes: 2 additions & 1 deletion src/layer/intermediate/Pooling1d.js
Expand Up @@ -78,9 +78,10 @@ Pooling1d.prototype = Object.assign( Object.create( NativeLayer2d.prototype ), {
* @param { int } layerIndex, this layer's order in model
*/

assemble: function( layerIndex ) {
assemble: function( layerIndex, layerLevel ) {

this.layerIndex = layerIndex;
this.layerLevel = layerLevel;

this.inputShape = this.lastLayer.outputShape;

Expand Down
3 changes: 2 additions & 1 deletion src/layer/intermediate/Pooling2d.js
Expand Up @@ -82,9 +82,10 @@ Pooling2d.prototype = Object.assign( Object.create( NativeLayer3d.prototype ), {
* @param { int } layerIndex, this layer's order in model
*/

assemble: function( layerIndex ) {
assemble: function( layerIndex, layerLevel ) {

this.layerIndex = layerIndex;
this.layerLevel = layerLevel;

this.depth = this.lastLayer.depth;

Expand Down
3 changes: 2 additions & 1 deletion src/layer/intermediate/Reshape1d.js
Expand Up @@ -63,9 +63,10 @@ Reshape1d.prototype = Object.assign( Object.create( NativeLayer1d.prototype ), {
* @param { int } layerIndex, this layer's order in model
*/

assemble: function( layerIndex ) {
assemble: function( layerIndex, layerLevel ) {

this.layerIndex = layerIndex;
this.layerLevel = layerLevel;

this.inputShape = this.lastLayer.outputShape;

Expand Down

0 comments on commit d2a00a4

Please sign in to comment.