keras中的K.concatenate()详解
keras中concatenate源代码如下:
def concatenate(tensors, axis=-1):"""Concatenates a list of tensors alongside the specified axis.# Argumentstensors: list of tensors to concatenate.axis: concatenation axis.# ReturnsA tensor."""if axis < 0:rank = ndim(tensors[0])if rank:axis %= rankelse:axis = 0if py_all([is_sparse(x) for x in tensors]):return tf.sparse_concat(axis, tensors)else:return tf.concat([to_dense(x) for x in tensors], axis)
可以看出keras的concatenate()函数是披了外壳的tf.concat()。不过用法没有tf.concat()那么复杂。对tf.concat()解释可以看我的另一篇博文《tf.concat()详解》,如果只想了解concatenate的用法,可以不用移步。
axis=n表示从第n个维度进行拼接,对于一个三维矩阵,axis的取值可以为[-3, -2, -1, 0, 1, 2]。虽然keras用模除允许axis的取值可以在这个范围之外,但不建议那么用。
可以通过如下小段代码来理解:
import numpy as np
import cv2
import keras.backend as K
import tensorflow as tft1 = K.variable(np.array([[[1, 2], [2, 3]], [[4, 4], [5, 3]]]))
t2 = K.variable(np.array([[[7, 4], [8, 4]], [[2, 10], [15, 11]]]))
d0 = K.concatenate([t1 , t2] , axis=-2)
d1 = K.concatenate([t1 , t2] , axis=1)
d2 = K.concatenate([t1 , t2] , axis=-1)
d3 = K.concatenate([t1 , t2] , axis=2)init = tf.global_variables_initializer()
with tf.Session() as sess:sess.run(init)print(sess.run(d0))print(sess.run(d1))print(sess.run(d2))print(sess.run(d3))
axis=-2,意思是从倒数第2个维度进行拼接,对于三维矩阵而言,这就等同于axis=1。
axis=-1,意思是从倒数第1个维度进行拼接,对于三维矩阵而言,这就等同于axis=2。
输出如下:
d0:
[[[ 1. 2.][ 2. 3.][ 7. 4.][ 8. 4.]][[ 4. 4.][ 5. 3.][ 2. 10.][ 15. 11.]]]d1:
[[[ 1. 2.][ 2. 3.][ 7. 4.][ 8. 4.]][[ 4. 4.][ 5. 3.][ 2. 10.][ 15. 11.]]]d2:
[[[ 1. 2. 7. 4.][ 2. 3. 8. 4.]][[ 4. 4. 2. 10.][ 5. 3. 15. 11.]]]d3:
[[[ 1. 2. 7. 4.][ 2. 3. 8. 4.]][[ 4. 4. 2. 10.][ 5. 3. 15. 11.]]]
keras中的K.concatenate()详解相关推荐
- Keras中Dropout的用法详解
本文借鉴整理三篇文章,比较全面的用法总结了,看完本文无需再查阅其他资料 一.Keras 中使用 Dropout 正则化减少过度拟合 Dropout正则化是最简单的神经网络正则化方法.其原理非常简单粗暴 ...
- 神经网络学习小记录58——Keras GhostNet模型的复现详解
神经网络学习小记录58--Keras GhostNet模型的复现详解 学习前言 什么是GhostNet模型 源码下载 GhostNet模型的实现思路 1.Ghost Module 2.Ghost Bo ...
- java中Freemarker list指令详解
java Freemarker中list指令主要是进行迭代服务器端传递过来的List集合. 定义 <#list nameList as names> ${names} </#list ...
- c++ memset 语言_C++中memset函数用法详解
本文实例讲述了C++中memset函数用法.分享给大家供大家参考,具体如下: 功 能: 将s所指向的某一块内存中的每个字节的内容全部设置为ch指定的ASCII值,块的大小由第三个参数指定,这个函数通常 ...
- mysql in从数据库取数_MySQL数据库中 where in 用法详解
本文主要向大家介绍了MySQL数据库中 where in 用法详解,通过具体的内容向大家展现,希望对大家学习MySQL数据库有所帮助. 这里分两种情况来介绍 WHERE column IN (valu ...
- smarty手册-smarty中foreach循环语句详解
原文地址:smarty手册-smarty中foreach循环语句详解作者:谭博 {foreach}循环也有自身属性的变量,可以通过{$smarty.foreach.name.property}访问,其 ...
- JS中的event 对象详解
JS中的event 对象详解 JS的event对象 Event属性和方法: 1. type:事件的类型,如onlick中的click: 2. srcElement/target:事件源,就是发生事件的 ...
- mysql中 where in 用法详解
https://blog.csdn.net/haibo0668/article/details/52584307 sssss mysql中 where in 用法详解 我是高手高手高高手 2016-0 ...
- linux bin fuser,Linux中fuser命令用法详解
描述: fuser可以显示出当前哪个程序在使用磁盘上的某个文件.挂载点.甚至网络端口,并给出程序进程的详细信息. fuser显示使用指定文件或者文件系统的进程ID. 默认情况下每个文件名后面跟一个字母 ...
最新文章
- (十二)企业级java springcloud b2bc商城系统开源源码二次开发-断路器监控(Hystrix Dashboard)...
- 在windows10中安装 linux ubuntu 子系统
- 深度学习论文阅读路线图
- 在windows中python安装sit-packages路径位置 在Pycharm中导入opencv不能自动代码补全问题
- iOS开发 贝塞尔曲线UIBezierPath
- 1352. 虫洞【难度: 中 / 枚举 判环】
- sparkstreaming监听hdfs目录_flume kafka和sparkstreaming整合
- 加入域时遇到“找不到网络路径”错误解决办法汇总
- 使用 cf push 部署应用到 SAP BTP 后启动失败 start unsuccessful 该如何处理
- 信息收集——Web目录扫描
- python3seek_Python seek()和tell()函数详解
- powershell some check
- Python版常见的排序算法
- 中国磷矿市场趋势报告、技术动态创新及市场预测
- Android9.0删除高通ADsp固件(二十六)
- 一步快速将Smartform转成生成PDF文件
- 快速开发:普元EOS平台简介
- spring boot 请求转发和重定向
- Ardupilot多旋翼自动规划路径实现绕开障碍物避障
- JS之如何判断数据类型