Skip to content

Commit

Permalink
add descriptions to layers from attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
transcranial committed Dec 2, 2017
1 parent 77d0075 commit f5bb73f
Show file tree
Hide file tree
Showing 35 changed files with 109 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/Layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export default class Layer {
constructor(attrs = {}) {
this.layerClass = 'Layer'
this.name = attrs.name
this.description = ''
this.gpu = webgl2.isSupported && attrs.gpu

this.params = []
Expand Down
2 changes: 2 additions & 0 deletions src/layers/InputLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ export default class InputLayer extends Layer {
const { shape = [] } = attrs

this.shape = attrs.batch_input_shape && attrs.batch_input_shape.length ? attrs.batch_input_shape.slice(1) : shape

this.description = `shape: ${JSON.stringify(this.shape)}`
}

/**
Expand Down
2 changes: 2 additions & 0 deletions src/layers/advanced_activations/ELU.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ export default class ELU extends Layer {

const { alpha = 1.0 } = attrs

this.description = `alpha: ${alpha}`

this.alpha = alpha

// GPU setup
Expand Down
2 changes: 2 additions & 0 deletions src/layers/advanced_activations/LeakyReLU.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ export default class LeakyReLU extends Layer {

const { alpha = 0.3 } = attrs

this.description = `alpha: ${alpha}`

this.alpha = alpha

// GPU setup
Expand Down
2 changes: 2 additions & 0 deletions src/layers/advanced_activations/ThresholdedReLU.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ export default class ThresholdedReLU extends Layer {

const { theta = 1 } = attrs

this.description = `theta: ${theta}`

this.theta = theta

// GPU setup
Expand Down
5 changes: 5 additions & 0 deletions src/layers/convolutional/Conv1D.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ export default class Conv1D extends Layer {
use_bias = true
} = attrs

this.description = `${filters} filters of size ${kernel_size}, striding ${strides}`
this.description += padding === 'valid' ? `, no border padding` : ', pad to same borders'
this.description += dilation_rate > 1 ? `, dilation rate ${dilation_rate}` : ''
this.description += activation !== 'linear' ? `, ${activation} activation` : ''

if (padding !== 'valid' && padding !== 'same') {
this.throwError('Invalid padding.')
}
Expand Down
6 changes: 6 additions & 0 deletions src/layers/convolutional/Conv2D.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,12 @@ export default class Conv2D extends Layer {
// Layer weights specification
this.params = this.useBias ? ['kernel', 'bias'] : ['kernel']

this.description = `${this.kernelShape[0]} ${this.kernelShape.slice(1).join('x')} filters`
this.description += this.strides.some(s => s > 1) ? `, ${this.strides.join('x')} striding` : ''
this.description += this.padding === 'valid' ? `, no border padding` : ', pad to same borders'
this.description += this.dilationRate.some(r => r > 1) ? `, ${this.dilationRate.join('x')} dilation` : ''
this.description += this.activation !== 'linear' ? `, ${this.activation} activation` : ''

// GPU setup
if (this.gpu) {
this.mapInputProgram = webgl2.compileProgram(mapInputProgramSource)
Expand Down
5 changes: 5 additions & 0 deletions src/layers/convolutional/Conv2DTranspose.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@ export default class Conv2DTranspose extends Layer {
// Layer weights specification
this.params = this.useBias ? ['kernel', 'bias'] : ['kernel']

this.description = `${this.kernelShape[0]} ${this.kernelShape.slice(1).join('x')} filters`
this.description += this.strides.some(s => s > 1) ? `, ${this.strides.join('x')} striding` : ''
this.description += this.padding === 'valid' ? `, no border padding` : ', pad to same borders'
this.description += this.activation !== 'linear' ? `, ${this.activation} activation` : ''

// GPU setup
if (this.gpu) {
this.matMulProgram = webgl2.compileProgram(matMulProgramSource)
Expand Down
6 changes: 6 additions & 0 deletions src/layers/convolutional/Conv3D.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,12 @@ export default class Conv3D extends Layer {
// Layer weights specification
this.params = this.useBias ? ['kernel', 'bias'] : ['kernel']

this.description = `${this.kernelShape[0]} ${this.kernelShape.slice(1).join('x')} filters`
this.description += this.strides.some(s => s > 1) ? `, ${this.strides.join('x')} striding` : ''
this.description += this.padding === 'valid' ? `, no border padding` : ', pad to same borders'
this.description += this.dilationRate.some(r => r > 1) ? `, ${this.dilationRate.join('x')} dilation` : ''
this.description += this.activation !== 'linear' ? `, ${this.activation} activation` : ''

// GPU setup
if (this.gpu) {
this.mapInputProgram = webgl2.compileProgram(mapInputProgramSource)
Expand Down
2 changes: 2 additions & 0 deletions src/layers/convolutional/Cropping1D.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ export default class Cropping1D extends Layer {
this.cropping = [cropping, cropping]
}

this.description = `${JSON.stringify(this.cropping)}`

// GPU setup
if (this.gpu) {
this.mapInputProgram = webgl2.compileProgram(mapInputProgramSource)
Expand Down
2 changes: 2 additions & 0 deletions src/layers/convolutional/Cropping2D.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ export default class Cropping2D extends Layer {

this.dataFormat = data_format

this.description = `${JSON.stringify(this.cropping)}`

// GPU setup
if (this.gpu) {
this.mapInputProgram = webgl2.compileProgram(mapInputProgramSource)
Expand Down
2 changes: 2 additions & 0 deletions src/layers/convolutional/Cropping3D.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ export default class Cropping3D extends Layer {

this.dataFormat = data_format

this.description = `${JSON.stringify(this.cropping)}`

// GPU setup
if (this.gpu) {
this.mapInputProgram = webgl2.compileProgram(mapInputProgramSource)
Expand Down
5 changes: 5 additions & 0 deletions src/layers/convolutional/SeparableConv2D.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,11 @@ export default class SeparableConv2D extends Layer {
use_bias = true
} = attrs

this.description = `${filters} ${kernel_size.join('x')} filters, ${strides.join('x')} striding`
this.description += padding === 'valid' ? `, no border padding` : ', pad to same borders'
this.description += depth_multiplier > 1 ? `, depth multiplier: ${depth_multiplier}` : ''
this.description += activation !== 'linear' ? `, ${activation} activation` : ''

if (Array.isArray(kernel_size)) {
this.kernelShape = [filters, ...kernel_size]
} else {
Expand Down
2 changes: 2 additions & 0 deletions src/layers/convolutional/UpSampling1D.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ export default class UpSampling1D extends Layer {
const { size = 2 } = attrs
this.size = size

this.description = `size ${size}`

// GPU setup
if (this.gpu) {
this.mapInputProgram = webgl2.compileProgram(mapInputProgramSource)
Expand Down
2 changes: 2 additions & 0 deletions src/layers/convolutional/UpSampling2D.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ export default class UpSampling2D extends Layer {

this.dataFormat = data_format

this.description = `size ${this.size.join('x')}`

// GPU setup
if (this.gpu) {
this.mapInputProgram = webgl2.compileProgram(mapInputProgramSource)
Expand Down
2 changes: 2 additions & 0 deletions src/layers/convolutional/UpSampling3D.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ export default class UpSampling3D extends Layer {

this.dataFormat = data_format

this.description = `size ${this.size.join('x')}`

// GPU setup
if (this.gpu) {
this.mapInputProgram = webgl2.compileProgram(mapInputProgramSource)
Expand Down
2 changes: 2 additions & 0 deletions src/layers/convolutional/ZeroPadding1D.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ export default class ZeroPadding1D extends Layer {
this.padding = [padding, padding]
}

this.description = `${JSON.stringify(this.padding)}`

// GPU setup
if (this.gpu) {
this.mapInputProgram = webgl2.compileProgram(mapInputProgramSource)
Expand Down
2 changes: 2 additions & 0 deletions src/layers/convolutional/ZeroPadding2D.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ export default class ZeroPadding2D extends Layer {

this.dataFormat = data_format

this.description = `${JSON.stringify(this.padding)}`

// GPU setup
if (this.gpu) {
this.mapInputProgram = webgl2.compileProgram(mapInputProgramSource)
Expand Down
2 changes: 2 additions & 0 deletions src/layers/convolutional/ZeroPadding3D.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ export default class ZeroPadding3D extends Layer {

this.dataFormat = data_format

this.description = `${JSON.stringify(this.padding)}`

// GPU setup
if (this.gpu) {
this.mapInputProgram = webgl2.compileProgram(mapInputProgramSource)
Expand Down
2 changes: 2 additions & 0 deletions src/layers/core/Activation.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ export default class Activation extends Layer {
this.activation = activation
this.activationFunc = activations[activation]

this.description = `${this.activation}`

// GPU setup
if (this.gpu) {
this.program = webgl2.compileProgram(activationProgramSources[this.activation])
Expand Down
2 changes: 2 additions & 0 deletions src/layers/core/Dense.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ export default class Dense extends Layer {

const { units = 1, activation = 'linear', input_dim = null, use_bias = true } = attrs

this.description = `${activation} activation, output dimensions: ${units}`

this.activation = activation
this.activationFunc = activations[this.activation]
this.units = units
Expand Down
2 changes: 2 additions & 0 deletions src/layers/core/Dropout.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ export default class Dropout extends Layer {

const { rate = 0.5 } = attrs

this.description = `${rate}`

this.rate = Math.min(Math.max(0, rate), 1)
}

Expand Down
3 changes: 3 additions & 0 deletions src/layers/core/Permute.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ export default class Permute extends Layer {
this.layerClass = 'Permute'

const { dims = [] } = attrs

this.description = `${JSON.stringify(dims)}`

this.dims = dims.map(dim => dim - 1)

// GPU setup
Expand Down
2 changes: 2 additions & 0 deletions src/layers/core/RepeatVector.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ export default class RepeatVector extends Layer {
const { n = 1 } = attrs
this.n = n

this.description = `n = ${n}`

// GPU setup
if (this.gpu) {
this.program = webgl2.compileProgram(programSource)
Expand Down
2 changes: 2 additions & 0 deletions src/layers/core/Reshape.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ export default class Reshape extends Layer {
const { target_shape = [] } = attrs
this.targetShape = target_shape

this.description = `target shape: ${JSON.stringify(this.targetShape)}`

// GPU setup
if (this.gpu) {
this.mapInputProgram = webgl2.compileProgram(mapInputProgramSource)
Expand Down
2 changes: 2 additions & 0 deletions src/layers/core/SpatialDropout1D.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ export default class SpatialDropout1D extends Layer {

const { p = 0.5 } = attrs

this.description = `${p}`

this.p = Math.min(Math.max(0, p), 1)
}

Expand Down
2 changes: 2 additions & 0 deletions src/layers/core/SpatialDropout2D.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ export default class SpatialDropout2D extends Layer {

const { rate = 0.5, data_format = 'channels_last' } = attrs

this.description = `${rate}`

this.rate = Math.min(Math.max(0, rate), 1)
this.dataFormat = data_format
}
Expand Down
2 changes: 2 additions & 0 deletions src/layers/core/SpatialDropout3D.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ export default class SpatialDropout3D extends Layer {

const { rate = 0.5, data_format = 'channels_last' } = attrs

this.description = `${rate}`

this.rate = Math.min(Math.max(0, rate), 1)
this.dataFormat = data_format
}
Expand Down
2 changes: 2 additions & 0 deletions src/layers/embeddings/Embedding.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ export default class Embedding extends Layer {

const { input_dim = 1, output_dim = 1, input_length = 0, mask_zero = false } = attrs

this.description = `output dimensions: ${output_dim}`

this.inputDim = input_dim
this.outputDim = output_dim
this.inputLength = input_length
Expand Down
4 changes: 4 additions & 0 deletions src/layers/pooling/_Pooling1D.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ export default class _Pooling1D extends Layer {
// can be `max` or `average`
this.poolingFunc = 'max'

this.description = `pool size ${this.poolSize}`
this.description += this.strides > 1 ? `, striding ${this.strides} striding` : ''
this.description += this.padding === 'valid' ? `, no border padding` : ', pad to same borders'

// GPU setup
if (this.gpu) {
this.poolingProgram = webgl2.compileProgram(poolingProgramSource)
Expand Down
4 changes: 4 additions & 0 deletions src/layers/pooling/_Pooling2D.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ export default class _Pooling2D extends Layer {
// can be `max` or `average`
this.poolingFunc = 'max'

this.description = `pool size ${this.poolSize.join('x')}`
this.description += this.strides.some(s => s > 1) ? `, ${this.strides.join('x')} striding` : ''
this.description += this.padding === 'valid' ? `, no border padding` : ', pad to same borders'

// GPU setup
if (this.gpu) {
this.poolingProgram = webgl2.compileProgram(poolingProgramSource)
Expand Down
4 changes: 4 additions & 0 deletions src/layers/pooling/_Pooling3D.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ export default class _Pooling3D extends Layer {
// can be `max` or `average`
this.poolingFunc = 'max'

this.description = `pool size ${this.poolSize.join('x')}`
this.description += this.strides.some(s => s > 1) ? `, ${this.strides.join('x')} striding` : ''
this.description += this.padding === 'valid' ? `, no border padding` : ', pad to same borders'

// GPU setup
if (this.gpu) {
this.poolingProgram = webgl2.compileProgram(poolingProgramSource)
Expand Down
8 changes: 8 additions & 0 deletions src/layers/recurrent/GRU.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,14 @@ export default class GRU extends Layer {
// Layer weights specification
this.params = this.use_bias ? ['kernel', 'recurrent_kernel', 'bias'] : ['kernel', 'recurrent_kernel']

this.description = `output dimensions: ${this.units}`
this.description += this.activation !== 'linear' ? `, ${this.activation} activation` : ''
this.description +=
this.recurrentActivation !== 'linear' ? `, ${this.recurrentActivation} recurrent activation` : ''
this.description += this.returnSequences ? `, return sequences` : ''
this.description += this.goBackwards ? `, backward direction` : ''
this.description += this.stateful ? `, stateful` : ''

// GPU setup
if (this.gpu) {
this.copyTextureProgram = webgl2.compileProgram(copyTextureProgramSource)
Expand Down
8 changes: 8 additions & 0 deletions src/layers/recurrent/LSTM.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,14 @@ export default class LSTM extends Layer {
// Layer weights specification
this.params = this.use_bias ? ['kernel', 'recurrent_kernel', 'bias'] : ['kernel', 'recurrent_kernel']

this.description = `output dimensions: ${this.units}`
this.description += this.activation !== 'linear' ? `, ${this.activation} activation` : ''
this.description +=
this.recurrentActivation !== 'linear' ? `, ${this.recurrentActivation} recurrent activation` : ''
this.description += this.returnSequences ? `, return sequences` : ''
this.description += this.goBackwards ? `, backward direction` : ''
this.description += this.stateful ? `, stateful` : ''

// GPU setup
if (this.gpu) {
this.copyTextureProgram = webgl2.compileProgram(copyTextureProgramSource)
Expand Down
6 changes: 6 additions & 0 deletions src/layers/recurrent/SimpleRNN.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ export default class SimpleRNN extends Layer {
// Layer weights specification
this.params = this.use_bias ? ['kernel', 'recurrent_kernel', 'bias'] : ['kernel', 'recurrent_kernel']

this.description = `output dimensions: ${this.units}`
this.description += this.activation !== 'linear' ? `, ${this.activation} activation` : ''
this.description += this.returnSequences ? `, return sequences` : ''
this.description += this.goBackwards ? `, backward direction` : ''
this.description += this.stateful ? `, stateful` : ''

// GPU setup
if (this.gpu) {
this.copyTextureProgram = webgl2.compileProgram(copyTextureProgramSource)
Expand Down

0 comments on commit f5bb73f

Please sign in to comment.