tensorflow中 tf.reduce_mean函数
tf.reduce_mean 函数用于计算张量tensor沿着指定的数轴(tensor的某一维度)上的的平均值,主要用作降维或者计算tensor(图像)的平均值。
reduce_mean(input_tensor,
axis=None,
keep_dims=False,
name=None,
reduction_indices=None)
- 第一个参数input_tensor: 输入的待降维的tensor;
- 第二个参数axis: 指定的轴,如果不指定,则计算所有元素的均值;
- 第三个参数keep_dims:是否降维度,设置为True,输出的结果保持输入tensor的形状,设置为False,输出结果会降低维度;
- 第四个参数name: 操作的名称;
- 第五个参数 reduction_indices:在以前版本中用来指定轴,已弃用;
以一个维度是2,形状是[3,3]的tensor举例:
import tensorflow as tf
x = [[1,2,3],
[1,2,3]]
xx = tf.cast(x,tf.float32)
mean_all = tf.reduce_mean(xx, keep_dims=False)
mean_0 = tf.reduce_mean(xx, axis=0, keep_dims=False)
mean_1 = tf.reduce_mean(xx, axis=1, keep_dims=False)
with tf.Session() as sess:
m_a,m_0,m_1 = sess.run([mean_all, mean_0, mean_1])
print m_a # output: 2.0
print m_0 # output: [ 1. 2. 3.]
print m_1 #output: [ 2. 2.]
如果设置保持原来的张量的维度,keep_dims=True ,结果:
print m_a # output: [[ 2.]]
print m_0 # output: [[ 1. 2. 3.]]
print m_1 #output: [[ 2.], [ 2.]]
类似函数还有:
- tf.reduce_sum :计算tensor指定轴方向上的所有元素的累加和;
- tf.reduce_max : 计算tensor指定轴方向上的各个元素的最大值;
- tf.reduce_all : 计算tensor指定轴方向上的各个元素的逻辑和(and运算);
- tf.reduce_any: 计算tensor指定轴方向上的各个元素的逻辑或(or运算);
tensorflow中 tf.reduce_mean函数的更多相关文章
- 【tensorflow基础】tensorflow中 tf.reduce_mean函数
参考 1. tensorflow中 tf.reduce_mean函数: 完
- tensorflow中 tf.train.slice_input_producer 和 tf.train.batch 函数(转)
tensorflow数据读取机制 tensorflow中为了充分利用GPU,减少GPU等待数据的空闲时间,使用了两个线程分别执行数据读入和数据计算. 具体来说就是使用一个线程源源不断的将硬盘中的图片数 ...
- tensorflow中 tf.train.slice_input_producer 和 tf.train.batch 函数
tensorflow数据读取机制 tensorflow中为了充分利用GPU,减少GPU等待数据的空闲时间,使用了两个线程分别执行数据读入和数据计算. 具体来说就是使用一个线程源源不断的将硬盘中的图片数 ...
- 【转载】 tensorflow中 tf.train.slice_input_producer 和 tf.train.batch 函数
原文地址: https://blog.csdn.net/dcrmg/article/details/79776876 ----------------------------------------- ...
- tensorflow中 tf.add_to_collection、 tf.get_collection 和 tf.add_n函数
tf.add_to_collection(name, value) 用来把一个value放入名称是'name'的集合,组成一个列表; tf.get_collection(key, scope=Non ...
- Tensorflow中的run()函数
1 run()函数存在的意义 run()函数可以让代码变得更加简洁,在搭建神经网络(一)中,经历了数据集准备.前向传播过程设计.损失函数及反向传播过程设计等三个过程,形成计算网络,再通过会话tf.Se ...
- TensorFlow:tf.reduce_mean(input_tensor, axis=None, keep_dims=False, name=None, reduction_indices=None)
转载:https://www.cnblogs.com/yuzhuwei/p/6986171.html 1.概述 在深度学习里研究的物体的关系,都是比较复杂的.比如一个图片32X32大小的,它的像素信息 ...
- TensorFlow中的卷积函数
前言 最近尝试看TensorFlow中Slim模块的代码,看的比较郁闷,所以试着写点小的代码,动手验证相关的操作,以增加直观性. 卷积函数 slim模块的conv2d函数,是二维卷积接口,顺着源代码可 ...
- 【TensorFlow】tf.reset_default_graph()函数
转载 https://blog.csdn.net/duanlianvip/article/details/98626111 tf.reset_default_graph函数用于清除默认图形堆栈并重置 ...
随机推荐
- spark2.1.1创建Pipeline
Pipeline 为流程,是Spark创建机器学习的一个流程控制的类 下面直接贴出创建的代码,以及整个流程 第一种: import org.apache.spark.ml.{Pipeline, Pip ...
- (转) SpringBoot非官方教程 | 第二十四篇: springboot整合docker
这篇文篇介绍,怎么为 springboot程序构建一个Docker镜像.docker 是一个开源的应用容器引擎,基于 Go 语言 并遵从Apache2.0协议开源.Docker 可以让开发者打包他们的 ...
- 【PGM】Representation--Knowledge Engineering,不同的模型表示,变量的类型,structure & parameters
Part 1. 重要的区别: Template based vs. specific Directed vs. undirected Generative vs. discrimina ...
- adb shell top 命令
原文地址https://blog.csdn.net/kittyboy0001/article/details/38562515 原文地址https://blog.csdn.net/u010503912 ...
- Preview all adidas NMD Singapore colorways just below
A week ago, we've got a glimpse into adidas NMD Singapore for the future using their Tubular line. O ...
- Thymeleaf使用说明
Thymeleaf使用说明 javascript操作: a.<script type="text/javascript" th:inline="javascript ...
- 1.初步认识JVM -- JVM序列
1.JVM概念 JVM是java Virtual Machine的简称.也称为Java虚拟机. 虚拟机:通过软件模拟具有完整硬件功能的运行在一个完全隔离环境的完整计算机系统.VMWare.Visual ...
- JDBC 连接Oracle 数据库,JDBC 连接Mysql 数据库
首先是JDBC 连接Oracle 数据库 package com.util; import com.pojo.UserInfo; import java.sql.*; public class DB ...
- 20145219《网络对抗》PC平台逆向破解
20145219<网络对抗>PC平台逆向破解 shellcode注入 1.shellcode shellcode是一段代码,溢出后,执行这段代码能开启系统shell. 2.构造方法 (1) ...
- G-Sensor 8452驱动及相关
8452是一款G-Sensor芯片,采用I2C跟主芯片通讯,采用中断方式跟操作系统协作.通过内部检测XYZ三个方向的加速度,实现各种应用. (1)原理框图如下: 现在来实现在WINCE中的I2C驱动, ...