Tensorflow如何用于使用Python遍历数据集并显示示例数据?
Tensorflow是Google提供的一种机器学习框架。它是一个开放源代码框架,可与Python结合使用,以实现算法,深度学习应用程序等等。它用于研究和生产目的。它具有优化技术,可帮助快速执行复杂的数学运算。这是因为它使用了NumPy和多维数组。这些多维数组也称为“张量”。该框架支持使用深度神经网络。它具有高度的可扩展性,并带有许多流行的数据集。它使用GPU计算并自动进行资源管理。它带有大量的机器学习库,并且得到了良好的支持和记录。该框架具有运行深度神经网络模型,对其进行训练,
可以使用下面的代码行在Windows上安装'tensorflow'软件包-
pip install tensorflow
Tensor是TensorFlow中使用的数据结构。它有助于连接流程图中的边缘。该流程图称为“数据流程图”。张量不过是多维数组或列表。可以使用三个主要属性来标识它们-
等级-讲述张量的维数。可以理解为张量的顺序或已定义的张量中的维数。
类型-它告诉与张量元素关联的数据类型。它可以是一维,二维或n维张量。
形状-它是行和列的总数。
我们正在使用Google合作实验室来运行以下代码。GoogleColab或Colaboratory可以帮助通过浏览器运行Python代码,并且需要零配置和对GPU(图形处理单元)的免费访问。合作已建立在JupyterNotebook的基础上。
示例
print("Iterating through the training data") for i, label in enumerate(raw_train_ds.class_names): print("Label", i, "maps to", label) print("The training parameters have been defined") raw_val_ds = preprocessing.text_dataset_from_directory( train_dir, batch_size=batch_size, validation_split=0.25, subset='validation', seed=seed) print("The test dataset is being prepared") test_dir = dataset_dir/'test' raw_test_ds = preprocessing.text_dataset_from_directory( test_dir, batch_size=batch_size)
代码信用-https://www.tensorflow.org/tutorials/load_data/text
输出结果
Iterating through the training data Label 0 maps to csharp Label 1 maps to java Label 2 maps to javascript Label 3 maps to python The training parameters have been defined Found 8000 files belonging to 4 classes. Using 2000 files for validation. The test dataset is being prepared Found 8000 files belonging to 4 classes.
解释
迭代训练数据。
培训,测试和验证集的行数显示在控制台上。
使用“text_dataset_from_directory”实用程序对数据进行预处理。