Tensorflow如何用于导出使用Python构建的模型?

Tensorflow是Google提供的一种机器学习框架。它是一个开放源代码框架,与Python结合使用以实现算法,深度学习应用程序等等。它用于研究和生产目的。

它具有优化技术,可帮助快速执行复杂的数学运算。

这是因为它使用了NumPy和多维数组。这些多维数组也称为“张量”。该框架支持使用深度神经网络。它具有高度的可扩展性,并带有许多流行的数据集。它使用GPU计算并自动进行资源管理。它带有大量的机器学习库,并且得到了良好的支持和记录。该框架具有运行深度神经网络模型,对其进行训练以及创建可预测各个数据集相关特征的应用程序的能力。

可以使用下面的代码行在Windows上安装'tensorflow'软件包-

pip install tensorflow

Tensor是TensorFlow中使用的数据结构。它有助于连接流程图中的边缘。该流程图称为“数据流程图”。张量不过是多维数组或列表。

我们正在使用Google合作实验室来运行以下代码。Google Colab或Colaboratory可以帮助通过浏览器运行Python代码,并且需要零配置和对GPU(图形处理单元)的免费访问。合作已建立在Jupyter Notebook的基础上。

示例

以下是代码片段-

print("The model is being exported")
export_model = tf.keras.Sequential(
   [binary_vectorize_layer, binary_model,
   layers.Activation('sigmoid')])
print("The model is being compiled")
export_model.compile(
   loss=losses.SparseCategoricalCrossentropy(from_logits=False),
   optimizer='adam',
   metrics=['accuracy'])
print("The model is being tested with `raw_test_ds`, which resuls in raw strings")
loss, accuracy = export_model.evaluate(raw_test_ds)
print("The accuracy of the model is : {:2.2%}".format(binary_accuracy))

代码信用-https://www.tensorflow.org/tutorials/load_data/text

输出结果

The model is being exported
The model is being compiled
The model is being tested with `raw_test_ds`, which resuls in raw strings
250/250 [==============================] - 4s 13ms/step - loss: 0.5296 - accuracy: 0.8078
The accuracy of the model is : 81.10%

解释

  • 将“ TextVectorization”层应用于数据集,然后再将其馈送到模型。

  • 如果模型需要处理原始字符串,则可以在模型内部应用“ TextVectorization”层。

  • 为此,借助训练期间使用的权重创建了一个新模型。

猜你喜欢