diff --git a/src/layers/core/Dropout.js b/src/layers/core/Dropout.js index 1d4f232..50e5a4b 100644 --- a/src/layers/core/Dropout.js +++ b/src/layers/core/Dropout.js @@ -2,7 +2,8 @@ import Layer from '../../Layer' /** * Dropout layer class - * Note that this layer is here for compatibility, it's only applied during training time. + * Note that this layer is here only for compatibility purposes, + * as it's only active during training phase. */ export default class Dropout extends Layer { /** diff --git a/src/layers/core/SpatialDropout2D.js b/src/layers/core/SpatialDropout2D.js new file mode 100644 index 0000000..65a9da4 --- /dev/null +++ b/src/layers/core/SpatialDropout2D.js @@ -0,0 +1,35 @@ +import Layer from '../../Layer' + +/** + * SpatialDropout2D layer class + * Note that this layer is here only for compatibility purposes, + * as it's only active during training phase. + */ +export default class SpatialDropout2D extends Layer { + /** + * Creates an SpatialDropout2D layer + * @param {number} attrs.p - fraction of the input units to drop (between 0 and 1) + * @param {number} [attrs.dimOrdering] - `tf` or `th` + */ + constructor (attrs = {}) { + super(attrs) + this.layerClass = 'SpatialDropout2D' + + const { + p = 0.5, + dimOrdering = 'tf' + } = attrs + + this.p = Math.min(Math.max(0, p), 1) + this.dimOrdering = dimOrdering + } + + /** + * Method for layer computational logic + * @param {Tensor} x + * @returns {Tensor} x + */ + call (x) { + return x + } +} diff --git a/src/layers/core/SpatialDropout3D.js b/src/layers/core/SpatialDropout3D.js new file mode 100644 index 0000000..e63966f --- /dev/null +++ b/src/layers/core/SpatialDropout3D.js @@ -0,0 +1,35 @@ +import Layer from '../../Layer' + +/** + * SpatialDropout3D layer class + * Note that this layer is here only for compatibility purposes, + * as it's only active during training phase. + */ +export default class SpatialDropout3D extends Layer { + /** + * Creates an SpatialDropout3D layer + * @param {number} attrs.p - fraction of the input units to drop (between 0 and 1) + * @param {number} [attrs.dimOrdering] - `tf` or `th` + */ + constructor (attrs = {}) { + super(attrs) + this.layerClass = 'SpatialDropout3D' + + const { + p = 0.5, + dimOrdering = 'tf' + } = attrs + + this.p = Math.min(Math.max(0, p), 1) + this.dimOrdering = dimOrdering + } + + /** + * Method for layer computational logic + * @param {Tensor} x + * @returns {Tensor} x + */ + call (x) { + return x + } +} diff --git a/src/layers/core/index.js b/src/layers/core/index.js index e18356e..1b0da9c 100644 --- a/src/layers/core/index.js +++ b/src/layers/core/index.js @@ -1,6 +1,8 @@ import Dense from './Dense' import Activation from './Activation' import Dropout from './Dropout' +import SpatialDropout2D from './SpatialDropout2D' +import SpatialDropout3D from './SpatialDropout3D' import Flatten from './Flatten' import Reshape from './Reshape' import Permute from './Permute' @@ -13,6 +15,8 @@ export { Dense, Activation, Dropout, + SpatialDropout2D, + SpatialDropout3D, Flatten, Reshape, Permute,