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


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

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


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

示例1: extractParams

export function extractParams(weights: Float32Array): NetParams {
  const {
    extractWeights,
    getRemainingWeights
  } = extractWeightsFactory(weights)

  const {
    extractConvLayerParams,
    extractResidualLayerParams
  } = extractorsFactory(extractWeights)

  const conv32_down = extractConvLayerParams(4704, 32, 7)
  const conv32_1 = extractResidualLayerParams(9216, 32, 3)
  const conv32_2 = extractResidualLayerParams(9216, 32, 3)
  const conv32_3 = extractResidualLayerParams(9216, 32, 3)

  const conv64_down = extractResidualLayerParams(36864, 64, 3, true)
  const conv64_1 = extractResidualLayerParams(36864, 64, 3)
  const conv64_2 = extractResidualLayerParams(36864, 64, 3)
  const conv64_3 = extractResidualLayerParams(36864, 64, 3)

  const conv128_down = extractResidualLayerParams(147456, 128, 3, true)
  const conv128_1 = extractResidualLayerParams(147456, 128, 3)
  const conv128_2 = extractResidualLayerParams(147456, 128, 3)

  const conv256_down = extractResidualLayerParams(589824, 256, 3, true)
  const conv256_1 = extractResidualLayerParams(589824, 256, 3)
  const conv256_2 = extractResidualLayerParams(589824, 256, 3)
  const conv256_down_out = extractResidualLayerParams(589824, 256, 3)

  const fc = tf.transpose(tf.tensor2d(extractWeights(256 * 128), [128, 256]), [1, 0])

  if (getRemainingWeights().length !== 0) {
    throw new Error(`weights remaing after extract: ${getRemainingWeights().length}`)
  }

  return {
    conv32_down,
    conv32_1,
    conv32_2,
    conv32_3,
    conv64_down,
    conv64_1,
    conv64_2,
    conv64_3,
    conv128_down,
    conv128_1,
    conv128_2,
    conv256_down,
    conv256_1,
    conv256_2,
    conv256_down_out,
    fc
  }
}
開發者ID:BakirDiyar,項目名稱:face-api.js,代碼行數:55,代碼來源:extractParams.ts

示例2: extractFilterValues

  function extractFilterValues(numFilterValues: number, numFilters: number, filterSize: number): tf.Tensor4D {
    const weights = extractWeights(numFilterValues)
    const depth = weights.length / (numFilters * filterSize * filterSize)

    if (isFloat(depth)) {
      throw new Error(`depth has to be an integer: ${depth}, weights.length: ${weights.length}, numFilters: ${numFilters}, filterSize: ${filterSize}`)
    }

    return tf.transpose(
      tf.tensor4d(weights, [numFilters, depth, filterSize, filterSize]),
      [2, 3, 1, 0]
    )
  }
開發者ID:BakirDiyar,項目名稱:face-api.js,代碼行數:13,代碼來源:extractParams.ts

示例3: 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

示例4: 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

示例5: switch

export let executeOp: OpExecutor = (node: Node, tensorMap: NamedTensorsMap,
                                    context: ExecutionContext):
                                       tfc.Tensor[] => {
  switch (node.op) {
    case 'matMul':
      return [tfc.matMul(
          getParamValue('a', node, tensorMap, context) as tfc.Tensor2D,
          getParamValue('b', node, tensorMap, context) as tfc.Tensor2D,
          getParamValue('transposeA', node, tensorMap, context) as boolean,
          getParamValue('transposeB', node, tensorMap, context) as boolean)];
    case 'transpose':
      return [tfc.transpose(
          getParamValue('x', node, tensorMap, context) as tfc.Tensor,
          getParamValue('perm', node, tensorMap, context) as number[])];

    default:
      throw TypeError(`Node type ${node.op} is not implemented`);
  }
};
開發者ID:oveddan,項目名稱:tfjs-converter,代碼行數:19,代碼來源:matrices_executor.ts


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