| 281 | } |
| 282 | |
| 283 | applyActivation<T extends Tensor>( |
| 284 | input: T, activation: string, preluActivationWeights?: Tensor, |
| 285 | leakyreluAlpha?: number): T { |
| 286 | let result = input; |
| 287 | if (activation != null) { |
| 288 | if (activation === 'linear') { |
| 289 | // No-op |
| 290 | } else if (activation === 'relu') { |
| 291 | result = tf.relu(result); |
| 292 | } else if (activation === 'prelu') { |
| 293 | result = tf.prelu(result, preluActivationWeights) as T; |
| 294 | } else if (activation === 'leakyrelu') { |
| 295 | result = tf.leakyRelu(result, leakyreluAlpha); |
| 296 | } else if (activation === 'elu') { |
| 297 | result = tf.elu(result); |
| 298 | } else if (activation === 'relu6') { |
| 299 | result = tf.relu6(result); |
| 300 | } else if (activation === 'sigmoid') { |
| 301 | result = tf.sigmoid(result); |
| 302 | } else { |
| 303 | throw new Error(`Activation: ${ |
| 304 | activation} has not been implemented for the Node.js backend`); |
| 305 | } |
| 306 | } |
| 307 | return result; |
| 308 | } |
| 309 | |
| 310 | divide(a: Tensor, b: Tensor): Tensor { |
| 311 | const opAttrs = [createTensorsTypeOpAttr( |