
TensorFlow
深度学习
廷益--飞鸟
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
tensorflow与pytorch GPU版本安装
tensorflow 版本与 cuda对应对应链接pythorch对应链接总结:cuda版本 10.1tensorflow_gpu 版本 2.1.0pythorch 版本 1.6.0cuda的安装1、官网安装就不介绍了2、conda安装 牛大神链接安装就完事了conda install cudatoolkit=10.1安装pytorchpip install torch==1.6.0 torchvision==0.6.1 -f https://download.pyt原创 2021-07-15 14:00:21 · 248 阅读 · 0 评论 -
Tensorflow yolov4 的处理流程
原创 2021-04-24 11:22:50 · 251 阅读 · 0 评论 -
Tesorflow2.0 全连接层(Dense)
具体代码import sysimport matplotlib as mplimport numpy as npimport pandas as pdimport sklearnimport tensorflow as tffrom tensorflow import kerasprint(tf.__version__)print(sys.version_info)for module in mpl, np, pd, sklearn, keras, tf: print(m.原创 2021-04-13 10:33:45 · 534 阅读 · 0 评论 -
Tensorflow2.0 keras 自定义损失函数
关键代码# 自定义损失函数def custom_loss(y_true, y_prd): # mean((y_prd-y_true)** 2) 均方差损失函数 return tf.reduce_mean(tf.square(y_prd - y_true))# 模型的编译 设置损失函数 优化器model.compile(loss=custom_loss, # 使用自定义损失函数 optimizer='sgd', metr原创 2021-04-13 10:08:15 · 1098 阅读 · 2 评论 -
Tensorflow2.0 keras 子类式多输入多输出
1.关键代码在定义好输入层、输出层后使用类 配置inputs outputs参数(数组)网络模型搭建class WideDeepModel(tf.keras.models.Model): def __init__(self): super(WideDeepModel, self).__init__() self.hidden1_layer = tf.keras.layers.Dense(30, activation='relu') self.h.原创 2021-03-09 19:28:54 · 1157 阅读 · 8 评论 -
Tensorflow2.0 keras 函数式多输入多输出
1.关键代码在定义好输入层、输出层后使用类 配置inputs outputs参数(数组)tf.keras.models.Modelmodel = tf.keras.models.Model(inputs=[input_wide, input_deep], outputs=[output1, output2])网络模型搭建# 多输入input_wide = tf.keras.layers.Input(shape=[5]) # .原创 2021-02-24 17:45:11 · 1698 阅读 · 0 评论 -
Tensorflow2.0 keras 模型搭建(函数式、子类式)
模型结构函数式关键代码# 函数式API 功能APIinput = tf.keras.layers.Input(shape=x_train.shape[1:])hidden1 = tf.keras.layers.Dense(30, activation='relu')(input)hidden2 = tf.keras.layers.Dense(30, activation='relu')(hidden1)concat = tf.keras.layers.concatenate([input,.原创 2021-02-22 10:18:35 · 891 阅读 · 9 评论 -
Tensorflow2.0 keras 回调函数
回调函数1、Tensorboard 查看过程数据tf.keras.callbacks.TensorBoard(日志保存路径)# 创建保存文件夹log_dir = os.path.join('callbacks')if not os.path.exists(log_dir): os.mkdir(log_dir)# 设置保存文件夹callbacks = [ tf.keras.callbacks.TensorBoard(log_dir)]详细使用过程使用过程2、Earlysto原创 2021-02-03 16:06:21 · 223 阅读 · 0 评论 -
Tensorflow 对比pytorch
1、pythonx = 0.0y = 1.0for iteration in range(50): x = x + y y = y / 2print(x)2、tensorflow1.13""" tensorflow与pytorch对比"""import tensorflow as tfimport keras.backend as K# 设置自增长config = tf.ConfigProto()config.gpu_options.allow_gr原创 2021-01-27 16:10:10 · 302 阅读 · 1 评论 -
Tensorflow2.0 无监督学习AVE
Auto Encoder的升级版import numpy as npimport tensorflow as tffrom PIL import Imageprint(tf.__version__)print(np.__version__)# 自增长gpus = tf.config.experimental.list_physical_devices('GPU')print(gpus)for gpu in gpus: tf.config.experimental.set_mem原创 2021-01-11 15:26:13 · 1124 阅读 · 0 评论 -
Tensorflow2.0 无监督学习自编码Auto Encoder
具体实现:import osimport numpy as npimport tensorflow as tffrom PIL import Imageprint(tf.__version__)print(np.__version__)# 自增长gpus = tf.config.experimental.list_physical_devices('GPU')print(gpus)for gpu in gpus: tf.config.experimental.set_me.原创 2021-01-06 15:30:12 · 512 阅读 · 0 评论 -
Tensorflow2.0 循环神经网络 LSTM与GRU
LSTMCELL LSTM循环神经网络单元有两个记忆参数self.state0 = [tf.zeros([batch_size, units]), tf.zeros([batch_size, units])] # 层1 记忆参数import numpy as npimport tensorflow as tffrom tensorflow import kerasprint(tf.__version__, np.__version__)# 设置随机种子tf.random.set_s原创 2020-12-31 15:14:51 · 766 阅读 · 0 评论 -
Tensorflow2.0 循环神经网络 新闻分类
简单循环神经网络import numpy as npimport tensorflow as tffrom tensorflow import kerasprint(tf.__version__, np.__version__)# 设置随机种子tf.random.set_seed(22)tf.random.set_seed(22)# GPU自增长gpus = tf.config.experimental.list_physical_devices('gpu')for gpu in.原创 2020-12-30 15:38:30 · 369 阅读 · 0 评论 -
Tensorflow2.0 循环神经网络单元
单层RNNimport tensorflow as tffrom tensorflow.keras import layers# 模拟输入数据x = tf.random.normal([4, 80, 100])xt0 = x[:, 0, :] # [4, 1, 100] 单个数据# 创建循环神经网络cell = layers.SimpleRNNCell(64)# 初始参数 记忆参数ht0 = [tf.zeros([4, 64])]# 循环网络的输出 out == ht1 (原创 2020-12-28 16:39:51 · 198 阅读 · 0 评论 -
Tensorflow2.0 Resnet18与cifar100
Resnet结构具体代码实现 准确率 42%左右网络结构代码:import tensorflow as tffrom tensorflow.keras import layers, Sequential# 基础卷积单元网络# conv + bn + reluclass BasicBlock(layers.Layer): def __init__(self, filter_num, stride=1): """ :param filter_num:原创 2020-12-07 15:50:53 · 1268 阅读 · 0 评论 -
Tensorflow2.0 正则化操作
正则化操作import tensorflow as tf# GPU设置gpu_list = tf.config.experimental.list_physical_devices("GPU")for gpu in gpu_list: tf.config.experimental.set_memory_growth(gpu, True)# 创建标准化层net = tf.keras.layers.BatchNormalization()# 模拟数据x = tf.random.no原创 2020-12-01 14:13:00 · 1785 阅读 · 0 评论 -
Tensorflow2.0 VGG13与cifar100
VGG13 网络具体代码实现 准确率 37%左右""" cifar100数据集处理 使用 VGG13 网络层"""import osimport tensorflow as tffrom tensorflow.keras import layers, Sequential, datasets, optimizersos.environ["TF_CPP_MIN_LOG_LEVEL"] = "2"tf.random.set_seed(2345)# GPU设置gpu_l原创 2020-11-30 16:52:12 · 432 阅读 · 0 评论 -
Tensorflow2.0 最大池化与上采样
最大池化""" 池化处理 layers.MaxPool2D 上采样处理 layers.UpSampling2D relu处理 layers.ReLU"""import tensorflow as tffrom tensorflow.keras import layersgpu_lst = tf.config.experimental.list_physical_devices("GPU")print("GPU:{}个".format(len(gpu_lst)原创 2020-11-27 13:55:56 · 1549 阅读 · 0 评论 -
Tensorflow2.0 卷积操作
卷积操作""" keras.Conv2D 卷积操作与 tf.nn.Conv2D 卷积操作"""import tensorflow as tffrom tensorflow.keras import layers# 获取物理GPU的个数gpus = tf.config.experimental.list_physical_devices("GPU")for gpu in gpus: # 设置内存增长方式 自增长 tf.config.experimental.se原创 2020-11-27 11:30:30 · 760 阅读 · 0 评论 -
Tensorflow2.0 防止过拟合
防止过拟合的方法增加更多的数据 (代价大)降低模型的复杂度 减小网络层数 正则化Dropout 丢弃数据增强提前结束Regularization 正则化 (weight Decay)权值衰减L1-regularizationL2-regularizationl2_model = keras.models.Sequential([ keras.layers.Dense(16, kernel_regularizer=keras.regularizers.l2(0.001)原创 2020-10-23 16:16:25 · 887 阅读 · 0 评论 -
TensorFlow2.0 模型的保存与加载
模型的保存与加载save/load weights 只保存权值 需要源代码 轻量级save/load entire model 所有的状态保存saved_model 通用模型 所有的信息 不需要源代码 可以使用C++解析方法一:save/load weights 只保存权值# 保存权值model.save_weights("./checkpoints/my_checkpoint")# 加载权值model = create_model() # 重新创建装载模型 model.l原创 2020-10-22 14:26:06 · 1760 阅读 · 0 评论 -
Tensorflow2.0 自定义网络
自定义网络keras.Sequential 容器keras.layers.Layerkeras.ModelKeras.Sequential 容器网络层的搭建model = keras.Sequential([keras.layers.Dense(256, activation="relu"), keras.layers.Dense(128, activation="relu"), kera原创 2020-10-19 13:59:42 · 1127 阅读 · 2 评论 -
Tensorflow2.0 keras 装载与训练
Compile与Fit 快捷训练方法Compile 装载 loss、优化器、 评估指标的选择Fit 训练的流程Evaluate 测试Predict 预测简化前模式# 训练的流程for step, (x_batch, y_batch) in enumerate(db_train): # 前向传播 with tf.GradientTape() as tape: # 前向传播准备 x_batch = tf.reshape(x_batch, (-1,原创 2020-10-15 17:51:05 · 179 阅读 · 0 评论 -
Tensorflow2.0 keras Metrics的基本使用
Metrics的基本使用Metrics 创建并设置数据模式update_state 添加数据result().numpy() 获取结果reset_states 清空数据步骤1 :创建meter 测量值处理acc_meter = metrics.Accuracy() # 正确率的计算loss_meter = metrics.Mean() # 求均值(传入损失值)步骤2 : 更新数据(添加)acc_meter.update_state(y_true, predict) # 正确原创 2020-10-15 17:48:00 · 2340 阅读 · 0 评论 -
Tensorflow2.0 Tensorboard的使用
Tensorflow2.0 Tensorboard的使用import tensorflow as tffrom tensorflow.keras import datasets, layers, optimizers, Sequential, metricsimport datetimefrom matplotlib import pyplot as pltimport io# 图片预处理def pre_process(x, y): x = tf.cast(x, dtype=tf.原创 2020-09-29 11:12:58 · 783 阅读 · 0 评论 -
Tensorflow2.0 梯度下降2D函数优化
梯度下降2D函数优化""" Himmelblau 函数的优化(求最低点)"""import numpy as npimport matplotlib.pyplot as mpfrom mpl_toolkits.mplot3d import Axes3Dimport tensorflow as tf# 函数实现def Himmellblau(x): return (x[0] ** 2 + x[1] - 11) ** 2 + (x[0] + x[1] ** 2 - 7) **原创 2020-09-23 09:52:11 · 263 阅读 · 0 评论 -
Tensorflow2.0 损失函数计算
交叉熵计算(分类)""" 分类问题 损失函数的计算"""import tensorflow as tfimport numpy as np# 交叉熵 值越小 越有价值print("普通函数 计算交叉熵", "--"*30)a = tf.fill([4], 0.25)b = - tf.reduce_sum(a * tf.math.log(a) / tf.math.log(2.0))print(a.numpy(), "--->", b.numpy())a = tf.cons原创 2020-09-21 21:40:41 · 530 阅读 · 0 评论 -
Tensorflow2.0 激活函数的使用
Tensorflow2.0 激活函数的使用sigmoidf(x)=11+e−xf(x) = \frac{1}{1+e^{-x}}f(x)=1+e−x1softmaxS(yi)=eyi∑jneyjS(y_i) = \frac{e^{y_i}}{\sum_{j}^n e^{y_j}}S(yi)=∑jneyjeyi""" 激活函数的使用"""import numpy as npimport tensorflow as tfprint("--" * 40, "sigm原创 2020-09-18 17:11:18 · 324 阅读 · 0 评论 -
Tensorflow2.0 链式法则 梯度
链式法则 梯度计算公式δyδx=δyδuδuδx\frac{\delta y}{\delta x} = \frac{\delta y}{\delta u} \frac{\delta u}{\delta x}δxδy=δuδyδxδu""" 反向传播 链式法则"""import tensorflow as tf# 准备数据x = tf.constant(1.)w1 = tf.constant(2.)b1 = tf.constant(1.)w2 = tf.constan原创 2020-09-18 16:54:44 · 358 阅读 · 0 评论 -
Tensorflow2.0 全连接层
全连接层的基本使用""" 全连接层 -- 简单使用"""import tensorflow as tf# 输入维度[4, 784]x = tf.random.normal((4, 784))# 网络结构 [?, 512] 输入维度确定?net = tf.keras.layers.Dense(units=512)out = net(x)print("输出维度:", out.shape)# 根据矩阵相乘规则 推断出 [784, 512]print("全连接层维度:", net原创 2020-09-17 18:43:11 · 2335 阅读 · 0 评论 -
Tensorflow2.0 感知机梯度计算
单输出感知机 梯度计算""" 单一输出 单层感知机"""import tensorflow as tf# 准备数据x = tf.random.normal([1, 3])w = tf.ones([3, 1])b = tf.ones([1])y = tf.constant([1])# 计算梯度with tf.GradientTape() as tape: tape.watch([w, b]) # 前向传播 y_prob = tf.sigmoid(x @原创 2020-09-17 18:26:59 · 224 阅读 · 0 评论 -
Tensorflow2.0 梯度下降与激活函数
Tensorflow2.0 梯度下降与激活函数""" 梯度下降与激活函数"""import tensorflow as tfprint("==" * 30, "sigmoid")# sigmoid# 原始数据x = tf.linspace(-10.0, 10.0, 10)# 梯度计算with tf.GradientTape() as tape: tape.watch(x) y = tf.sigmoid(x) # 函数处理 grads = tape原创 2020-09-16 15:33:36 · 324 阅读 · 0 评论 -
Tensorflow2.0 梯度下降与损失函数
Tensorflow2.0 梯度下降与损失函数""" 分类问题 梯度下降 下计算损失函数MSE"""import tensorflow as tf# 初始化变量x = tf.random.normal([2, 4])w = tf.random.normal([4, 3])b = tf.zeros([3])y = tf.constant([2, 0])with tf.GradientTape() as tape: tape.watch([w, b]) # 分类问原创 2020-09-16 15:18:48 · 652 阅读 · 0 评论 -
TensorFlow 正反向传播 numpy实现
TensorFlow 正反向传播 numpy实现""" 正反向传播 使用线性回归 y = wx + b"""import numpy as npimport matplotlib.pyplot as mpdef active(x): # sigmoid 函数 return 1 / (1 + np.exp(-x))def forward(x, w): # 前向传播 矩阵相乘 return np.dot(x, w)def backward(x):原创 2020-09-02 16:35:24 · 310 阅读 · 0 评论 -
Tensorflow 1.x 基本使用
常量与会话import tensorflow as tf# 常量的定义a = tf.constant([1.0, 2.0], name="a")b = tf.constant([2.0, 3.0], name="b")# 常量相加print(a)print(b)result = a + bprint(result) # 并没有执行# 使用 Sessionsess = tf.Session()r = sess.run(result)print(r, "\n", type(r原创 2020-09-01 17:02:12 · 497 阅读 · 0 评论 -
TensorFlow2.0 前向传播 -- 测试集正确率统计
TensorFlow2.0 前向传播 – 测试集正确率统计1.导入与设置import tensorflow as tffrom tensorflow import kerasfrom tensorflow.keras import datasetsprint(tf.__version__)2.加载数据集# 加载数据集(x, y), (x_test, y_test) = datasets.mnist.load_data()print(x.shape)print(y.shape)prin原创 2020-07-14 21:57:03 · 1029 阅读 · 0 评论 -
python 文件夹图片重命名
python 文件夹图片重命名import os# 重命名 文件夹/000.jpg 模式def rename(path): file_list = os.listdir(path) print(file_list) count = 0 for item in file_list: src = os.path.join(os.path.abspath(path), item) dst = os.path.join(os.path.a原创 2020-07-06 15:41:33 · 505 阅读 · 0 评论 -
TensorFlow2.0 数组排序 正确率计算(top_k)
import tensorflow as tfimport numpy as npprint(tf.__version__)1.数组排序tf.sort tf.argsort# 创建 0-4的数组 随机打散arry = tf.random.shuffle(tf.range(0, 5))print(ary)# 降序排序 tf.sortarry_sort = tf.sort(arry, direction="DESCENDING")print(arry_sort)# 降序序号 tf原创 2020-06-16 23:07:16 · 1296 阅读 · 0 评论 -
TensorFlow2.0 范数/最大值/最小值/准确度统计
TensorFlow2.0 范数/最大值/最小值/准确度统计import tensorflow as tf import numpy as npprint(tf.__version__)计算范数# tf.norm 2范数a = tf.ones([2, 2])print(tf.norm(a))a = tf.ones([4, 28, 28, 3])print(tf.norm(a))# tf.norm 1 范数a = tf.ones([2, 2])# 2范数 维度1print(t原创 2020-06-15 19:59:15 · 1460 阅读 · 0 评论 -
TensorFlow2.0 前向传播 张量基础的使用
TensorFlow2.0 前向传播 张量基础的使用1.导入与设置import tensorflow as tffrom tensorflow import kerasfrom tensorflow.keras import datasetsprint(tf.__version__)# 使用GPU的 设置# 获取物理GPU的个数gpus = tf.config.experimental.list_physical_devices("GPU") for gpu in gpus:原创 2020-06-10 14:48:12 · 186 阅读 · 0 评论