目录

数据层面

数据增强

数据正则化

​数据采样

模型结构层面

简化模型

添加正则化层

早停法(Early Stopping)

训练过程层面

使用交叉验证

使用集成学习

调整学习率


防止过拟合是机器学习中一个非常重要的问题,它可以帮助模型在新的数据上表现得更好。以下将从数据层面、模型结构层面和训练过程层面对防止过拟合的方法进行分类介绍

数据层面

数据增强

数据增强通过对训练数据进行变换(如旋转、缩放、裁剪等),增加数据的多样性,从而减少模型对训练数据的过拟合

## 数据层面
# 1. 数据增强import numpy as np
import matplotlib.pyplot as plt
from tensorflow.keras.datasets import mnist
from tensorflow.keras.preprocessing.image import ImageDataGenerator# 加载 MNIST 数据集
(x_train, y_train), (x_test, y_test) = mnist.load_data()# 将图像数据转换为浮点数并归一化
x_train = x_train.astype('float32') / 255.0
x_test = x_test.astype('float32') / 255.0# 将图像数据扩展为 4D 张量 (samples, height, width, channels)
x_train = np.expand_dims(x_train, -1)
x_test = np.expand_dims(x_test, -1)# 创建数据增强生成器
datagen = ImageDataGenerator(rotation_range=20,  # 随机旋转度数范围width_shift_range=0.1,  # 随机水平移动范围height_shift_range=0.1,  # 随机垂直移动范围shear_range=0.2,  # 剪切强度zoom_range=0.2,  # 随机缩放范围horizontal_flip=False,  # 不进行水平翻转(因为数字图像水平翻转可能没有意义)fill_mode='nearest'  # 填充新创建像素的方法
)# 选择一张图像进行增强
sample_image = x_train[0]  # 选择第一张图像
sample_image = np.expand_dims(sample_image, 0)  # 添加批次维度# 使用数据增强生成器生成增强后的图像
augmented_images = datagen.flow(sample_image, batch_size=1)# 可视化增强后的图像
plt.figure(figsize=(10, 6))
for i in range(10):  # 生成并显示 10 张增强后的图像augmented_image = next(augmented_images)[0]  # 获取一张增强后的图像plt.subplot(2, 5, i + 1)plt.imshow(augmented_image.squeeze(), cmap='gray')  # 显示灰度图像plt.axis('off')  # 关闭坐标轴
plt.show()

数据正则化

数据正则化通过对输入数据进行归一化或标准化,使数据的分布更加均匀,减少模型对数据的过拟合

# 2. 数据正则化import numpy as np
import matplotlib.pyplot as plt
from tensorflow.keras.datasets import mnist
from sklearn.preprocessing import StandardScaler
from imblearn.over_sampling import SMOTE
from imblearn.under_sampling import RandomUnderSampler# 加载 MNIST 数据集
(x_train, y_train), (x_test, y_test) = mnist.load_data()# 将图像数据转换为浮点数
x_train = x_train.astype('float32')
x_test = x_test.astype('float32')# 数据归一化(将像素值缩放到 [0, 1])
x_train_normalized = x_train / 255.0
x_test_normalized = x_test / 255.0# 数据标准化(将数据缩放到均值为 0,标准差为 1)
scaler = StandardScaler()
x_train_reshaped = x_train.reshape(-1, 28 * 28)  # 将图像数据展平为二维数组
x_test_reshaped = x_test.reshape(-1, 28 * 28)x_train_standardized = scaler.fit_transform(x_train_reshaped)
x_test_standardized = scaler.transform(x_test_reshaped)# 可视化归一化和标准化的效果
def plot_images(images, title):plt.figure(figsize=(10, 2))for i in range(10):plt.subplot(1, 10, i + 1)plt.imshow(images[i], cmap='gray')plt.axis('off')plt.suptitle(title)plt.show()# 显示原始图像
plot_images(x_train[:10], "Original Images")# 显示归一化后的图像
plot_images(x_train_normalized[:10], "Normalized Images")# 显示标准化后的图像
plot_images(x_train_standardized[:10].reshape(-1, 28, 28), "Standardized Images")

 

数据采样

数据采样可以通过欠采样(减少多数类样本)或过采样(增加少数类样本)来平衡数据集,减少模型对多数类的过拟合

