Tensorflow.js 数据集到张量? [英] Tensorflow.js Dataset to Tensor?

查看:32
本文介绍了Tensorflow.js 数据集到张量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Dataset 中的基础数据示例"存在时,是否有推荐/有效的方法将 tf.data.Dataset 转换为 Tensor代码> 是平面数组吗?

Is there a recommended/efficient way to convert a tf.data.Dataset to a Tensor when the underlying 'data examples' in the Dataset are flat arrays?

我正在使用 tf.data.csv 读取和解析 CSV,但随后想使用 Tensorflow.js Core API 将数据处理为 tf.Tensors.

I am using tf.data.csv to read and parse a CSV but then want to use the Tensorflow.js Core API to process the data as tf.Tensors.

推荐答案

请注意,通常不推荐使用此工作流程,因为具体化主 JavaScript 内存中的所有数据可能不适用于大型 CSV 数据集.

Beware that this workflow is not typically recommended, because materializing all the data in the main JavaScript memory may not work for large CSV datasets.

您可以使用 tf.data.Dataset 对象的 toArray() 方法.例如:

You can use the toArray() method of tf.data.Dataset objects. For example:

  const csvUrl =
'https://storage.googleapis.com/tfjs-examples/multivariate-linear-regression/data/boston-housing-train.csv';

  const csvDataset = tf.data.csv(
     csvUrl, {
       columnConfigs: {
         medv: {
           isLabel: true
         }
       }
     }).batch(4);

  const tensors = await csvDataset.toArray();
  console.log(tensors.length);
  console.log(tensors[0][0]);

这篇关于Tensorflow.js 数据集到张量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