飞桨常规赛:PALM眼底彩照视盘探测与分割 2021 5月第1名方案

P粉084495128
发布: 2025-07-25 10:34:04
原创
828人浏览过
本文介绍飞桨常规赛PALM眼底彩照视盘探测与分割任务。赛题源于ISBI2019PALM眼科大赛,需用飞桨框架分割眼底图像视盘区域。数据集含800张训练图及标注、400张测试图。文中展示了用UNet模型的训练、验证、预测流程,包括数据处理、配置设置,最终生成符合要求的分割结果。

☞☞☞AI 智能聊天, 问答助手, AI 智能搜索, 免费无限量使用 DeepSeek R1 模型☜☜☜

飞桨常规赛:palm眼底彩照视盘探测与分割 2021 5月第1名方案 - php中文网

飞桨常规赛:PALM眼底彩照视盘探测与分割

常规赛简介

飞桨(PaddlePaddle)以百度多年的深度学习技术研究和业务应用为基础,是中国首个开源开放、技术领先、功能完备的产业级深度学习平台。更多飞桨资讯,点击此处查看。

飞桨常规赛由百度飞桨于 2019 年发起,面向全球 AI 开发者,赛题范围广,涵盖领域多。常规赛旨在通过长期发布的经典比赛项目,为开发者提供学习锻炼机会,助力大家在飞桨大赛中获得骄人成绩。

参赛选手需使用飞桨框架,基于特定赛题下的真实行业数据完成并提交任务。常规赛采取月度评比方式,为打破历史最高记录选手和当月有资格参与月度评奖的前 10 名选手提供飞桨特别礼包奖励。更多惊喜,更多收获,尽在飞桨常规赛。

赛题介绍 本赛题原型为ISBI2019PALM眼科大赛。 近视已成为全球公共卫生负担。在近视患者中,约35%为高度近视。近视导致眼轴长度的延长,可能引起视网膜和脉络膜的病理改变。随着近视屈光度的增加,高度近视将发展为病理性近视,其特点是病理改变的形成:(1)后极,包括镶嵌型眼底、后葡萄肿、视网膜脉络膜变性等;(2)视盘,包括乳头旁萎缩、倾斜等;(3)近视性黄斑,包括漆裂、福氏斑、CNV等。病理性近视对患者造成不可逆的视力损害。因此,早期诊断和定期随访非常重要。 飞桨常规赛:PALM眼底彩照视盘探测与分割 2021 5月第1名方案 - php中文网 视网膜由黄斑向鼻侧约3mm处有一直径约1.5mm、境界清楚的淡红色圆盘状结构,称为视神经盘,简称视盘。视盘是眼底图像的一个重要特征,对其进行准确、快速地定位与分割对利用眼底图像进行疾病辅助诊断具有重要意义。

比赛任务

该任务目的是对眼底图像的视盘进行检测,若存在视盘结构,需从眼底图像中分割出视盘区域;若无视盘结构,分割结果直接置全背景。飞桨常规赛:PALM眼底彩照视盘探测与分割 2021 5月第1名方案 - php中文网        

数据集介绍

本次常规赛提供的金标准由中山大学中山眼科中心的7名眼科医生手工进行视盘像素级标注,之后由另一位高级专家将它们融合为最终的标注结果。存储为BMP图像,与对应的眼底图像大小相同,标签为0代表视盘(黑色区域);标签为255代表其他(白色区域)。

训练数据集

文件名称:Train Train文件夹里有fundus_images文件夹和Disc_Masks文件夹。

飞桨PaddlePaddle
飞桨PaddlePaddle

飞桨PaddlePaddle开发者社区与布道,与社区共同进步

飞桨PaddlePaddle 12
查看详情 飞桨PaddlePaddle

fundus_images文件夹内包含800张眼底彩照,分辨率为1444×1444,或2124×2056。命名形如H0001.jpg、N0001.jpg、P0001.jpg和V0001.jpg。

Disc_Masks文件夹内包含fundus_images里眼底彩照的视盘分割金标准,大小与对应的眼底彩照一致。命名前缀和对应的fundus_images文件夹里的图像命名一致,后缀为bmp。

测试数据集

文件名称:PALM-Testing400-Images

包含400张眼底彩照,命名形如T0001.jpg。

比赛思路

先用Unet进行分割。对预测结果进行处理。假如某一张图片预测的结果出现多个不连通的区域,通过面积筛选,只保留最大的面积。

In [ ]
#解压数据!unzip -o data/data86770/seg.zip -d /home/aistudio/work
登录后复制
   
In [ ]
#已经克隆了,不用再克隆,里面已经包含了修改的配置文件和训练保存的模型文件# !git clone https://gitee.com/PaddlePaddle/PaddleSeg
登录后复制
   

生成train.txt 和val.txt