# 3. 数据采样import numpy as np
import matplotlib.pyplot as plt
from tensorflow.keras.datasets import mnist
from sklearn.preprocessing import StandardScaler
from imblearn.over_sampling import SMOTE
from imblearn.under_sampling import RandomUnderSampler# 加载 MNIST 数据集
(x_train, y_train), (x_test, y_test) = mnist.load_data()# 将图像数据转换为浮点数
x_train = x_train.astype('float32')
x_test = x_test.astype('float32')# 模拟不平衡数据集(选择数字 0 和数字 1)
x_train_sampled = x_train[y_train < 2]
y_train_sampled = y_train[y_train < 2]# 过采样(SMOTE)
smote = SMOTE(random_state=42)
x_resampled, y_resampled = smote.fit_resample(x_train_sampled.reshape(-1, 28 * 28), y_train_sampled)# 欠采样(RandomUnderSampler)
undersampler = RandomUnderSampler(random_state=42)
x_undersampled, y_undersampled = undersampler.fit_resample(x_train_sampled.reshape(-1, 28 * 28), y_train_sampled)# 可视化过采样和欠采样的效果
def plot_sampled_images(images, labels, title):plt.figure(figsize=(10, 2))for i in range(10):plt.subplot(1, 10, i + 1)plt.imshow(images[i].reshape(28, 28), cmap='gray')plt.title(labels[i])plt.axis('off')plt.suptitle(title)plt.show()# 显示过采样后的图像
plot_sampled_images(x_resampled[:10], y_resampled[:10], "Over-sampled Images")# 显示欠采样后的图像
plot_sampled_images(x_undersampled[:10], y_undersampled[:10], "Under-sampled Images")

模型结构层面

简化模型

选择更简单的模型结构或减少模型的复杂度,可以有效减少过拟合。例如,减少神经网络的层数或神经元数量

## 模型结构层面# 1. 简化模型
import numpy as np
import matplotlib.pyplot as plt
from tensorflow.keras.datasets import mnist
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense
from tensorflow.keras.callbacks import EarlyStopping# 加载 MNIST 数据集
(x_train, y_train), (x_test, y_test) = mnist.load_data()# 数据预处理
x_train = x_train.astype('float32') / 255.0
x_test = x_test.astype('float32') / 255.0
x_train = x_train.reshape(-1, 28 * 28)
x_test = x_test.reshape(-1, 28 * 28)# 构建简化模型
model = Sequential()
model.add(Dense(64, activation='relu', input_shape=(28 * 28,)))  # 较少的神经元
model.add(Dense(10, activation='softmax'))# 编译模型
model.compile(optimizer='adam', loss='sparse_categorical_crossentropy', metrics=['accuracy'])# 训练模型
history_simple = model.fit(x_train, y_train,validation_split=0.2,epochs=50,batch_size=128
)# 可视化训练过程
def plot_training_history(history, title):plt.figure(figsize=(12, 4))# 绘制训练和验证的损失plt.subplot(1, 2, 1)plt.plot(history.history['loss'], label='Training Loss')plt.plot(history.history['val_loss'], label='Validation Loss')plt.title(f'Training and Validation Loss ({title})')plt.xlabel('Epochs')plt.ylabel('Loss')plt.legend()# 绘制训练和验证的准确率plt.subplot(1, 2, 2)plt.plot(history.history['accuracy'], label='Training Accuracy')plt.plot(history.history['val_accuracy'], label='Validation Accuracy')plt.title(f'Training and Validation Accuracy ({title})')plt.xlabel('Epochs')plt.ylabel('Accuracy')plt.legend()plt.tight_layout()plt.show()# 调用可视化函数
plot_training_history(history_simple, "Simple Model")

添加正则化层

在模型中添加正则化层(如 Dropout 或 L1/L2 正则化),可以减少模型对训练数据的依赖

