【592】Keras相关函数说明
-
tf.keras.Input:用于添加输入张量
-
tf.keras.layers.MaxPooling2D:二维最大池化
- tf.keras.layers.BatchNormalization:批量标准化层,在每一个批次的数据中标准化前一层的激活项, 即,应用一个维持激活项平均值接近 0,标准差接近 1 的转换。
-
- tf.keras.layers.Concatenate:按照输入顺序进行连接,axis 的值对应于 shape 的 0、1、2 的位置
import keras from keras.layers import Concatenate import numpy as np x = np.arange(20).reshape(2, 2, 5) x array([[[ 0, 1, 2, 3, 4], [ 5, 6, 7, 8, 9]], [[10, 11, 12, 13, 14], [15, 16, 17, 18, 19]]]) y = np.arange(20, 40).reshape(2, 2, 5) y array([[[20, 21, 22, 23, 24], [25, 26, 27, 28, 29]], [[30, 31, 32, 33, 34], [35, 36, 37, 38, 39]]]) Concatenate(axis=0)([x, y]) # when axis=0, it changes the outmost layer <tf.Tensor: shape=(4, 2, 5), dtype=int64, numpy= array([[[ 0, 1, 2, 3, 4], [ 5, 6, 7, 8, 9]], [[10, 11, 12, 13, 14], [15, 16, 17, 18, 19]], [[20, 21, 22, 23, 24], [25, 26, 27, 28, 29]], [[30, 31, 32, 33, 34], [35, 36, 37, 38, 39]]])> Concatenate(axis=0)([y, x]) <tf.Tensor: shape=(4, 2, 5), dtype=int64, numpy= array([[[20, 21, 22, 23, 24], [25, 26, 27, 28, 29]], [[30, 31, 32, 33, 34], [35, 36, 37, 38, 39]], [[ 0, 1, 2, 3, 4], [ 5, 6, 7, 8, 9]], [[10, 11, 12, 13, 14], [15, 16, 17, 18, 19]]])> Concatenate(axis=1)([x, y]) # when axis=1, it changes the middle layer # column <tf.Tensor: shape=(2, 4, 5), dtype=int64, numpy= array([[[ 0, 1, 2, 3, 4], [ 5, 6, 7, 8, 9], [20, 21, 22, 23, 24], [25, 26, 27, 28, 29]], [[10, 11, 12, 13, 14], [15, 16, 17, 18, 19], [30, 31, 32, 33, 34], [35, 36, 37, 38, 39]]])> Concatenate(axis=1)([y, x]) <tf.Tensor: shape=(2, 4, 5), dtype=int64, numpy= array([[[20, 21, 22, 23, 24], [25, 26, 27, 28, 29], [ 0, 1, 2, 3, 4], [ 5, 6, 7, 8, 9]], [[30, 31, 32, 33, 34], [35, 36, 37, 38, 39], [10, 11, 12, 13, 14], [15, 16, 17, 18, 19]]])> Concatenate(axis=2)([x, y]) # get the same result with # Concatenate(axis=-1)([x, y]) # when axis=-1, it changes the inmost layer # row <tf.Tensor: shape=(2, 2, 10), dtype=int64, numpy= array([[[ 0, 1, 2, 3, 4, 20, 21, 22, 23, 24], [ 5, 6, 7, 8, 9, 25, 26, 27, 28, 29]], [[10, 11, 12, 13, 14, 30, 31, 32, 33, 34], [15, 16, 17, 18, 19, 35, 36, 37, 38, 39]]])> Concatenate(axis=-1)([y, x]) <tf.Tensor: shape=(2, 2, 10), dtype=int64, numpy= array([[[20, 21, 22, 23, 24, 0, 1, 2, 3, 4], [25, 26, 27, 28, 29, 5, 6, 7, 8, 9]], [[30, 31, 32, 33, 34, 10, 11, 12, 13, 14], [35, 36, 37, 38, 39, 15, 16, 17, 18, 19]]])>
- tf.keras.layers.Add:按照输入顺序进行相加
import keras from keras.layers import Concatenate, Add import numpy as np x = np.arange(20).reshape(2, 2, 5) x array([[[ 0, 1, 2, 3, 4], [ 5, 6, 7, 8, 9]], [[10, 11, 12, 13, 14], [15, 16, 17, 18, 19]]]) y = np.arange(20, 40).reshape(2, 2, 5) y array([[[20, 21, 22, 23, 24], [25, 26, 27, 28, 29]], [[30, 31, 32, 33, 34], [35, 36, 37, 38, 39]]]) Add()([x, y]) <tf.Tensor: shape=(2, 2, 5), dtype=int64, numpy= array([[[20, 22, 24, 26, 28], [30, 32, 34, 36, 38]], [[40, 42, 44, 46, 48], [50, 52, 54, 56, 58]]])>
- Average layer
- Maximum layer
- Minimum layer
- Subtract layer
- Multiply layer
- Dot layer
- tf.keras.layers.Concatenate:按照输入顺序进行连接,axis 的值对应于 shape 的 0、1、2 的位置
-
tf.keras.preprocessing.image:图像数据处理
-
tf.keras.preprocessing.image.load_img:加载一张图片为 PIL 格式。
-
tf.keras.preprocessing.image.img_to_array:将 PIL 格式图片实例转换为一个 Numpy 数组。
-
tf.keras.preprocessing.image.ImageDataGenerator:生成批量的图片张量(包含数据增强)。
- flow_from_directory:Takes the path to a directory & generates batches of augmented data.
-
tf.keras.Model:在函数式 API 中,给定一些输入张量和输出张量可以构建一个模型
中文链接- compile:用于配置训练模型。
- fit:以给定数量的轮次(数据集上的迭代)训练模型。
- evaluate:在测试模式下返回模型的误差值和评估标准值。
- predict:为输入样本生成输出预测。
- fit_generator:使用 Python 生成器(或
Sequence
实例)逐批生成的数据,按批次训练模型。 - evaluate_generator:在数据生成器上评估模型。
- predict_generator:为来自数据生成器的输入样本生成预测。
- summary:打印网络结构。
- save:保存模型参数及结构。
- save_model
- load_model
- get_weights
- save_weights
- load_weights
分类:
Python Study
, AI Related
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· .NET10 - 预览版1新功能体验(一)
2013-07-04 【124】排球基本技术