In [ ]
import randomimport os
random.seed(2020)
mask_dir  = '/home/aistudio/work/seg/Train/masks'img_dir = '/home/aistudio/work/seg/Train/fundus_image'path_list = list()for img in os.listdir(img_dir):
    img_path = os.path.join(img_dir,img)
    mask_path = os.path.join(mask_dir,img.replace('jpg', 'png'))
    path_list.append((img_path, mask_path))
random.shuffle(path_list)
ratio = 0.8train_f = open('/home/aistudio/work/seg/Train/train.txt','w') 
val_f = open('/home/aistudio/work/seg/Train/val.txt' ,'w')for i ,content in enumerate(path_list):
    img, mask = content
    text = img + ' ' + mask + '\n'
    if i < len(path_list) * ratio:
        train_f.write(text)    else:
        val_f.write(text)
train_f.close()
val_f.close()
登录后复制
   

配置文件如下

batch_size: 4iters: 16000train_dataset:
  type: Dataset
  dataset_root: /home/aistudio/work/seg/Train/
  train_path: /home/aistudio/work/seg/Train/train.txt
  num_classes: 2
  transforms:
    - type: Resize
      target_size: [512, 512]    # - type: RandomRotation
    #   max_rotation: 15
    - type: RandomHorizontalFlip
    - type: RandomDistort
      brightness_range: 0.4
      contrast_range: 0.4
      saturation_range: 0.4
    - type: Normalize
  mode: trainval_dataset:
  type: Dataset
  dataset_root: /home/aistudio/work/seg/Train/
  val_path: /home/aistudio/work/seg/Train/val.txt
  num_classes: 2
  transforms:
    - type: Resize
      target_size: [512, 512]    - type: Normalize
  mode: valoptimizer:
  type: sgd
  momentum: 0.9
  weight_decay: 4.0e-5learning_rate:
  value: 0.00125
  decay:
    type: poly
    power: 0.9
    end_lr: 0.0loss:
  types:
    - type: MixedLoss
      losses:
        - type: CrossEntropyLoss
        - type: DiceLoss
      coef: [0.7, 0.3]  coef: [1]model:
  type: UNet
  num_classes: 2
  use_deconv: False
  pretrained: /home/aistudio/unetmodel.pdparams
登录后复制
   

开始训练

In [ ]
%cd /home/aistudio/PaddleSeg
!python train.py \
       --config configs/unet_PALM.yml \
       --do_eval \
       --use_vdl \
       --save_interval 480 \
       --save_dir output_unet_PALMoutput
登录后复制
   

验证

In [ ]
!python val.py --config configs/unet_PALM.yml  --model_path output_unet_PALMoutput/best_model/model.pdparams
登录后复制
       
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/fluid/layers/utils.py:26: DeprecationWarning: `np.int` is a deprecated alias for the builtin `int`. To silence this warning, use `int` by itself. Doing this will not modify any behavior and is safe. When replacing `np.int`, you may wish to use e.g. `np.int64` or `np.int32` to specify the precision. If you wish to review your current use, check the release note link for additional information.
Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations
  def convert_to_list(value, n, name, dtype=np.int):
2021-05-07 18:16:17 [INFO]
---------------Config Information---------------
batch_size: 4
iters: 16000
learning_rate:
  decay:
    end_lr: 0.0
    power: 0.9
    type: poly
  value: 0.00125
loss:
  coef:
  - 1
  types:
  - coef:
    - 0.7
    - 0.3
    losses:
    - type: CrossEntropyLoss
    - type: DiceLoss
    type: MixedLoss
model:
  num_classes: 2
  pretrained: /home/aistudio/unetmodel.pdparams
  type: UNet
  use_deconv: false
optimizer:
  momentum: 0.9
  type: sgd
  weight_decay: 4.0e-05
train_dataset:
  dataset_root: /home/aistudio/work/seg/Train/
  mode: train
  num_classes: 2
  train_path: /home/aistudio/work/seg/Train/train.txt
  transforms:
  - target_size:
    - 512
    - 512
    type: Resize
  - type: RandomHorizontalFlip
  - brightness_range: 0.4
    contrast_range: 0.4
    saturation_range: 0.4
    type: RandomDistort
  - type: Normalize
  type: Dataset
val_dataset:
  dataset_root: /home/aistudio/work/seg/Train/
  mode: val
  num_classes: 2
  transforms:
  - target_size:
    - 512
    - 512
    type: Resize
  - type: Normalize
  type: Dataset
  val_path: /home/aistudio/work/seg/Train/val.txt