# 2. 添加正则化层from tensorflow.keras.regularizers import l2
from tensorflow.keras.layers import Dropout
from tensorflow.keras.layers import Dense
from tensorflow.keras.datasets import mnist
from tensorflow.keras.models import Sequential
import matplotlib.pyplot as plt# 加载 MNIST 数据集
(x_train, y_train), (x_test, y_test) = mnist.load_data()# 数据预处理
x_train = x_train.astype('float32') / 255.0
x_test = x_test.astype('float32') / 255.0
x_train = x_train.reshape(-1, 28 * 28)
x_test = x_test.reshape(-1, 28 * 28)# 构建带有正则化层的模型
model = Sequential()
model.add(Dense(256, activation='relu', kernel_regularizer=l2(0.01), input_shape=(28 * 28,)))  # L2 正则化
model.add(Dropout(0.5))  # Dropout
model.add(Dense(128, activation='relu', kernel_regularizer=l2(0.01)))
model.add(Dropout(0.5))
model.add(Dense(10, activation='softmax'))# 编译模型
model.compile(optimizer='adam', loss='sparse_categorical_crossentropy', metrics=['accuracy'])# 训练模型
history_regularized = model.fit(x_train, y_train,validation_split=0.2,epochs=50,batch_size=128
)# 可视化训练过程
def plot_training_history(history, title):plt.figure(figsize=(12, 4))# 绘制训练和验证的损失plt.subplot(1, 2, 1)plt.plot(history.history['loss'], label='Training Loss')plt.plot(history.history['val_loss'], label='Validation Loss')plt.title(f'Training and Validation Loss ({title})')plt.xlabel('Epochs')plt.ylabel('Loss')plt.legend()# 绘制训练和验证的准确率plt.subplot(1, 2, 2)plt.plot(history.history['accuracy'], label='Training Accuracy')plt.plot(history.history['val_accuracy'], label='Validation Accuracy')plt.title(f'Training and Validation Accuracy ({title})')plt.xlabel('Epochs')plt.ylabel('Accuracy')plt.legend()plt.tight_layout()plt.show()# 可视化训练过程
plot_training_history(history_regularized, "Regularized Model")

早停法(Early Stopping)

早停法通过在训练过程中监控验证集的损失,当验证集的损失不再下降时停止训练,从而避免过拟合

# 3. 早停法(Early Stopping)from tensorflow.keras.callbacks import EarlyStopping
from tensorflow.keras.datasets import mnist
from tensorflow.keras.layers import Dense
from tensorflow.keras.models import Sequential
import matplotlib.pyplot as plt# 加载 MNIST 数据集
(x_train, y_train), (x_test, y_test) = mnist.load_data()# 数据预处理
x_train = x_train.astype('float32') / 255.0
x_test = x_test.astype('float32') / 255.0
x_train = x_train.reshape(-1, 28 * 28)
x_test = x_test.reshape(-1, 28 * 28)# 构建模型
model = Sequential()
model.add(Dense(256, activation='relu', input_shape=(28 * 28,)))
model.add(Dense(128, activation='relu'))
model.add(Dense(10, activation='softmax'))# 编译模型
model.compile(optimizer='adam', loss='sparse_categorical_crossentropy', metrics=['accuracy'])# 设置早停法
early_stopping = EarlyStopping(monitor='val_loss', patience=5, restore_best_weights=True)# 训练模型
history_early_stopping = model.fit(x_train, y_train,validation_split=0.2,epochs=50,batch_size=128,callbacks=[early_stopping]
)# 可视化训练过程
def plot_training_history(history, title):plt.figure(figsize=(12, 4))# 绘制训练和验证的损失plt.subplot(1, 2, 1)plt.plot(history.history['loss'], label='Training Loss')plt.plot(history.history['val_loss'], label='Validation Loss')plt.title(f'Training and Validation Loss ({title})')plt.xlabel('Epochs')plt.ylabel('Loss')plt.legend()# 绘制训练和验证的准确率plt.subplot(1, 2, 2)plt.plot(history.history['accuracy'], label='Training Accuracy')plt.plot(history.history['val_accuracy'], label='Validation Accuracy')plt.title(f'Training and Validation Accuracy ({title})')plt.xlabel('Epochs')plt.ylabel('Accuracy')plt.legend()plt.tight_layout()plt.show()# 可视化训练过程
plot_training_history(history_early_stopping, "Early Stopping")

训练过程层面

使用交叉验证

交叉验证可以更好地评估模型的泛化能力,避免模型对特定训练集的过拟合

