
TensorFlow
TensorFlow学习笔记
Michael阿明
两个孩子的父亲,机械工程师,准备转行人工智能方向,一起加油吧!高举智慧,她就使你高升;怀抱智慧,她就使你尊荣。-- 箴言(4:8)
-
原创 TensorFlow 2.0 - Hub 模型复用
文章目录1. tfhub2. 例子:神经风格转换3. retrain 例子学习于:简单粗暴 TensorFlow 21. tfhub网址:https://hub.tensorflow.google.cn/https://tfhub.dev/可以搜索,下载模型安装包 pip install tensorflow-hubimport tensorflow_hub as hubhub_url = 'https://hub.tensorflow.google.cn/google/m2021-02-05 00:09:2074
2
-
原创 TensorFlow 2.0 - tf.distribute 分布式训练
文章目录1. 单机多卡 MirroredStrategy2. 多机训练 MultiWorkerMirroredStrategy学习于:简单粗暴 TensorFlow 21. 单机多卡 MirroredStrategy# 分布式训练import tensorflow as tfimport tensorflow_datasets as tfds# 1 单机多卡 MirroredStrategystrategy = tf.distribute.MirroredStrategy()# 指定设备2021-02-03 23:51:2670
1
-
原创 用Docker部署TensorFlow Serving服务
文章目录1. 安装 Docker2. 使用 Docker 部署参考:https://tensorflow.google.cn/tfx/serving/docker1. 安装 Docker参考文章:docker安装等操作2. 使用 Docker 部署2021-02-03 19:15:4575
1
-
原创 TensorFlow 2.0 - tf.saved_model.save 模型导出
文章目录1. tf.saved_model.save2. Keras 模型导出学习于:简单粗暴 TensorFlow 21. tf.saved_model.savetf.train.Checkpoint 可以保存和恢复模型中参数的权值导出模型:包含参数的权值,计算图无须源码即可再次运行模型,适用于模型的分享、部署注意:继承 tf.keras.Model 的模型,一些方法需要是计算图模式,比如 call() 方法必须用 @tf.function 修饰class MLPmodel(tf.2021-02-02 00:20:18108
0
-
原创 TensorFlow 2.0 - TFRecord存储数据集、@tf.function图执行模式、tf.TensorArray、tf.config分配GPU
文章目录1. TFRecord 格式存储2. tf.function 高性能3. tf.TensorArray 支持计算图特性4. tf.config 分配GPU学习于:简单粗暴 TensorFlow 21. TFRecord 格式存储使用该种格式,更高效地进行大规模的模型训练import randomimport osimport tensorflow as tf# 使用前一节 kaggle 上的 猫狗数据集train_data_dir = "./dogs-vs-cats/trai2021-02-01 22:47:3486
1
-
原创 TensorFlow 2.0 - tf.data.Dataset 数据预处理 & 猫狗分类
文章目录1. tf.data1.1 数据集建立1.2 数据集预处理1.3 并行处理1.4学习于:简单粗暴 TensorFlow 21. tf.data1.1 数据集建立tf.data.Dataset.from_tensor_slices()import matplotlib.pyplot as plt(train_data, train_label), (_, _) = tf.keras.datasets.mnist.load_data()train_data = np.expand_dims2021-01-31 20:35:20183
3
-
原创 TensorFlow 2.0 - Checkpoint 保存变量、TensorBoard 训练可视化
文章目录学习于:简单粗暴 TensorFlow 22021-01-28 22:59:16121
1
-
原创 TensorFlow 2.0 - Keras Pipeline、自定义Layer、Loss、Metric
文章目录1. Keras Sequential / Functional API2. 自定义 layer3. 自定义 loss4. 自定义 评估方法学习于:简单粗暴 TensorFlow 21. Keras Sequential / Functional APItf.keras.models.Sequential([layers...]),但是它不能表示更复杂的模型mymodel = tf.keras.models.Sequential([ tf.keras.layers.Flatten2021-01-27 22:37:5980
1
-
原创 TensorFlow 2.0 - CNN / 预训练 / RNN
文章目录1. CNN 卷积神经网络2. 预训练模型学习于:简单粗暴 TensorFlow 21. CNN 卷积神经网络卷积神经网络,卷积后尺寸计算# CNN 模型class myCNN(tf.keras.Model): def __init__(self): super().__init__() self.conv1 = tf.keras.layers.Conv2D( filters=32, kernel_si2021-01-26 23:31:5695
0
-
原创 TensorFlow 2.x GPU版在conda虚拟环境下安装步骤
先下载安装驱动:https://www.nvidia.cn/Download/index.aspx?lang=cn下载安装 anaconda,管理虚拟环境:https://www.anaconda.com/products/individual,并换国内的源,加速后面下载包打开 conda 命令行,conda create -n env_name python=3.7,or 自定义路径 conda create --prefix=D:\yourpath\tf2 python=3.7激活创建的虚拟环境.2021-01-26 11:27:36104
0
-
原创 TensorFlow 2.0 - 自定义模型、训练过程
文章目录1. 自定义模型2. 学习流程学习于:简单粗暴 TensorFlow 21. 自定义模型重载 call() 方法,pytorch 是重载 forward() 方法import tensorflow as tfX = tf.constant([[1.0, 2.0, 3.0],[4.0, 5.0, 6.0]])y = tf.constant([[10.0],[20.0]])class Linear(tf.keras.Model): def __init__(self):2021-01-23 20:16:2491
0
-
原创 TensorFlow 2.0 - 张量/自动求导/梯度下降
文章目录1. 张量2. 自动求导、梯度下降学习于:简单粗暴 TensorFlow 21. 张量import tensorflow as tfprint(tf.__version__) # 2.3.1random_float = tf.random.uniform(shape=())# tf.Tensor(0.80420315, shape=(), dtype=float32)zero_vec = tf.zeros(shape=(2))# tf.Tensor([0. 0.], shape=(2021-01-19 21:57:1377
0