當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript tfjs-core.add函數代碼示例

本文整理匯總了TypeScript中@tensorflow/tfjs-core.add函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript add函數的具體用法?TypeScript add怎麽用?TypeScript add使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了add函數的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: dLoss

 // Define losses.
 dLoss(truePred: tf.Tensor1D, generatedPred: tf.Tensor1D) {
   if (this.lossType === 'LeastSq loss') {
     return tf.add(
       truePred.sub(tf.scalar(1)).square().mean(),
       generatedPred.square().mean()
     ) as tf.Scalar;
   } else {
     return tf.add(
       truePred.log().mul(tf.scalar(0.95)).mean(),
       tf.sub(tf.scalar(1), generatedPred).log().mean()
     ).mul(tf.scalar(-1)) as tf.Scalar;
   }
 }
開發者ID:deepkapha,項目名稱:dklabs.github.io,代碼行數:14,代碼來源:ganlab_models.ts

示例2:

  return tf.tidy(() => {

    let out = tf.conv2d(x, params.filters, strides, 'same')
    out = tf.add(out, params.batch_norm_offset)
    return tf.clipByValue(out, 0, 6)

  })
開發者ID:BakirDiyar,項目名稱:face-api.js,代碼行數:7,代碼來源:pointwiseConvLayer.ts

示例3: residual

export function residual(x: tf.Tensor4D, params: ResidualLayerParams): tf.Tensor4D {
  let out = conv(x, params.conv1)
  out = convNoRelu(out, params.conv2)
  out = tf.add(out, x)
  out = tf.relu(out)
  return out
}
開發者ID:BakirDiyar,項目名稱:face-api.js,代碼行數:7,代碼來源:residualLayer.ts

示例4: residualDown

export function residualDown(x: tf.Tensor4D, params: ResidualLayerParams): tf.Tensor4D {
  let out = convDown(x, params.conv1)
  out = convNoRelu(out, params.conv2)

  let pooled = tf.avgPool(x, 2, 2, 'valid') as tf.Tensor4D
  const zeros = tf.zeros<tf.Rank.R4>(pooled.shape)
  const isPad = pooled.shape[3] !== out.shape[3]
  const isAdjustShape = pooled.shape[1] !== out.shape[1] || pooled.shape[2] !== out.shape[2]

  if (isAdjustShape) {
    const padShapeX = [...out.shape] as [number, number, number, number]
    padShapeX[1] = 1
    const zerosW = tf.zeros<tf.Rank.R4>(padShapeX)
    out = tf.concat([out, zerosW], 1)

    const padShapeY = [...out.shape] as [number, number, number, number]
    padShapeY[2] = 1
    const zerosH = tf.zeros<tf.Rank.R4>(padShapeY)
    out = tf.concat([out, zerosH], 2)
  }

  pooled = isPad ? tf.concat([pooled, zeros], 3) : pooled
  out = tf.add(pooled, out) as tf.Tensor4D

  out = tf.relu(out)
  return out
}
開發者ID:BakirDiyar,項目名稱:face-api.js,代碼行數:27,代碼來源:residualLayer.ts

示例5:

  return tf.tidy(() => {
    const out = tf.add(
      tf.conv2d(x, params.filters, [1, 1], padding),
      params.bias
    ) as tf.Tensor4D

    return withRelu ? tf.relu(out) : out
  })
開發者ID:BakirDiyar,項目名稱:face-api.js,代碼行數:8,代碼來源:convLayer.ts

示例6: getCenterCoordinatesAndSizesLayer

function getCenterCoordinatesAndSizesLayer(x: tf.Tensor2D) {
  const vec = tf.unstack(tf.transpose(x, [1, 0]))

  const sizes = [
    tf.sub(vec[2], vec[0]),
    tf.sub(vec[3], vec[1])
  ]

  const centers = [
    tf.add(vec[0], tf.div(sizes[0], tf.scalar(2))),
    tf.add(vec[1], tf.div(sizes[1], tf.scalar(2)))
  ]

  return {
    sizes,
    centers
  }
}
開發者ID:BakirDiyar,項目名稱:face-api.js,代碼行數:18,代碼來源:outputLayer.ts

示例7: convLayer

function convLayer(
  x: tf.Tensor4D,
  params: ConvLayerParams,
  strides: [number, number],
  withRelu: boolean,
  padding: 'valid' | 'same' = 'same'
): tf.Tensor4D {
  const { filters, bias } = params.conv

  let out = tf.conv2d(x, filters, strides, padding)
  out = tf.add(out, bias)
  out = scale(out, params.scale)
  return withRelu ? tf.relu(out) : out
}
開發者ID:BakirDiyar,項目名稱:face-api.js,代碼行數:14,代碼來源:convLayer.ts

示例8: decodeBoxesLayer

function decodeBoxesLayer(x0: tf.Tensor2D, x1: tf.Tensor2D) {
  const {
    sizes,
    centers
  } = getCenterCoordinatesAndSizesLayer(x0)

  const vec = tf.unstack(tf.transpose(x1, [1, 0]))

  const div0_out = tf.div(tf.mul(tf.exp(tf.div(vec[2], tf.scalar(5))), sizes[0]), tf.scalar(2))
  const add0_out = tf.add(tf.mul(tf.div(vec[0], tf.scalar(10)), sizes[0]), centers[0])

  const div1_out = tf.div(tf.mul(tf.exp(tf.div(vec[3], tf.scalar(5))), sizes[1]), tf.scalar(2))
  const add1_out = tf.add(tf.mul(tf.div(vec[1], tf.scalar(10)), sizes[1]), centers[1])

  return tf.transpose(
    tf.stack([
      tf.sub(add0_out, div0_out),
      tf.sub(add1_out, div1_out),
      tf.add(add0_out, div0_out),
      tf.add(add1_out, div1_out)
    ]),
    [1, 0]
  )
}
開發者ID:BakirDiyar,項目名稱:face-api.js,代碼行數:24,代碼來源:outputLayer.ts

示例9: scale

export function scale(x: tf.Tensor4D, params: ScaleLayerParams): tf.Tensor4D {
  return tf.add(tf.mul(x, params.weights), params.biases)
}
開發者ID:BakirDiyar,項目名稱:face-api.js,代碼行數:3,代碼來源:scaleLayer.ts

示例10:

 return tf.tidy(() =>
   tf.add(
     tf.matMul(x, params.weights),
     params.bias
   )
開發者ID:BakirDiyar,項目名稱:face-api.js,代碼行數:5,代碼來源:fullyConnectedLayer.ts


注:本文中的@tensorflow/tfjs-core.add函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。