------------------------------------------------
W0507 18:16:17.212044  4392 device_context.cc:362] Please NOTE: device: 0, GPU Compute Capability: 7.0, Driver API Version: 10.1, Runtime API Version: 10.1
W0507 18:16:17.212100  4392 device_context.cc:372] device: 0, cuDNN Version: 7.6.
2021-05-07 18:16:24 [INFO]	Loading pretrained model from /home/aistudio/unetmodel.pdparams
2021-05-07 18:16:24 [WARNING]	[SKIP] Shape of pretrained params cls.weight doesn't match.(Pretrained: (19, 64, 3, 3), Actual: [2, 64, 3, 3])
2021-05-07 18:16:24 [WARNING]	[SKIP] Shape of pretrained params cls.bias doesn't match.(Pretrained: (19,), Actual: [2])
2021-05-07 18:16:24 [WARNING]	[SKIP] Shape of pretrained params conv.weight doesn't match.(Pretrained: (19, 64, 3, 3), Actual: [2, 64, 3, 3])
2021-05-07 18:16:24 [WARNING]	[SKIP] Shape of pretrained params conv.bias doesn't match.(Pretrained: (19,), Actual: [2])
2021-05-07 18:16:25 [INFO]	There are 108/112 variables loaded into UNet.
2021-05-07 18:16:25 [INFO]	Loading pretrained model from output_unet_PALMoutput/best_model/model.pdparams
2021-05-07 18:16:25 [INFO]	There are 112/112 variables loaded into UNet.
2021-05-07 18:16:25 [INFO]	Loaded trained params of model successfully
2021-05-07 18:16:25 [INFO]	Start evaluating (total_samples=160, total_iters=160)...
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/fluid/dataloader/dataloader_iter.py:89: DeprecationWarning: `np.bool` is a deprecated alias for the builtin `bool`. To silence this warning, use `bool` by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use `np.bool_` here.
Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations
  if isinstance(slot[0], (np.ndarray, np.bool, numbers.Number)):
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/fluid/dygraph/math_op_patch.py:238: UserWarning: The dtype of left and right variables are not the same, left dtype is VarType.INT32, but right dtype is VarType.BOOL, the right dtype will convert to VarType.INT32
  format(lhs_dtype, rhs_dtype, lhs_dtype))
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/fluid/dygraph/math_op_patch.py:238: UserWarning: The dtype of left and right variables are not the same, left dtype is VarType.INT64, but right dtype is VarType.BOOL, the right dtype will convert to VarType.INT64
  format(lhs_dtype, rhs_dtype, lhs_dtype))
160/160 [==============================] - 26s 163ms/step - batch_cost: 0.1623 - reader cost: 0.147
2021-05-07 18:16:51 [INFO]	[EVAL] #Images=160 mIoU=0.9424 Acc=0.9980 Kappa=0.9390 
2021-05-07 18:16:51 [INFO]	[EVAL] Class IoU: 
[0.998  0.8868]
2021-05-07 18:16:51 [INFO]	[EVAL] Class Acc: 
[0.999  0.9366]
登录后复制
       

预测

In [ ]
!python predict.py \
       --config configs/unet_PALM.yml \
       --model_path output_unet_PALMoutput/best_model/model.pdparams \
       --image_path /home/aistudio/work/seg/test \
       --save_dir output_unet_PALMoutput/result
登录后复制
   

生成结果

In [ ]
import os 
import cv2
result_path = '/home/aistudio/PaddleSeg/output_unet_PALMoutput/result/pseudo_color_prediction'dist_path = '/home/aistudio/Disc_Segmentation'for img_name in os.listdir(result_path):
    img_path = os.path.join(result_path, img_name)
    img = cv2.imread(img_path)
    g  = img[:,:,1]
    ret, result = cv2.threshold(g, 127,255, cv2.THRESH_BINARY_INV)
    cv2.imwrite(os.path.join(dist_path,img_name), result)
登录后复制
   

假如预测中出现多个不连通的区域,只保留最大的区域

In [ ]
import os 
import cv2import matplotlib.pyplot as pltdef cnt_area(cnt):
    area = cv2.contourArea(cnt)    return area

result_path = '/home/aistudio/PaddleSeg/output_unet_PALMoutput/result/pseudo_color_prediction'dist_path = '/home/aistudio/Disc_Segmentation'for img_name in os.listdir(result_path):
    img_path = os.path.join(result_path, img_name)
    img = cv2.imread(img_path)
    g  = img[:,:,1]
    ret, threshold = cv2.threshold(g, 127,255, cv2.THRESH_BINARY)


    contours, hierarch = cv2.findContours(threshold, cv2.RETR_LIST, cv2.CHAIN_APPROX_NONE)
    contours.sort(key=cnt_area, reverse=True)    if len(contours) > 1:        for i in range(1,len(contours)):
            cv2.drawContours(threshold, [contours[i]], 0, 0, -1)
    _,result = cv2.threshold(threshold, 127, 255, cv2.THRESH_BINARY_INV)
    cv2.imwrite(os.path.join(dist_path, img_name), result)
登录后复制
   

以上就是飞桨常规赛:PALM眼底彩照视盘探测与分割 2021 5月第1名方案的详细内容,更多请关注php中文网其它相关文章!

最佳 Windows 性能的顶级免费优化软件
最佳 Windows 性能的顶级免费优化软件

每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。

下载
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号