TensorFlow函数(九)tf.add_to_collection()、tf.get_collection() 和 tf.add_n()

tf.add_to_collection(name, value)

此函数将元素添加到列表中

参数:

  • name:列表名。如果不存在,创建一个新的列表
  • value:元素

tf.get_collection(name)

此函数获取列表

参数:

  • name:列表名

tf.add_n(inputs)

此函数将元素相加并返回

注意:元素类型必须一致,否者报错

1 tf.add_to_collection(‘losses‘, regularizer(weights))
2 tf.add_n(tf.get_collection(‘losses‘))

原文地址:https://www.cnblogs.com/reaptomorrow-flydream/p/9492550.html

时间: 2024-08-30 11:59:30

TensorFlow函数(九)tf.add_to_collection()、tf.get_collection() 和 tf.add_n()的相关文章

tensorflow函数

TensorFlow 将图形定义转换成分布式执行的操作, 以充分利用可用的计算资源(如 CPU 或 GPU.一般你不需要显式指定使用 CPU 还是 GPU, TensorFlow 能自动检测.如果检测到 GPU, TensorFlow 会尽可能地利用找到的第一个 GPU 来执行操作. 并行计算能让代价大的算法计算加速执行,TensorFlow也在实现上对复杂操作进行了有效的改进.大部分核相关的操作都是设备相关的实现,比如GPU.下面是一些重要的操作/核: 操作组 操作 Maths Add, Su

Tensorflow 函数学习笔记

## tf.Variable(??)    创建tf变量 ## tf.matmul(w,x)       矩阵乘法 w = tf.Variable([[0.5,1.0]]) x = tf.Variable([[2.0],[1.0]]) y = tf.matmul(w, x) init_op = tf.global_variables_initializer() with tf.Session() as sess: sess.run(init_op) print (y.eval()) #tf中显示

tf.contrib.rnn.static_rnn与tf.nn.dynamic_rnn区别

tf.contrib.rnn.static_rnn与tf.nn.dynamic_rnn区别 https://blog.csdn.net/u014365862/article/details/78238807 MachineLP的Github(欢迎follow):https://github.com/MachineLP 我的GitHub:https://github.com/MachineLP/train_cnn-rnn-attention 自己搭建的一个框架,包含模型有:vgg(vgg16,vg

【Tensorflow】(tf.Graph)和(tf.session)

图(tf.Graph):计算图,主要用于构建网络,本身不进行任何实际的计算. 会话(tf.session):会话,主要用于执行网络.所有关于神经网络的计算都在这里进行,它执行的依据是计算图或者计算图的一部分,同时,会话也会负责分配计算资源和变量存放,以及维护执行过程中的变量. Tensorflow的几种基本数据类型: tf.constant(value, dtype=None, shape=None, name='Const', verify_shape=False) tf.Variable(i

【tensorflow】在 Ubuntu/Linux 环境下安装TF遇到的问题 [Errno 13] Permission denied

环境:Ubuntu虚拟机 / python2.7 按照官网安装: $ pip install https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.5.0-cp27-none-linux_x86_64.whl 提示:Could not install packages due to an Environment Error: [Errno 13] Permission denied: “...balabal” 解决方案:

tensorflow零起点快速入门(6) --np与tf

numpy.random.uniform np.random.rand 原文地址:https://www.cnblogs.com/bai2018/p/12133993.html

tensorflow函数介绍(3)

tf.nn.softmax_cross_entropy_with_logits(logits,labels) #其中logits为神经网络最后一层输出,labels为实际的标签,该函数返回经过softmax转换之后并与实际值相比较得到的交叉熵损失函数的值,该函数返回向量 例: import tensorflow as tf logits=tf.constant([[1.0,2.0,3.0],[1.0,2.0,3.0],[1.0,2.0,3.0]]) y=tf.nn.softmax(logits)

tensorflow函数介绍(4)

队列的实现: import tensorflow as tf q=tf.FIFOQueue(2,'int32') #创建一个先进先出队列,指定队列中最多可以保存两个元素,并指定类型为整数. init=q.enqueue_many(([0,10],)) #初始化队列中的元素 x=q.dequeue() y=x+1 #将加1后的值再重新加入队列 q_inc=q.enqueue([y]) with tf.Session() as sess: init.run() for _ in range(5):

TensorFlow函数(六)初始值生成函数

1.常量生成函数 tf.constant(value, dtype) 生成一个初始值为常量value的数组 value:指定的常量 dtype:数据类型 tf.zeros(shape, dtype) 生成一个形状为shape.初始值全为0的数组 tf.ones(shape, dtype) 生成一个形状为shape.初始值全为1的数组 2.初始化为正太分布 tf.random_normal(shape, mean, stddev, seed, dtype) 生成一组符合标准正态分布的数组 shap