## 训练过程层面# 1. 使用交叉验证
import numpy as np
import matplotlib.pyplot as plt
from tensorflow.keras.datasets import mnist
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense
from sklearn.model_selection import KFold# 加载 MNIST 数据集
(x_train, y_train), (x_test, y_test) = mnist.load_data()# 数据预处理
x_train = x_train.astype('float32') / 255.0
x_test = x_test.astype('float32') / 255.0
x_train = x_train.reshape(-1, 28 * 28)
x_test = x_test.reshape(-1, 28 * 28)# 定义模型
def create_model():model = Sequential()model.add(Dense(256, activation='relu', input_shape=(28 * 28,)))model.add(Dense(128, activation='relu'))model.add(Dense(10, activation='softmax'))model.compile(optimizer='adam', loss='sparse_categorical_crossentropy', metrics=['accuracy'])return model# K 折交叉验证
kf = KFold(n_splits=5, shuffle=True, random_state=42)
fold_no = 1
accuracies = []for train_index, val_index in kf.split(x_train):print(f'Training on fold {fold_no}...')x_train_fold, x_val_fold = x_train[train_index], x_train[val_index]y_train_fold, y_val_fold = y_train[train_index], y_train[val_index]model = create_model()model.fit(x_train_fold, y_train_fold, epochs=10, batch_size=128, verbose=0)scores = model.evaluate(x_val_fold, y_val_fold, verbose=0)accuracies.append(scores[1])print(f'Score for fold {fold_no}: {model.metrics_names[0]} of {scores[0]}; {model.metrics_names[1]} of {scores[1] * 100}%')fold_no += 1# 输出交叉验证的平均准确率
print(f'Average accuracy: {np.mean(accuracies) * 100}%') # 97.5766670703888%

使用集成学习

集成学习通过组合多个模型来提高模型的泛化能力,减少过拟合

# 2. 使用集成学习from sklearn.ensemble import VotingClassifier
from sklearn.linear_model import LogisticRegression
from sklearn.svm import SVC
from tensorflow.keras.datasets import mnist
from sklearn.ensemble import RandomForestClassifier
from sklearn.metrics import accuracy_score# 加载 MNIST 数据集
(x_train, y_train), (x_test, y_test) = mnist.load_data()# 数据预处理
x_train = x_train.astype('float32') / 255.0
x_test = x_test.astype('float32') / 255.0
x_train = x_train.reshape(-1, 28 * 28)
x_test = x_test.reshape(-1, 28 * 28)# 定义多个模型
model1 = LogisticRegression(max_iter=1000, random_state=42)
model2 = SVC(probability=True, random_state=42)
model3 = RandomForestClassifier(random_state=42)# 创建集成模型
ensemble_model = VotingClassifier(estimators=[('lr', model1), ('svc', model2), ('rf', model3)], voting='soft')# 训练集成模型
ensemble_model.fit(x_train, y_train)# 预测并评估
y_pred = ensemble_model.predict(x_test)
accuracy = accuracy_score(y_test, y_pred)
print(f'Ensemble model accuracy: {accuracy * 100}%')   # 97.21%

调整学习率

适当调整学习率可以避免模型在训练过程中过度拟合训练数据

# 3. 调整学习率
from tensorflow.keras.callbacks import ReduceLROnPlateau
from tensorflow.keras.layers import Dense
import matplotlib.pyplot as plt
from tensorflow.keras.datasets import mnist
from tensorflow.keras.models import Sequential# 加载 MNIST 数据集
(x_train, y_train), (x_test, y_test) = mnist.load_data()# 数据预处理
x_train = x_train.astype('float32') / 255.0
x_test = x_test.astype('float32') / 255.0
x_train = x_train.reshape(-1, 28 * 28)
x_test = x_test.reshape(-1, 28 * 28)# 定义模型
model = Sequential()
model.add(Dense(256, activation='relu', input_shape=(28 * 28,)))
model.add(Dense(128, activation='relu'))
model.add(Dense(10, activation='softmax'))
model.compile(optimizer='adam', loss='sparse_categorical_crossentropy', metrics=['accuracy'])# 设置动态调整学习率
reduce_lr = ReduceLROnPlateau(monitor='val_loss', factor=0.5, patience=3, min_lr=0.00001)# 训练模型
history = model.fit(x_train, y_train,validation_split=0.2,epochs=50,batch_size=128,callbacks=[reduce_lr]
)# 可视化训练过程
def plot_training_history(history, title):plt.figure(figsize=(12, 4))# 绘制训练和验证的损失plt.subplot(1, 2, 1)plt.plot(history.history['loss'], label='Training Loss')plt.plot(history.history['val_loss'], label='Validation Loss')plt.title(f'Training and Validation Loss ({title})')plt.xlabel('Epochs')plt.ylabel('Loss')plt.legend()# 绘制训练和验证的准确率plt.subplot(1, 2, 2)plt.plot(history.history['accuracy'], label='Training Accuracy')plt.plot(history.history['val_accuracy'], label='Validation Accuracy')plt.title(f'Training and Validation Accuracy ({title})')plt.xlabel('Epochs')plt.ylabel('Accuracy')plt.legend()plt.tight_layout()plt.show()# 可视化训练过程
plot_training_history(history, "Dynamic Learning Rate")

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如若转载,请注明出处:http://www.pswp.cn/web/88514.shtml
繁体地址,请注明出处:http://hk.pswp.cn/web/88514.shtml
英文地址,请注明出处:http://en.pswp.cn/web/88514.shtml

