- 博客(61)
- 资源 (23)
- 收藏
- 关注
原创 pytorch1.4+tensorboard不显示graph计算图的问题
电脑安装的pytoch版本为1.4,tensorboard无法显示计算图graph,但可以显示scalar。经过多方查证为pytorch版本问题,目前graph显示仅支持到pytorch1.3。处理如下:(1)卸载当前的pytorch并安装低版本1.3.1版本卸载当前的高版本,cmd中输入:pip uninstall torch安装低版本,采用离线安装的方式。从连接https://...
2020-04-23 22:36:17
1263
1
原创 pytorch: where、gather函数
**一、where函数**torch.where(condition,x,y)out = x,if condition is 1= y ,if condition is 0In [29]: cond = torch.rand(2,2)In [30]: condOut[30]:tensor([[0.1326, 0.4126], [0.7093, 0.5339]])...
2019-10-24 14:42:31
4546
原创 pytorch:属性统计
**一、求范数**torch.norm(p,dim)In [1]: import torchIn [2]: a = torch.full([8],1)In [3]: aOut[3]: tensor([1., 1., 1., 1., 1., 1., 1., 1.])In [4]: b = a.view(2,4)In [5]: bOut[5]:tensor([[1., 1...
2019-10-24 11:44:08
741
原创 pytorch:tensor的运算
**一、加减乘除**torch.add / torch.sub / torch.mul / torch.div分别为矩阵对应元素的加减乘除与使用符号±*/功能相同//表示整除In [1]: import torchIn [2]: a = torch.rand(3,4)In [3]: b = torch.rand(4)In [4]: a+bOut[4]:tensor([...
2019-10-22 14:40:43
2628
原创 pytorch拼接与拆分
**一、拼接**cat/stackcat在指定的维度上进行连接;stack创建了新的维度进行连接。In [1]: import torchIn [2]: a = torch.rand(4,32,8)In [3]: b = torch.rand(5,32,8)In [4]: torch.cat([a,b],dim=0).shapeOut[4]: torch.Size([9,...
2019-10-22 12:38:05
3101
原创 pytorch维度变换
一、view/reshapeIn [1]: import torchIn [2]: a = torch.rand(4,1,28,28)In [3]: a.shapeOut[3]: torch.Size([4, 1, 28, 28])In [4]: a.view(4,28*28)Out[4]:tensor([[0.3060, 0.2680, 0.3763, ..., 0.659...
2019-10-22 11:20:30
529
原创 pytorch的索引与切片
**一、从左边开始索引**In [12]: a = torch.rand(4,3,28,28)In [13]: a.shapeOut[13]: torch.Size([4, 3, 28, 28])In [14]: a[0].shapeOut[14]: torch.Size([3, 28, 28])In [15]: a[0,0].shapeOut[15]: torch.Siz...
2019-10-21 18:06:32
601
原创 pytorch创建tensor
**一、import from numpy**In [40]: a = np.array([2,3.3])In [41]: aOut[41]: array([2. , 3.3])In [42]: b = torch.from_numpy(a)In [43]: bOut[43]: tensor([2.0000, 3.3000], dtype=torch.float64)In...
2019-10-21 16:59:28
2925
原创 pytorch tensor的数据类型
一、维度为0的标量一般用于loss计算In [1]: import torchIn [2]: a = torch.tensor(1.)#维度为0In [3]: b = torch.tensor(1.3)In [4]: c = torch.tensor(2.2)In [5]: a.shape,b.shape,c.shapeOut[5]: (torch.Size([]), tor...
2019-10-21 15:44:26
236
原创 TensorFlow2.0:模型的保存与加载
**一、权重参数的保存与加载**network.save_weights('weights.ckpt')network.load_weights('weights.ckpt')权重参数的保存与加载可以针对任何模型,包括自定义的。但是在加载权重参数时,其模型的结构需要与原来的完全一致。import tensorflow as tffrom tensorflow import ker...
2019-09-11 09:33:28
2875
原创 TensorFlow2.0:自定义层与自定义网络
自定义层函数需要继承layers.Layer,自定义网络需要继承keras.Model。其内部需要定义两个函数:1、__init__初始化函数,内部需要定义构造形式;2、call函数,内部需要定义计算形式及返回值。#self def layerclass MyDense(layers.Layer):#inherit layers.Layer def __init__(self,i...
2019-09-11 08:45:20
3276
原创 TensorFlow2.0:keras.compile与fit的使用
import tensorflow as tffrom tensorflow import kerasfrom tensorflow.keras import layers,datasets,optimizers,Sequential,metricsdef preprocess(x,y): x = tf.cast(x,dtype=tf.float32)/255. x = t...
2019-09-10 16:17:50
2977
原创 TensorFlow2.0: keras.metrics的使用
keras.metrics中有两个api函数可以简化准确率acc和损失值loss的计算。其分别是metrics.Accuracy( )和metrics.Mean( )。一、建立测量尺#建立测量尺acc_meter = metrics.Accuracy()loss_meter = metrics.Mean()二、更新数据loss_meter.update_state(loss)acc...
2019-09-10 15:09:07
8048
2
原创 TensorFlow2.0:tensorboard使用
**一、tensorboard的安装**使用命令pip install tensorboard**二、使用方法**2.1、启动listener在项目所在的目录创建文件夹logs用于存放监听数据使用命令行中定位到项目所在的文件夹,并使用命令tensorboard --logdir logs启用listener使用浏览器输入localhost:6006打开端口2.2、使用代码...
2019-09-10 14:59:04
4409
原创 TensorFlow2.0:单层感知机梯度计算
**一 单层单输出感知机梯度计算**单层感知机指的是输入有多个节点,输出只有一个节点.其实质为二分类,即将样本的多个特征值作为输入,输出为二分类.假设输入有5个样本,每个样本有3个特征参数,样本的标签值为[0,1,0,1,0].那么x的维度为[5,3],y的维度为[5].其中感知机参数设置为:w的维度为[3,1],b的维度为[3].由于为单输出,因此输出层可以使用sigmoid激...
2019-08-22 11:13:30
760
原创 TensorFlow2.0:梯度计算
**一 2阶梯度的计算**将需要计算梯度的变量设置为tf.Variable( ),并将计算函数置于with tf.GradientTape ( ) as tape内.import tensorflow as tfx = tf.Variable(tf.constant([2.]))w = tf.Variable(tf.constant([2.]))b = tf.Variable(t...
2019-08-22 10:46:00
4639
原创 TensorFlow2.0:误差计算
**一 MSE(Mean Square Error)均方误差**In [2]: out = tf.random.normal([5,4]) In [3]: y = tf.constant([1,2,3,0,2]) ...
2019-08-20 12:29:21
965
原创 TensorFlow2.0:常用数据范围压缩函数
**一 tf.nn.relu( )函数**tf.nn.relu( )激活函数可以将小于0的数据变成0,大于0的数据保持不变.In [2]: a = tf.constant([-1,-2,0,1,2]) ...
2019-08-20 10:57:56
948
原创 TensorFlow2.0:高阶操作
**一 tf.where( )函数**tf.where(tensor)当只有一个输入时,输入为布尔型,其返回的是值为True的位置.In [3]: a = tf.random.normal([3,3])#生成3行3列的随机数组 ...
2019-08-19 12:05:12
216
原创 TensorFlow2.0:张量限幅
**一 tf.clip_by_value( )函数**tf.maximum(a,b)返回a和b之间的最大值tf.minimum(a,b)返回a和b之间的最小值tf.clip_by_value(t, clip_value_min, clip_value_max, name=None)限制tensor t中张量的最小值为clip_value_min,张量的最大值为clip_value_max...
2019-08-19 10:51:21
361
原创 TensorFlow2.0:数据的填充与复制
**一 tf.pad( )填充函数**tf.pad(tensor, paddings, mode="CONSTANT", name=None, constant_values=0): paddings参数的设置方法:假设输入tensor有两个维度,则paddings参数设置为paddings = [[a,b],[c,d]]a,b表示为axis=0维度上最前面填充a行,最后面填充b行,...
2019-08-19 10:16:59
1532
原创 TensorFlow2.0:张量排序
一 sort argsort排序tf.sort( )按照升序或者降序对张量进行排序tf.argsort( )按照升序或者降序对张量进行排序,但返回的是索引In [4]: a = tf.range(5) In [5]: a ...
2019-08-19 09:36:54
2169
原创 TensorFlow2.0:张量的合并与分割
**一 tf.concat( ) 函数–合并**In [2]: a = tf.ones([4,35,8]) In [3]: b = tf.ones([2,35,8]) In [4]: c...
2019-08-13 16:40:01
2656
原创 TensorFlow2.0:张量的数学运算
(1)+ - * /(2)** pow square(3) sqrt(4) // %(5) exp log(6)@ matmul(7) linear layerelement-wise: + - * /matrix-wise: @ matmuldim-wise: reduce_mean/max/min/sum**一 + - * / % //运算**+:对应矩阵元素相加...
2019-08-13 10:15:15
4829
原创 TensorFlow2.0:维度变换
**一 reshape函数 重排列**In [1]: import tensorflow as tf In [2]: a = tf.random.normal([4,28,28,3],mean=1,stddev=1) In [3]: a.shap...
2019-08-13 09:29:46
1080
原创 TensorFlow2.0:索引和切片(2)
**一 tf.gather( ) 函数**–tf.gather(params, indices, validate_indices=None, name=None, axis=0)params:待切片的参数indices:取出数据所在的位置axis:指定切片数据所在的维度tf.gather(a,axis=0,indices=[2,3]): 对参数a进行切片, 对维度0进行操作,将维度...
2019-08-13 08:36:15
1063
原创 TensorFlow2.0:创建tensor
**一 从numpy list中得到tensor**—tf.convert_to_tensor()In [1]: import tensorflow as tf In [2]: import numpy as np ...
2019-08-12 16:58:23
264
原创 TensorFlow2.0:索引和切片(1)
**一 基本的索引方式**给定每个维度的索引,直接进行索引In [1]: import tensorflow as tf In [2]: import numpy as np ...
2019-08-12 16:57:50
284
原创 Tensorflow2.0数据类型
**一 Tensorflow的类型**--int, float, double--bool--tringIn [1]: import tensorflow as tf In [2]: import numpy as np ...
2019-08-12 10:06:44
1480
原创 吴恩达RNN编程作业:Character level language model - Dinosaurus land
Welcome to Dinosaurus Island! 65 million years ago, dinosaurs existed, and in this assignment they are back. You are in charge of a special task. Leading biology researchers are creating new breeds of...
2019-08-06 19:08:53
825
原创 吴恩达RNN作业:Building your Recurrent Neural Network - Step by Step
Building your Recurrent Neural Network - Step by StepWelcome to Course 5’s first assignment! In this assignment, you will implement your first Recurrent Neural Network in numpy.Recurrent Neural Netw...
2019-08-06 16:37:06
654
原创 吴恩达CNN作业:Face Recognition for the Happy House
Welcome to the first assignment of week 4! Here you will build a face recognition system. Many of the ideas presented here are from FaceNet. In lecture, we also talked about DeepFace.Face recognition...
2019-08-05 11:20:31
639
吴恩达RNN编程作业:Character level language model - Dinosaurus land
2019-08-06
吴恩达RNN作业:Building your Recurrent Neural Network - Step by Step
2019-08-06
Deep Neural Network Application - Image Classification
2019-07-22
Building your Deep Neural Network - Step by Step
2019-07-22
Planar data classification with one hidden layer
2019-07-22
Logistic Regression as a Neural Network
2019-07-22
Python Basics with Numpy
2019-07-22
吴恩达机器学习ex8
2019-07-22
吴恩达机器学习ex7
2019-07-22
吴恩达机器学习作业ex4
2019-06-04
吴恩达机器学习作业ex3
2019-06-04
吴恩达机器学习作业ex2
2019-06-04
吴恩达机器学习作业ex1
2019-06-04
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人