- 博客(142)
- 资源 (1)
- 收藏
- 关注
原创 tensorflow随笔-条件循环控制(4)
例如非严格语义的示例:在下面的示例中,计数器i的最终值不依赖于x。while_loop可并行地增加计数器,并更新x。#!/usr/bin/env python2# -*- coding: utf-8 -*-import tensorflow as tfimport tensorflow as tfn = 10x = tf.constant(0)c = lambda i, x: i...
2019-04-30 22:55:31 326
原创 tensorflow随笔-条件循环控制(3)
#!/usr/bin/env python2# -*- coding: utf-8 -*-import tensorflow as tfimport collectionsPair = collections.namedtuple('Pair', 'j, k')ijk_0 = (tf.constant(0), Pair(tf.constant(1), tf.constant(2)))...
2019-04-30 20:33:10 308
原创 tensorflow随笔-条件循环控制(2)
tf.count_up_totf.count_up_to(ref,limit,name=None)增加“ref”直到它达到“limit”参数:ref:一个变量,必须是int32, int64类型。必要来自于一个 scalar Variable 节点limit:一个int,如果增加ref在limit之上,将报错 ‘OutOfRange’ 。name: 操作名字(可选)返回:t...
2019-04-30 20:30:56 385
原创 tensorflow随笔-队列(2)
#!/usr/bin/env python2# -*- coding: utf-8 -*-import tensorflow as tfn = 100xQueue=tf.FIFOQueue(100,dtypes=[tf.int32],shapes=[])with tf.Session() as sess: for i in xrange(n): if i...
2019-04-30 20:17:41 295
原创 tensorflow随笔-sigmoid预测
#!/usr/bin/env python2# -*- coding: utf-8 -*-import tensorflow as tfimport ostrainCount=10000inputNodeCount=8validateCount=20sampleCount=100testCount=7outputNodeCount=1g=tf.Graph()with g...
2019-04-30 20:14:41 702
原创 mxnet基础到提高(21)-配置mxnet并运行第一个C++程序
1、从源码安装mxnet$ git clone --recursive https://github.com/apache/incubator-mxnet mxnet$git clone https://github.com/xianyi/OpenBLAS.git
2019-04-30 16:07:24 633
原创 sklearn随笔-归一化(标准化)
class sklearn.preprocessing.Normalizer(norm=’l2’, copy=True)[source]fit(X[, y]) 什么都不做并且返回估计量,但不改变fit_transform(X[, y]) 作用于数据,然后转换它。from sklearn.preprocessing import NormalizerX = [[4, 1, 2, 2], ...
2019-04-30 08:49:33 818
原创 tensorflow随笔-队列(1)
tf.FIFOQueueClass FIFOQueue先进先出的队列属性dtypes队列元素的每个组件的dtypes列表name队列名字基础队列的名称。names队列元素的每个组件的名字列表queue_ref基础队列引用shapes队列元素的每个组件的尺寸列表Methodsinitinit(capacity,dtypes,shapes=None,names...
2019-04-30 08:47:25 273
原创 python3精要(40)-数组与矩阵
import numpy as npimport scipy as spprint(np.zeros((3,2)))#全0数组print(np.array([[1.,2.],[3.,4.]]))print(np.random.rand(2,3))#随机数组print(np.asmatrix(np.eye(4)))#单位数组print(np.arange(12))print(np.ma...
2019-04-30 08:45:12 811
原创 TensorFlow随笔-多分类单层神经网络softmax
#!/usr/bin/env python2# -*- coding: utf-8 -*-import tensorflow as tffrom tensorflow.examples.tutorials.mnist import input_datamnist = input_data.read_data_sets("MNIST_data/", one_hot=True)print...
2019-04-30 08:43:38 553
原创 python3随笔-特征值,特征向量,逆矩阵
import numpy as npx=np.diag((1,2,3))#对角阵print(x)a,b=np.linalg.eig(x)#特征值给a,特征向量给bprint(a)print(b)[[1 0 0][0 2 0][0 0 3]][1. 2. 3.][[1. 0. 0.][0. 1. 0.][0. 0. 1.]]import numpy as npx=np....
2019-04-30 08:43:24 739
原创 tensorflow随笔-训练检查点tf.train.Saver
#!/usr/bin/env python2# -*- coding: utf-8 -*-import tensorflow as tfg1=tf.Graph()with g1.as_default(): with tf.name_scope("input_Variable"): my_var=tf.Variable(1,dtype=tf.f...
2019-04-29 18:53:37 467
原创 tensorflow随笔-读取多个文件
#!/usr/bin/env python2# -*- coding: utf-8 -*-"""读取多个文件"""import tensorflow as tfimport osvalidateCount=10sampleCount=10testCount=10g=tf.Graph()with g.as_default(): def inputFromFi...
2019-04-29 18:53:13 667
原创 tensorflow随笔-tf.no_op
tf.no_optf.no_op(name=None)什么都不做,仅做为点位符使用控制边界。参数:name: 操作名字(可选)Returns:创建的操作#!/usr/bin/env python2# -*- coding: utf-8 -*-import tensorflow as tfx = tf.random_normal([3,5],mean=100)y1=x+x...
2019-04-29 17:45:14 3954
原创 机器学习&AI之c++随笔(1)-配置tensorflow并运行第一个C++程序
1、从源代码安装tensorflow-r1.132、建立目录lx@lx-Lenovo:~/soft/tensorflow-r1.13/tensorflow/cc$ pwd/home/lx/soft/tensorflow-r1.13/tensorflow/cclx@lx-Lenovo:~/soft/tensorflow-r1.13/tensorflow/cc$ mkdir lx_learn...
2019-04-29 17:40:10 389
原创 tensorflow随笔-abs
#!/usr/bin/env python2# -*- coding: utf-8 -*-# TensorFlow and tf.kerasimport tensorflow as tfsess=tf.Session()with sess: x = tf.constant([[-2.25 + 4.75j], [-3.25 + 5.75j]]) print x.eval...
2019-04-29 10:31:49 459
原创 tensorflow随笔-变量
由于tf.Variable() 每次都在创建新对象,所有reuse=True 和它并没有什么关系。对于get_variable(),来说,如果已经创建的变量对象,就把那个对象返回,如果没有创建变量对象的话,就创建一个新的。get_variable()变量必须已经定义过了,而且必须是通过get_variable()定义的,才能设置 reuse=True#!/usr/bin/env python3...
2019-04-29 10:30:47 202
原创 tensorflow随笔-正则化+指数衰减+滑动平均
#!/usr/bin/env python2# -*- coding: utf-8 -*-"""Created on Tue Sep 19 09:42:22 2017@author: myhaspl"""import tensorflow as tffrom tensorflow.examples.tutorials.mnist import input_dataINPUT_N...
2019-04-29 10:29:43 404
原创 mxnet基础到提高(31)-repeat
# -*- coding: utf-8 -*-"""Spyder EditorThis is a temporary script file."""import mxnet as mxx = mx.nd.array([[ 1, 2],[ 3, 4]])print mx.nd.repeat(x, repeats=2) print mx.nd.repeat(x, repeat...
2019-04-29 10:28:46 375
原创 tensorflow随笔-tf.group
tf.grouptf.group(*inputs,**kwargs)创建一个操作,组合多操作。当该操作完成后,在inputs的所有操作完成,该操作没有输出。参数:*inputs: 需要组合的零或多个tensorsname: 操作符的名字(可选)返回:一个操作符,能处理所有输入Raises:ValueError: 如果提供了unknown关键参数。#!/usr/bin/e...
2019-04-29 10:28:06 328
原创 python3随笔-梯度下降法
梯度下降是迭代法的一种,可以用于求解最小二乘问题(线性和非线性都可以)。在求解机器学习算法的模型参数,即无约束优化问题时,梯度下降(Gradient Descent)是最常采用的方法之一,另一种常用的方法是最小二乘法。在求解损失函数的最小值时,可以通过梯度下降法来一步步的迭代求解,得到最小化的损失函数和模型参数值。反过来,如果我们需要求解损失函数的最大值,这时就需要用梯度上升法来迭代了。在机器学习...
2019-04-29 10:27:23 470
原创 tensorflow随笔-矩阵乘法
#!/usr/bin/env python3# -*- coding: utf-8 -*-"""Created on Wed Dec 12 18:18:06 2018@author: myhaspl"""import tensorflow as tf w1=tf.Variable(tf.random_normal([2,5],mean=1.0,stddev=1.0))w2=tf...
2019-04-29 10:25:36 329
原创 pythn3随笔-enumerate()
enumerate() 函数用于将一个可遍历的数据对象(如列表、元组或字符串)组合为一个索引序列,同时列出数据和数据下标,一般用在 for 循环当中。>>>seq = ['one', 'two', 'three']>>>for i, element in enumerate(seq):... print(i, seq[i])... 0 one1...
2019-04-29 10:24:11 104
原创 tensorflow随笔-二分法求解一元方程
tensorflow编程还是比较麻烦~#!/usr/bin/env python2# -*- coding: utf-8 -*-"""Created on Mon Jul 24 08:25:41 2017f(x)=x^3+2*(x^2)-45=0二分法求解一元方程"""import tensorflow as tfdef fp(x): return tf.subtra...
2019-04-29 10:23:39 325
原创 tensorflow随笔-检测浮点数类型check_numerics
参数 ‘tensor’ 要属于以下类型才能通过 bfloat16, float16, float32, float64,返回原tensorflow。否则报InvalidArgument 错误。#!/usr/bin/env python2# -*- coding: utf-8 -*-"""Created on Mon Aug 27 11:16:32 2018@author: myhasp...
2019-04-29 10:22:34 1133
原创 tensorflow随笔-数据需要通过字典输入
# -*- coding: utf-8 -*-import tensorflow as tfw1=tf.Variable(tf.random_normal([2,6],stddev=1))w2=tf.Variable(tf.random_normal([6,1],stddev=1))x=tf.placeholder(dtype=tf.float32,shape=(4,2),name="...
2019-04-28 22:39:52 640
原创 TensorFlow随笔-常量与计算图
>>> import tensorflow as tf>>> node1 = tf.constant(3.0, dtype=tf.float32)>>> node2 = tf.constant(4.0)>>> node3=tf.constant(66)>>> print(node1,node2,nod...
2019-04-28 22:36:38 205
原创 tensorflow随笔-tf.decode_csv
tf.decode_csvtf.decode_csv(records,record_defaults,field_delim=’,’,use_quote_delim=True,name=None,na_value=’’,select_cols=None)将CSV记录转换为张量。每一列映射到一个张量。rfc4180格式预计用于CSV记录。(https://tools.ietf....
2019-04-25 12:00:17 8645 1
原创 tensorflow随笔-tf.while_loop
tf.while_loop(cond,body,loop_vars,shape_invariants=None,parallel_iterations=10,back_prop=True,swap_memory=False,name=None,maximum_iterations=None,return_same_structure=False)当条件谓词cond为True...
2019-04-25 11:59:26 1842
原创 tensorflow随笔-文件数据读取
# -*- coding:utf-8 -*-import tensorflow as tffn_queue=tf.train.string_input_producer(["winequality-white-test.csv"])reader=tf.TextLineReader(skip_header_lines=1)key,value=reader.read(fn_queue)pri...
2019-04-25 11:56:05 1105 2
原创 tensorflow随笔-读写数据tf.data
模块:tf.data定义在tensorflow/_api/v1/data/init.py输入管道的tf.data.Dataset API模块实验模块:构建输入管道的实验API。类class Dataset:可能是大型的元素集。class FixedLengthRecordDataset: 来自一个或多个二进制文件的固定长度记录的数据集。class Iterator: 表示通过数据集...
2019-04-25 11:55:27 446
原创 tensorflow随笔-条件语句-tf.cond
tf.condtf.cond(pred,true_fn=None,false_fn=None,strict=False,name=None,fn1=None,fn2=None)如果谓词pred是真的返回true_fn(),否则返回false_fn()。有些参数将过时,在未来版本将被移除,指令更新:fn1/fn2 不支持 true_fn/false_fn参数。true_fn ...
2019-04-25 11:54:15 1197
原创 tensorflow随笔-线性拟合以及tensorboard
运行程序,并查看生成的汇总信息[root@VM_0_3_centos learn]# python36 learn1.py2018-12-19 09:22:26.676337: I tensorflow/core/platform/cpu_feature_guard.cc:141] Your CPU supports instructions that this TensorFlow bina...
2019-04-25 11:53:14 508
原创 TensorFlow随笔-四则运算
import tensorflow as tfa=tf.constant([[1,2],[3,4]])b=tf.constant([6,6])result=tf.add(a,b)sess=tf.Session()sess.run(result)array([[ 7, 8], [ 9, 10]], dtype=int32)c=tf.constant([[1,2,3],[...
2019-04-25 11:52:17 565
原创 tensorflow随笔-条件语句-tf.case
tf.casetf.case(pred_fn_pairs,default=None,exclusive=False,strict=False,name=‘case’)创建case操作pred_fn_pairs参数是大小为N的字典或pairs的列表。每对包含一个布尔标量tensor和一个python可调用函数项,当条件为True将返回对应的函数项创建的tensors。在pred_f...
2019-04-23 08:50:07 3061
原创 tensorflow-计算图
#!/usr/bin/env python3# -*- coding: utf-8 -*-"""Created on Sun Dec 23 11:26:04 2018"""import tensorflow as tf#创建图c=tf.constant(0.0)g=tf.Graph()with g.as_default(): c1=tf.constant(0.1) ...
2019-04-23 08:49:03 265
原创 tensorflow随笔-tf.ReaderBase
tf.ReaderBaseClass ReaderBase为不同阅读器类型生成记录的基类。从概念上讲,Reader (阅读器)将字符串“work units”(“工作单元”)转换为records (key, value pairs)(记录(键、值对))。通常“工作单元”是文件名,记录从这些文件的内容中提取。我们希望每个步骤产生一个记录,但是工作单元可以对应许多记录。因此,我们使用队列引入一...
2019-04-23 08:46:25 277
原创 tensorflow随笔 -QueueRunner
使用基于队列的api实现输入管道,属于数据API。从文件中读取记录的典型基于队列的管道有以下几个阶段:1.文件名列表2.可选的文件名洗牌式重排3.可选的epoch限制4.文件名队列5.文件格式的阅读器6.一种×××,供读者阅读记录7.可选的预处理8.例子队列文件名、变换和epoch限制对于文件名列表,可以使用常量字符串张量(如[“file0”, “file1”]或[(“fil...
2019-04-23 08:45:07 331
原创 tensorflow-tf.nn.conv2d卷积运算(3)
#!/usr/bin/env python2# -*- coding: utf-8 -*-"""Created on Tue Oct 2 13:23:27 2018@author: xxxxxxx@email:xxxxxxx@xxxxxxx.comtf.nn.conv2d"""import tensorflow as tfg=tf.Graph()with g.as_d...
2019-04-22 16:14:16 481
原创 C指针原理(47)-C应用技巧(2)
委托模型,即有一个BOSS线程,就是主线程,产生woker线程,boss线程和worker线程并发执行。BOSS线程的主要任务是创建worker线程,将工作线程放入队列中,当有工作可处理时,唤醒 工作线程。/ Create a new thread, starting with execution of START-ROUTINE getting passed ARG. Creation at...
2019-04-22 16:12:07 313
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人