如若内容造成侵权/违法违规/事实不符,请联系英文站点网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

持有对象-泛型和类型安全的容器

我们需要管理一批对象序列&#xff0c;但是又对实际运行的时候的对象类型和对象序列长度不确定的时候&#xff0c;用简单的对象引用无法满足&#xff0c;java有ArrayList,Map,Set等这些容器类提供&#xff0c;这些都实现了Collections接口&#xff0c;所以都属于Collections类。…

《财税企业经营管理秘籍(一):行业适配的获客方式》

在财税服务这片竞争激烈的红海中&#xff0c;客户资源如同氧气——没有它&#xff0c;企业寸步难行。然而残酷的现实是&#xff0c;许多财税企业正深陷“获客泥潭”&#xff1a;投入巨大精力与成本&#xff0c;换来的却是转化渺茫、增长停滞的困境。高质量线索&#xff0c;已成…

使用tensorflow的多项式回归的例子(一)

多项式回归例1%matplotlib inlineimport tensorflow as tfimport numpy as npimport matplotlib.pyplot as plttrX np.linspace(-1, 1, 101)num_coeffs 6trY_coeffs [1, 2, 3, 4, 5, 6]trY 0for i in range(num_coeffs):trY trY_coeffs[i] * np.power(trX, i)trY np.rand…

STM32F103C8T6基于HAL库驱动NB-IoT模块BC26通信详 解

一、引言&#xff1a; NB-IoT技术与应用场景NB-IoT&#xff08; Narrow Band Internet of Things &#xff09;作为低功耗广域网&#xff08; LPWAN &#xff09;的核心技术&#xff0c;以其广覆 盖、低功耗、大连接、低成本的特性&#xff0c;广泛应用于智能表计、环境监测、…

iOS 性能测试工具全流程:主流工具实战对比与适用场景

在iOS开发中&#xff0c;性能优化往往被安排到开发后期&#xff0c;甚至上线前才临时补救。但性能瓶颈通常是架构设计、资源加载、动画机制等多方面共同作用的结果&#xff0c;仅凭肉眼感知和log输出&#xff0c;难以精准定位。 一套合适的性能测试工具组合&#xff0c;不仅能帮…

目标检测:视觉系统中的CNN-Transformer融合网络

一、背景 无人机&#xff08;UAVs&#xff09;在城市自动巡逻中发挥着重要作用&#xff0c;但它们在图像识别方面面临挑战&#xff0c;尤其是小目标检测和目标遮挡问题。此外&#xff0c;无人机的高速飞行要求检测系统具备实时处理能力。 为解决这些问题&#xff0c;我们提出了…

揭示宇宙的隐藏对称性:群论-AI云计算拓展核心内容

通过利用云计算&#xff0c;借助群论对宇宙对称性的探索&#xff0c;从离散群和李群等基础概念&#xff0c;逐步深入到量子力学和更高自旋系统中的高级应用。 对称性远不止是美学上的吸引力&#xff1b;它是编织在宇宙结构中的一个基本原则。从雪花的复杂图案到控制粒子的基本定…

前端项目vue3项目集成eslint@9.x跟prettier

tips: 这些涉及编辑器的修改不一定能及时生效&#xff0c;如果没有生效&#xff0c;可以试试重启编辑器窗口 编辑器集成 我的编辑器是vscode&#xff0c;需要安装这两个编辑器插件eslint prettier我这个配置主要是通过eslint提供的配置cli命令生成&#xff0c;在里面加入了对pr…

登录超时问题的排查方法与预防经验分享

​​一、排查方法​​​​检查网络连接​​确保网络稳定&#xff0c;尝试重启路由器或切换网络&#xff08;如从WiFi切换到移动数据&#xff09;。使用命令&#xff08;如 ping 或 traceroute&#xff09;测试网络连通性&#xff0c;排查是否存在丢包或高延迟。​​验证服务端状…

uniapp,Anroid10+版本如何保存图片并删除

