![](https://img-blog.csdnimg.cn/20201014180756922.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
TensorFlow
文章平均质量分 76
tf2.0 教程
识醉沉香
渣渣一枚
展开
-
一、数据加载
1. NumPy dataLoad NumPy arrays with tf.data.DatasetBATCH_SIZE=64SHUFFLE_BUFFER_SIZE=1000# 构建训练集、测试集迭代器train_dataset=tf.data.Dataset.from_tensor_slices((train_examples,train_labels)).\shuffle(SHUFFLE_BUFFER_SIZE).batch(BATCH_SIZE)test_dataset=tf.da原创 2022-01-29 17:48:44 · 1610 阅读 · 1 评论 -
二、特征数据预处理
目录1. 数据加载1.1 Numpy数据1.2 CSV 格式1.2 使用pandas读取数据1.2.1 加载数据集1.2.1 使用tf.data.Dataset 读区数据1. 数据加载1.1 Numpy数据使用 tf.data.Dataset 加载Numpy数据,将(feature_array,label_array)两个数组作为元组传递给tf.data.Dataset.from_tensor_slices以创建tf.data.DatasetBATCH_SIZE=64SHUFFLE_BUFFER_原创 2022-05-22 14:36:02 · 428 阅读 · 0 评论 -
三、构建模型
Sequential modelA Sequential model is appropriate for a plain stack of layerswhere each layer has exactly one input tensor and one output tensor.import tensorflow as tffrom tensorflow import kerasfrom tensorflow.keras import layers# 方法1: You can cre原创 2022-01-29 15:21:02 · 653 阅读 · 0 评论 -
四、模型训练和评估
1. 使用内建方法训练评估模型Model.fit(), Model.evaluate() and Model.predict()构建模型inputs = keras.Input(shape=(784,), name="digits")x = layers.Dense(64, activation="relu", name="dense_1")(inputs)x = layers.Dense(64, activation="relu", name="dense_2")(x)outputs = la原创 2022-01-29 16:21:55 · 1431 阅读 · 0 评论 -
五、模型保存
Tensorflow Model 模型保存的两种方式Checkpoints:只保存模型的参数,不保存模型的训练过程使用 tf.keras.Model.save_weights使用 tf.train.Checkpoint() 或者 tf.train.CheckpointManager()SavedModel format,保存完整的tensorflow程序,适用于模型部署 tensorflow servingtf.saved_modeltf.keras.Model构建模型imp原创 2022-01-29 16:29:36 · 1198 阅读 · 1 评论 -
tensor and operation
TensorsA Tensor is a multi-dimensional array. Similar to NumPy ndarray objects。维度:一维直接写个数,二维使用【行,列】 多维 [n,m,k,…]1. 创建张量# 1. tf.constant(张量内容,dtype=数据类型(可选)) a = tf.constant(4)b = tf.constant([1,5],dtype=tf.int32) c = tf.constant([[1, 2],原创 2022-01-29 14:52:28 · 559 阅读 · 0 评论 -
variable
Create a variableimport tensorflow as tfmy_tensor = tf.constant([[1.0, 2.0], [3.0, 4.0]])my_variable = tf.Variable(my_tensor)# You can reassign the tensor using tf.Variable.assign。a = tf.Variable([2.0, 3.0])a.assign([1, 2]) # This will keep the sa原创 2022-01-29 20:01:46 · 319 阅读 · 0 评论