时间:2025-07-25 作者:游乐小编
本项目复现2019年论文提出的SRM网络,首次用Paddle2.0实现含风格校正的SRM,在10分类动物数据集(按8:2划分)上实验。对比SRM、GE、SE模块及ResNet50,SRM验证准确率0.8736,优于其他,表明风格校正机制提升分类效果。
本项目首次使用paddle2.0复现了含有基于风格校正的网络SRM,并在动物数据集上进行了训练和验证。
动物数据集的划分是按8:2的的划分方法进行训练集与验证集划分的。
SRM网络的核心思想是提出了SRM模块。该模块首先通过风格池化从每个通道的特征图中提取风格信息,然后通过风格集成来评估每个通道的校正权重。其中,风格池化是在空间维度上操作,风格集成是在通道维度上操作。这种将特征图和风格权重相结合的方式本质上是一种注意力机制,只不过这种注意力关注的是特征图中的风格信息。SRM示意图如图1所示。
图1 SRM模块示意图
SRM实现细节如图2所示。
图2 SRM模块实现细节示意图
具体实现可以fork后见代码细节。
论文原文:SRM : A Style-based Recalibration Module for Convolutional Neural Networks
参考代码:
PyTorch的实现
本项目使用10分类的动物数据集进行训练和测试.
该十分类动物数据集,包含dog,horse,elephant,butterfly,chicken,cat,cow,sheep,spider和squirrel。每一分类的图片数量为2k-5k。
!unzip -q data/data70196/animals.zip -d work/dataset登录后复制
import osimport randomfrom matplotlib import pyplot as pltfrom PIL import Imageimgs = []paths = os.listdir('work/dataset')for path in paths: img_path = os.path.join('work/dataset', path) if os.path.isdir(img_path): img_paths = os.listdir(img_path) img = Image.open(os.path.join(img_path, random.choice(img_paths))) imgs.append((img, path))f, ax = plt.subplots(3, 3, figsize=(12,12))for i, img in enumerate(imgs[:9]): ax[i//3, i%3].imshow(img[0]) ax[i//3, i%3].axis('off') ax[i//3, i%3].set_title('label: %s' % img[1])plt.show()登录后复制
登录后复制
!python code/train_val_split.py登录后复制
finished train val split!登录后复制
!python code/train.py --net 'attention_resnet' --recalibration_type 'srm'登录后复制
!python code/eval.py --net 'attention_resnet' --recalibration_type 'srm'登录后复制
Eval begin...The loss value printed in the log is the current batch, and the metric is the average value of previous step.step 3276/3276 [==============================] - loss: 7.0645e-04 - acc: 0.8736 - 297ms/step Eval samples: 3276{'loss': [0.0007064453], 'acc': 0.8736263736263736}登录后复制
图3. 使用SRM的训练验证比较图示
!python code/train.py --net 'attention_resnet' --recalibration_type 'ge'登录后复制
!python code/eval.py --net 'attention_resnet' --recalibration_type 'ge'登录后复制
Eval begin...The loss value printed in the log is the current batch, and the metric is the average value of previous step.step 3276/3276 [==============================] - loss: 0.6899 - acc: 0.8614 - 228ms/step Eval samples: 3276{'loss': [0.6899206], 'acc': 0.8614163614163615}登录后复制
图4. 使用GE的训练验证比较图示
!python code/train.py --net 'attention_resnet' --recalibration_type 'se'登录后复制
!python code/eval.py --net 'attention_resnet' --recalibration_type 'se'登录后复制
W0222 10:36:03.112169 9128 device_context.cc:362] Please NOTE: device: 0, GPU Compute Capability: 7.0, Driver API Version: 10.1, Runtime API Version: 10.1W0222 10:36:03.116613 9128 device_context.cc:372] device: 0, cuDNN Version: 7.6.Eval begin...The loss value printed in the log is the current batch, and the metric is the average value of previous step.step 103/103 [==============================] - loss: 0.6246 - acc: 0.8730 - 175ms/step Eval samples: 3276{'loss': [0.6245543], 'acc': 0.873015873015873}登录后复制
图5. 使用SE的训练验证比较图示
!python code/train.py --net 'resnet'登录后复制
!python code/eval.py --net 'resnet'登录后复制
W0213 21:34:50.038996 12684 device_context.cc:362] Please NOTE: device: 0, GPU Compute Capability: 7.0, Driver API Version: 10.1, Runtime API Version: 10.1W0213 21:34:50.043457 12684 device_context.cc:372] device: 0, cuDNN Version: 7.6.Eval begin...The loss value printed in the log is the current batch, and the metric is the average value of previous step.step 103/103 [==============================] - loss: 1.4232 - acc: 0.5888 - 191ms/step Eval samples: 3276{'loss': [1.4232028], 'acc': 0.5888278388278388}登录后复制
图6. 使用ResNet的训练验证图示
图7. 使用SRM,GE,SE和ResNet的验证比较图示
2021-11-05 11:52
手游攻略2021-11-19 18:38
手游攻略2021-10-31 23:18
手游攻略2022-06-03 14:46
游戏资讯2025-06-28 12:37
单机攻略