Android 10系统开始 进一步增强了平台功能&#xff0c;为外部存储设备上的应用和用户数据提供了更好的保护。作为这项工作的一部分&#xff0c;平台引入了进一步的改进&#xff0c;以简化向分区存储的转换。 为了让用户更好地控制自己的文件&#xff0c;保护用户隐私数据&#…

Jenkins Pipeline 语法

Pipeline 简介 Jenkins2.x 的核心是使用 pipeline 来构建项目,也就是流水线,将 Jenkins1.0 版本中基于表单的配置信息比如 JDK/SVN 以及参数的配置都转变成了代码,即 pipeline as Code。 传统的表单方式有以下缺点: 需要大量的 web 表单交互,有时候需要进行很多次的切换…

搭建渗透测试环境

一、基于docker搭建靶场 #此步骤需要科学上网 #从软件源中下载 docker.io 和 docker -compose 软件包及其依赖项。 sudo apt-get install docker.io docker-compose #查看docker版本 docker -v #查看docker信息 docker info #重启docker服务 sudo systemctl daemon-reload sudo…

(一)OpenCV——噪声去除(降噪)

高斯滤波器&#xff08;针对高斯噪声&#xff09; 高斯噪声是指它的概率密度函数服从高斯分布&#xff08;即正态分布&#xff09;的一类噪声。常见的高斯噪声包括起伏噪声、宇宙噪声、热噪声和散粒噪声等等。 高斯滤波(Gaussian filter) 包含许多种&#xff0c;包括低通、带…

百度开源文心 4.5 系列开源大模型 GitCode 本地化部署,硅基流动:文心 vs. DeepSeek vs. Qwen 3.0 深度测评

百度开源文心 4.5 系列开源大模型 GitCode 本地化部署&#xff0c;硅基流动&#xff1a;文心 vs. DeepSeek vs. Qwen 3.0 深度测评 文章目录百度开源文心 4.5 系列开源大模型 GitCode 本地化部署&#xff0c;硅基流动&#xff1a;文心 vs. DeepSeek vs. Qwen 3.0 深度测评背景百…

「日拱一码」022 机器学习——数据划分

目录 基于单次随机划分的方法 普通单次随机划分&#xff08;train_test_split&#xff09; 分层单次随机划分(使用 train_test_split 的 stratify 参数) 基于多次随机划分的方法 普通多次随机划分(ShuffleSplit) 分层多次随机划分&#xff08;StratifiedShuffleSplit…

lora网关

所需配置的引脚&#xff0c;SPI传输&#xff0c;PG13复位&#xff08;输出引脚&#xff0c;推挽输出&#xff09;&#xff0c;PE2忙碌&#xff08;输入引脚&#xff0c;浮空输入&#xff09;PE6PE5输出。若利用延时处理按键消抖&#xff0c;hal库里用systick中断实现延时&#…

5G IMS注册关键一步:UE如何通过ePCO获取P-CSCF地址

看似简单的P-CSCF地址传递,背后是5G核心网控制面与用户面的精密协作。ePCO作为高效的信令载体,承载着IMS业务触达的第一把钥匙。 在5G网络中建立IMS PDN连接时,UE(用户设备)获取P-CSCF(Proxy-Call Session Control Function)地址是IMS业务(如VoLTE、VoNR)成功注册和运…

JVM方法区的运行时常量区到底存储哪些数据?

JDK8以后&#xff0c;运行时常量池逻辑上属于方法区&#xff1b;但&#xff1a; 其中的字符串常量池实际位置移至到了java堆&#xff1b;其中一些符号引用也存储到了元空间&#xff1b;字符串常量池&#xff0c;元空间&#xff0c;运行时常量区的具体关系请看这篇博客&#xf…

Go defer(二):从汇编的角度理解延迟调用的实现

Go的延迟调用机制会在当前函数返回前执行传入的函数&#xff0c;它会经常被用于关闭文件描述符、关闭数据库连接以及解锁资源。之前的文章&#xff08; Go defer&#xff08;一&#xff09;&#xff1a;延迟调用的使用及其底层实现原理详解 &#xff09;详细介绍了defer的使用以…

Android 12系统源码_分屏模式(一)从最近任务触发分屏模式

前言 打开MainActivity&#xff0c;然后进入最近任务触发分屏&#xff0c;可以成功进入分屏模式。 本篇文章我们来具体梳理一下这个过程的源码调用流程。 一 launcher3阶段 1.1 源码 //packages/apps/Launcher3/quickstep/src/com/android/quickstep/views/TaskView.java publi…