安装paddleSeq2.7.0版本模块-笔记

安装paddleSeq2.7.0版本模块-笔记

先安装conda和python版本
本机安装的conda 22.9.0
python2.9.12
paddle2.4.2
paddlepaddle-gpu==2.4.2 cuda10.2
安装matplotlib3.5.0版本
opencv_python-4.5.4.60-cp39-cp39-win_amd64.whl

测试采用分割模型名称:BiSeNetv2

#BiSeNetv2保证速度的同时,也能保证精度
#2020年,相关学者基于可实现实时语义分割的双向网络BiSeNet(Bilateral Segmentation Network),
# 建设性地提出了BiSeNetv2,# 以期望获得更好的语义分割精度。
# 通常来说,语义分割任务既需要低级细节,也需要高级语义。
# 就目前的语义分割模型而言,于精度相比,更多的是追求速度,因此存在着一定缺陷。
# 而BiSeNetv2则是两方兼顾且行之有效的语义分割模型。
#(Bilateral Segmentation Network) 双边分割网络

测试分割结果图效果如下所示:
左图为分割结果图,中间图是分割后合成图,右图是测试的原图

在这里插入图片描述
在这里插入图片描述

一、第一步先激活环境
conda activate base

conda activate base

安装完paddleSeq后要关闭conda激活环境
conda deactivate

conda deactivate

二、第二步安装paddleSeq版本
本机选择安装paddleSeq2.7.0版本安装没有冲突OK
(base) D:\ProgramData\Anaconda3>pip install PaddleSeg==2.7.0
(base) D:\ProgramData\Anaconda3>

(base) D:\ProgramData\Anaconda3>pip install PaddleSeg==2.7.0
(base) D:\ProgramData\Anaconda3>

升级protobuf==3.20.0为3.20.0
(base) D:\ProgramData\Anaconda3>pip install protobuf==3.20.0

(base) D:\ProgramData\Anaconda3>pip install protobuf==3.20.0
Collecting protobuf==3.20.0
  Downloading protobuf-3.20.0-cp39-cp39-win_amd64.whl (904 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 904.1/904.1 kB 510.8 kB/s eta 0:00:00
Installing collected packages: protobuf
  Attempting uninstall: protobuf
    Found existing installation: protobuf 3.19.0
    Uninstalling protobuf-3.19.0:
      Successfully uninstalled protobuf-3.19.0
Successfully installed protobuf-3.20.0
If you cannot immediately regenerate your protos, some other possible workarounds are:
 1. Downgrade the protobuf package to 3.20.x or lower.
 2. Set PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python (but this will use pure-Python parsing and will be much slower).

默认安装paddleSeq最新版2.8.0时有版本冲突问题,如下所示:

(base) D:\ProgramData\Anaconda3>pip install PaddleSeg
ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.
anaconda-project 0.11.1 requires ruamel-yaml, which is not installed.
paddlepaddle-gpu 2.4.2 requires protobuf<=3.20.0,>=3.1.0, but you have protobuf 4.24.0 which is incompatible.
conda-repo-cli 1.0.20 requires clyent==1.2.1, but you have clyent 1.2.2 which is incompatible.
conda-repo-cli 1.0.20 requires nbformat==5.4.0, but you have nbformat 5.5.0 which is incompatible.

三、paddleSeq2.7.0安装详细情况

显示Successfully installed PaddleSeg-2.7.0 sklearn-0.0
表示安装成功

(base) D:\ProgramData\Anaconda3>pip install PaddleSeg==2.7.0
Collecting PaddleSeg==2.7.0
  Downloading paddleseg-2.7.0-py3-none-any.whl (349 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 349.4/349.4 kB 271.3 kB/s eta 0:00:00
Requirement already satisfied: prettytable in d:\programdata\anaconda3\lib\site-packages (from PaddleSeg==2.7.0) (3.8.0)
Requirement already satisfied: filelock in d:\programdata\anaconda3\lib\site-packages (from PaddleSeg==2.7.0) (3.6.0)
Requirement already satisfied: pyyaml>=5.1 in d:\programdata\anaconda3\lib\site-packages (from PaddleSeg==2.7.0) (6.0)
Requirement already satisfied: opencv-python in d:\programdata\anaconda3\lib\site-packages (from PaddleSeg==2.7.0) (4.5.4.60)
Requirement already satisfied: visualdl>=2.2.0 in d:\programdata\anaconda3\lib\site-packages (from PaddleSeg==2.7.0) (2.5.3)
Requirement already satisfied: scipy in d:\programdata\anaconda3\lib\site-packages (from PaddleSeg==2.7.0) (1.9.1)
Collecting sklearn==0.0
  Downloading sklearn-0.0.tar.gz (1.1 kB)
  Preparing metadata (setup.py) ... done
Requirement already satisfied: tqdm in d:\programdata\anaconda3\lib\site-packages (from PaddleSeg==2.7.0) (4.64.1)
Requirement already satisfied: scikit-learn in d:\programdata\anaconda3\lib\site-packages (from sklearn==0.0->PaddleSeg==2.7.0) (1.0.2)
Requirement already satisfied: numpy in d:\programdata\anaconda3\lib\site-packages (from visualdl>=2.2.0->PaddleSeg==2.7.0) (1.21.5)
Requirement already satisfied: requests in d:\programdata\anaconda3\lib\site-packages (from visualdl>=2.2.0->PaddleSeg==2.7.0) (2.28.1)
Requirement already satisfied: protobuf>=3.20.0 in d:\programdata\anaconda3\lib\site-packages (from visualdl>=2.2.0->PaddleSeg==2.7.0) (4.24.0)
Requirement already satisfied: matplotlib in d:\programdata\anaconda3\lib\site-packages (from visualdl>=2.2.0->PaddleSeg==2.7.0) (3.5.2)
Requirement already satisfied: bce-python-sdk in d:\programdata\anaconda3\lib\site-packages (from visualdl>=2.2.0->PaddleSeg==2.7.0) (0.8.87)
Requirement already satisfied: packaging in d:\programdata\anaconda3\lib\site-packages (from visualdl>=2.2.0->PaddleSeg==2.7.0) (21.3)
Requirement already satisfied: pandas in d:\programdata\anaconda3\lib\site-packages (from visualdl>=2.2.0->PaddleSeg==2.7.0) (1.4.4)
Requirement already satisfied: flask>=1.1.1 in d:\programdata\anaconda3\lib\site-packages (from visualdl>=2.2.0->PaddleSeg==2.7.0) (2.3.2)
Requirement already satisfied: Pillow>=7.0.0 in d:\programdata\anaconda3\lib\site-packages (from visualdl>=2.2.0->PaddleSeg==2.7.0) (9.2.0)
Requirement already satisfied: six>=1.14.0 in d:\programdata\anaconda3\lib\site-packages (from visualdl>=2.2.0->PaddleSeg==2.7.0) (1.16.0)
Requirement already satisfied: Flask-Babel>=3.0.0 in d:\programdata\anaconda3\lib\site-packages (from visualdl>=2.2.0->PaddleSeg==2.7.0) (3.1.0)
Requirement already satisfied: rarfile in d:\programdata\anaconda3\lib\site-packages (from visualdl>=2.2.0->PaddleSeg==2.7.0) (4.0)
Requirement already satisfied: psutil in d:\programdata\anaconda3\lib\site-packages (from visualdl>=2.2.0->PaddleSeg==2.7.0) (5.9.0)
Requirement already satisfied: wcwidth in d:\programdata\anaconda3\lib\site-packages (from prettytable->PaddleSeg==2.7.0) (0.2.5)
Requirement already satisfied: colorama in d:\programdata\anaconda3\lib\site-packages (from tqdm->PaddleSeg==2.7.0) (0.4.5)
Requirement already satisfied: itsdangerous>=2.1.2 in d:\programdata\anaconda3\lib\site-packages (from flask>=1.1.1->visualdl>=2.2.0->PaddleSeg==2.7.0) (2.1.2)
Requirement already satisfied: Jinja2>=3.1.2 in d:\programdata\anaconda3\lib\site-packages (from flask>=1.1.1->visualdl>=2.2.0->PaddleSeg==2.7.0) (3.1.2)
Requirement already satisfied: Werkzeug>=2.3.3 in d:\programdata\anaconda3\lib\site-packages (from flask>=1.1.1->visualdl>=2.2.0->PaddleSeg==2.7.0) (2.3.6)
Requirement already satisfied: click>=8.1.3 in d:\programdata\anaconda3\lib\site-packages (from flask>=1.1.1->visualdl>=2.2.0->PaddleSeg==2.7.0) (8.1.6)
Requirement already satisfied: blinker>=1.6.2 in d:\programdata\anaconda3\lib\site-packages (from flask>=1.1.1->visualdl>=2.2.0->PaddleSeg==2.7.0) (1.6.2)
Requirement already satisfied: importlib-metadata>=3.6.0 in d:\programdata\anaconda3\lib\site-packages (from flask>=1.1.1->visualdl>=2.2.0->PaddleSeg==2.7.0) (4.11.3)
Requirement already satisfied: Babel>=2.12 in d:\programdata\anaconda3\lib\site-packages (from Flask-Babel>=3.0.0->visualdl>=2.2.0->PaddleSeg==2.7.0) (2.12.1)
Requirement already satisfied: pytz>=2022.7 in d:\programdata\anaconda3\lib\site-packages (from Flask-Babel>=3.0.0->visualdl>=2.2.0->PaddleSeg==2.7.0) (2023.3)
Requirement already satisfied: pycryptodome>=3.8.0 in d:\programdata\anaconda3\lib\site-packages (from bce-python-sdk->visualdl>=2.2.0->PaddleSeg==2.7.0) (3.18.0)
Requirement already satisfied: future>=0.6.0 in d:\programdata\anaconda3\lib\site-packages (from bce-python-sdk->visualdl>=2.2.0->PaddleSeg==2.7.0) (0.18.2)
Requirement already satisfied: python-dateutil>=2.7 in d:\programdata\anaconda3\lib\site-packages (from matplotlib->visualdl>=2.2.0->PaddleSeg==2.7.0) (2.8.2)
Requirement already satisfied: cycler>=0.10 in d:\programdata\anaconda3\lib\site-packages (from matplotlib->visualdl>=2.2.0->PaddleSeg==2.7.0) (0.11.0)
Requirement already satisfied: fonttools>=4.22.0 in d:\programdata\anaconda3\lib\site-packages (from matplotlib->visualdl>=2.2.0->PaddleSeg==2.7.0) (4.25.0)
Requirement already satisfied: pyparsing>=2.2.1 in d:\programdata\anaconda3\lib\site-packages (from matplotlib->visualdl>=2.2.0->PaddleSeg==2.7.0) (3.0.9)
Requirement already satisfied: kiwisolver>=1.0.1 in d:\programdata\anaconda3\lib\site-packages (from matplotlib->visualdl>=2.2.0->PaddleSeg==2.7.0) (1.4.2)
Requirement already satisfied: charset-normalizer<3,>=2 in d:\programdata\anaconda3\lib\site-packages (from requests->visualdl>=2.2.0->PaddleSeg==2.7.0) (2.0.4)
Requirement already satisfied: urllib3<1.27,>=1.21.1 in d:\programdata\anaconda3\lib\site-packages (from requests->visualdl>=2.2.0->PaddleSeg==2.7.0) (1.26.11)
Requirement already satisfied: idna<4,>=2.5 in d:\programdata\anaconda3\lib\site-packages (from requests->visualdl>=2.2.0->PaddleSeg==2.7.0) (3.3)
Requirement already satisfied: certifi>=2017.4.17 in d:\programdata\anaconda3\lib\site-packages (from requests->visualdl>=2.2.0->PaddleSeg==2.7.0) (2022.9.14)
Requirement already satisfied: threadpoolctl>=2.0.0 in d:\programdata\anaconda3\lib\site-packages (from scikit-learn->sklearn==0.0->PaddleSeg==2.7.0) (2.2.0)
Requirement already satisfied: joblib>=0.11 in d:\programdata\anaconda3\lib\site-packages (from scikit-learn->sklearn==0.0->PaddleSeg==2.7.0) (1.1.0)
Requirement already satisfied: zipp>=0.5 in d:\programdata\anaconda3\lib\site-packages (from importlib-metadata>=3.6.0->flask>=1.1.1->visualdl>=2.2.0->PaddleSeg==2.7.0) (3.8.0)
Requirement already satisfied: MarkupSafe>=2.0 in d:\programdata\anaconda3\lib\site-packages (from Jinja2>=3.1.2->flask>=1.1.1->visualdl>=2.2.0->PaddleSeg==2.7.0) (2.1.3)
Building wheels for collected packages: sklearn
  Building wheel for sklearn (setup.py) ... done
  Created wheel for sklearn: filename=sklearn-0.0-py2.py3-none-any.whl size=1304 sha256=292bc45b32f83827cb71ee7501b63c818b0b845e39c063fe776f07399e395fd6
  Stored in directory: c:\users\hsgpc\appdata\local\pip\cache\wheels\e4\7b\98\b6466d71b8d738a0c547008b9eb39bf8676d1ff6ca4b22af1c
Successfully built sklearn
Installing collected packages: sklearn, PaddleSeg
  Attempting uninstall: PaddleSeg
    Found existing installation: paddleseg 2.8.0
    Uninstalling paddleseg-2.8.0:
      Successfully uninstalled paddleseg-2.8.0
Successfully installed PaddleSeg-2.7.0 sklearn-0.0

(base) D:\ProgramData\Anaconda3>

四、测试训练代码

测试结果正常运行

PS E:\project\python> & D:/ProgramData/Anaconda3/python.exe e:/project/python/Seq/test.py
Connecting to https://paddleseg.bj.bcebos.com/dataset/optic_disc_seg.zip
Downloading optic_disc_seg.zip
[==================================================] 100.00%
Uncompress optic_disc_seg.zip
[==================================================] 100.00%
W0811 20:07:56.475862 16348 gpu_resources.cc:61] Please NOTE: device: 0, GPU Compute Capability: 6.1, Driver API Version: 12.2, Runtime API Version: 10.2
W0811 20:07:56.523449 16348 gpu_resources.cc:91] device: 0, cuDNN Version: 7.6.
D:\ProgramData\Anaconda3\lib\site-packages\paddle\nn\layer\norm.py:712: UserWarning: When training, we now always track global mean and variance.
  warnings.warn(
D:\ProgramData\Anaconda3\lib\site-packages\paddle\fluid\dygraph\math_op_patch.py:275: UserWarning: The dtype of left and right variables are not the same, left dtype is paddle.float32, but right dtype is paddle.int64, the right dtype will convert to paddle.float32
  warnings.warn(
2023-08-11 20:08:09 [INFO]      [TRAIN] epoch: 1, iter: 10/1000, loss: 2.6801, lr: 0.009919, batch_cost: 1.0978, reader_cost: 0.09730, ips: 3.6436 samples/sec | ETA 00:18:06
2023-08-11 20:08:13 [INFO]      [TRAIN] epoch: 1, iter: 20/1000, loss: 0.6180, lr: 0.009829, batch_cost: 0.3860, reader_cost: 0.00010, ips: 10.3626 samples/sec | ETA 00:06:18
2023-08-11 20:08:17 [INFO]      [TRAIN] epoch: 1, iter: 30/1000, loss: 0.4047, lr: 0.009739, batch_cost: 0.4011, reader_cost: 0.00020, ips: 9.9725 samples/sec | ETA 00:06:29
2023-08-11 20:08:21 [INFO]      [TRAIN] epoch: 1, iter: 40/1000, loss: 0.3404, lr: 0.009648, batch_cost: 0.4061, reader_cost: 0.00030, ips: 9.8509 samples/sec | ETA 00:06:29
2023-08-11 20:08:25 [INFO]      [TRAIN] epoch: 1, iter: 50/1000, loss: 0.3043, lr: 0.009558, batch_cost: 0.3877, reader_cost: 0.00030, ips: 10.3161 samples/sec | ETA 00:06:08
2023-08-11 20:08:28 [INFO]      [TRAIN] epoch: 1, iter: 60/1000, loss: 0.2918, lr: 0.009467, batch_cost: 0.3862, reader_cost: 0.00010, ips: 10.3586 samples/sec | ETA 00:06:02
2023-08-11 20:08:32 [INFO]      [TRAIN] epoch: 2, iter: 70/1000, loss: 0.2548, lr: 0.009377, batch_cost: 0.4038, reader_cost: 0.01672, ips: 9.9049 samples/sec | ETA 00:06:15
2023-08-11 20:08:36 [INFO]      [TRAIN] epoch: 2, iter: 80/1000, loss: 0.2641, lr: 0.009286, batch_cost: 0.3905, reader_cost: 0.00015, ips: 10.2446 samples/sec | ETA 00:05:59
2023-08-11 20:08:40 [INFO]      [TRAIN] epoch: 2, iter: 90/1000, loss: 0.2426, lr: 0.009195, batch_cost: 0.3884, reader_cost: 0.00000, ips: 10.2990 samples/sec | ETA 00:05:53
2023-08-11 20:08:44 [INFO]      [TRAIN] epoch: 2, iter: 100/1000, loss: 0.2403, lr: 0.009104, batch_cost: 0.3864, reader_cost: 0.00000, ips: 10.3526 samples/sec | ETA 00:05:47
2023-08-11 20:08:48 [INFO]      [TRAIN] epoch: 2, iter: 110/1000, loss: 0.2847, lr: 0.009013, batch_cost: 0.3890, reader_cost: 0.00010, ips: 10.2830 samples/sec | ETA 00:05:46
2023-08-11 20:08:52 [INFO]      [TRAIN] epoch: 2, iter: 120/1000, loss: 0.2442, lr: 0.008922, batch_cost: 0.3874, reader_cost: 0.00010, ips: 10.3261 samples/sec | ETA 00:05:40
2023-08-11 20:08:56 [INFO]      [TRAIN] epoch: 2, iter: 130/1000, loss: 0.2243, lr: 0.008831, batch_cost: 0.3901, reader_cost: 0.00020, ips: 10.2547 samples/sec | ETA 00:05:39
2023-08-11 20:09:00 [INFO]      [TRAIN] epoch: 3, iter: 140/1000, loss: 0.2251, lr: 0.008740, batch_cost: 0.3946, reader_cost: 0.00559, ips: 10.1366 samples/sec | ETA 00:05:39
2023-08-11 20:09:04 [INFO]      [TRAIN] epoch: 3, iter: 150/1000, loss: 0.1888, lr: 0.008648, batch_cost: 0.3949, reader_cost: 0.00000, ips: 10.1292 samples/sec | ETA 00:05:35
2023-08-11 20:09:08 [INFO]      [TRAIN] epoch: 3, iter: 160/1000, loss: 0.2272, lr: 0.008557, batch_cost: 0.3883, reader_cost: 0.00030, ips: 10.3016 samples/sec | ETA 00:05:26
2023-08-11 20:09:11 [INFO]      [TRAIN] epoch: 3, iter: 170/1000, loss: 0.1854, lr: 0.008465, batch_cost: 0.3875, reader_cost: 0.00010, ips: 10.3239 samples/sec | ETA 00:05:21
2023-08-11 20:09:15 [INFO]      [TRAIN] epoch: 3, iter: 180/1000, loss: 0.2287, lr: 0.008374, batch_cost: 0.3893, reader_cost: 0.00020, ips: 10.2751 samples/sec | ETA 00:05:19
2023-08-11 20:09:19 [INFO]      [TRAIN] epoch: 3, iter: 190/1000, loss: 0.1802, lr: 0.008282, batch_cost: 0.4025, reader_cost: 0.00030, ips: 9.9373 samples/sec | ETA 00:05:26
2023-08-11 20:09:23 [INFO]      [TRAIN] epoch: 4, iter: 200/1000, loss: 0.1878, lr: 0.008190, batch_cost: 0.3942, reader_cost: 0.00663, ips: 10.1465 samples/sec | ETA 00:05:15
2023-08-11 20:09:23 [INFO]      Start evaluating (total_samples: 76, total_iters: 76)...
76/76 [==============================] - 2s 33ms/step - batch_cost: 0.0325 - reader cost: 3.1596e-04
2023-08-11 20:09:26 [INFO]      [EVAL] #Images: 76 mIoU: 0.7409 Acc: 0.9900 Kappa: 0.6546 Dice: 0.8271
2023-08-11 20:09:26 [INFO]      [EVAL] Class IoU: 
[0.9899 0.4919]
2023-08-11 20:09:26 [INFO]      [EVAL] Class Precision: 
[0.9912 0.8759]
2023-08-11 20:09:26 [INFO]      [EVAL] Class Recall:
[0.9986 0.5287]
2023-08-11 20:09:26 [INFO]      [EVAL] The model with the best validation mIoU (0.7409) was saved at iter 200.

test.py

# 构建训练用的数据增强和预处理
import paddleseg.transforms as T
transforms = [
    T.Resize(target_size=(512, 512)),
    T.RandomHorizontalFlip(),
    T.Normalize()
]

# 构建训练集
from paddleseg.datasets import OpticDiscSeg
train_dataset = OpticDiscSeg(
    dataset_root='data/optic_disc_seg',
    transforms=transforms,
    mode='train'
)

from paddleseg.models import BiSeNetV2
model = BiSeNetV2(num_classes=2,
                 lambd=0.25,
                 align_corners=False,
                 pretrained=None)

# 构建验证用的数据增强和预处理
import paddleseg.transforms as T
transforms = [
    T.Resize(target_size=(512, 512)),
    T.Normalize()
]

# 构建验证集
from paddleseg.datasets import OpticDiscSeg
val_dataset = OpticDiscSeg(
    dataset_root='data/optic_disc_seg',
    transforms=transforms,
    mode='val'
)

import paddle
# 设置学习率
base_lr = 0.01
lr = paddle.optimizer.lr.PolynomialDecay(base_lr, power=0.9, decay_steps=1000, end_lr=0)

optimizer = paddle.optimizer.Momentum(lr, parameters=model.parameters(), momentum=0.9, weight_decay=4.0e-5)

from paddleseg.models.losses import CrossEntropyLoss
losses = {}
losses['types'] = [CrossEntropyLoss()] * 5
losses['coef'] = [1]* 5

print(losses)  #构造字典的值
#losses={
# 'types': [CrossEntropyLoss(), CrossEntropyLoss(), CrossEntropyLoss(), CrossEntropyLoss(), CrossEntropyLoss()], 
# 'coef': [1, 1, 1, 1, 1]
# }

from paddleseg.core import train
train(
    model=model,
    train_dataset=train_dataset,
    val_dataset=val_dataset,
    optimizer=optimizer,
    save_dir='output',
    iters=1000,
    batch_size=4,
    save_interval=200,
    log_iters=10,
    num_workers=0,
    losses=losses,
    use_vdl=True)

五、评估结果

#optic disc seq 视盘分割  测试
import paddle
#模型评估
#============================================
#构建模型
from paddleseg.models import BiSeNetV2
model = BiSeNetV2(num_classes=2,
                 lambd=0.25,
                 align_corners=False,
                 pretrained=None)
#============================================
#BiSeNetv2保证速度的同时,也能保证精度
#2020年,相关学者基于可实现实时语义分割的双向网络BiSeNet(Bilateral Segmentation Network),
# 建设性地提出了BiSeNetv2,# 以期望获得更好的语义分割精度。
# 通常来说,语义分割任务既需要低级细节,也需要高级语义。
# 就目前的语义分割模型而言,于精度相比,更多的是追求速度,因此存在着一定缺陷。
# 而BiSeNetv2则是两方兼顾且行之有效的语义分割模型。
#(Bilateral Segmentation Network) 双边分割网络

#加载模型参数
model_path = 'output/best_model/model.pdparams'
if model_path:
    para_state_dict = paddle.load(model_path)
    model.set_dict(para_state_dict)
    print('Loaded trained params of model successfully')
else: 
    raise ValueError('The model_path is wrong: {}'.format(model_path))

# 构建验证集
# 构建验证用的transforms
import paddleseg.transforms as T
transforms = [
    T.Resize(target_size=(512, 512)),
    T.Normalize()
]

# 构建验证集
from paddleseg.datasets import OpticDiscSeg
val_dataset = OpticDiscSeg(
    dataset_root='data/optic_disc_seg',
    transforms=transforms,
    mode='val'
)   

#评估
from paddleseg.core import evaluate
#evaluate(model,val_dataset)
'''
评估结果:准确率Acc: 0.9942
平均交并比:mIoU: 0.8601=(0.9941+0.7262)/2
2023-08-12 12:06:05 [INFO]      [EVAL] #Images: 76 mIoU: 0.8601 Acc: 0.9942 Kappa: 0.8384 Dice: 0.9192
2023-08-12 12:06:05 [INFO]      [EVAL] Class IoU:      [0.9941 0.7262]
2023-08-12 12:06:05 [INFO]      [EVAL] Class Precision:[0.9969 0.8497]
2023-08-12 12:06:05 [INFO]      [EVAL] Class Recall:   [0.9972 0.8331]
'''

#多尺度+翻转评估
evaluate(
        model,
        val_dataset,
        aug_eval=True,
        scales=[0.75, 1.0, 1.25],
        flip_horizontal=True)

#
'''
评估结果:准确率Acc: 0.9943
平均交并比:mIoU: 0.8629=(0.9942+0.7315)/2
2023-08-12 12:14:34 [INFO]      [EVAL] #Images: 76 mIoU: 0.8629 Acc: 0.9943 Kappa: 0.8421 Dice: 0.9210
2023-08-12 12:14:34 [INFO]      [EVAL] Class IoU:      [0.9942 0.7315]
2023-08-12 12:14:34 [INFO]      [EVAL] Class Precision:[0.9971 0.8459]
2023-08-12 12:14:34 [INFO]      [EVAL] Class Recall:   [0.9971 0.844 ]
'''   

六、预测结果代码

#predict  预测
#效果可视化

#构建模型
from paddleseg.models import BiSeNetV2
model = BiSeNetV2(num_classes=2,
                 lambd=0.25,
                 align_corners=False,
                 pretrained=None)

#创建transform
import paddleseg.transforms as T
transforms = T.Compose([
    T.Resize(target_size=(512, 512)),
    T.RandomHorizontalFlip(),
    T.Normalize()
])

#构建待预测的图像列表
import os
def get_image_list(image_path):
    """Get image list"""
    valid_suffix = [
        '.JPEG', '.jpeg', '.JPG', '.jpg', '.BMP', '.bmp', '.PNG', '.png'
    ]
    image_list = []
    image_dir = None
    if os.path.isfile(image_path):
        if os.path.splitext(image_path)[-1] in valid_suffix:
            image_list.append(image_path)
    elif os.path.isdir(image_path):
        image_dir = image_path
        for root, dirs, files in os.walk(image_path):
            for f in files:
                if os.path.splitext(f)[-1] in valid_suffix:
                    image_list.append(os.path.join(root, f))
    else:
        raise FileNotFoundError(
            '`--image_path` is not found. it should be an image file or a directory including images'
        )

    if len(image_list) == 0:
        raise RuntimeError('There are not image file in `--image_path`')

    return image_list, image_dir

#====================================================================================
image_path = 'data/optic_disc_seg/JPEGImages/N0010.jpg' # 也可以输入一个包含图像的目录   N0010.jpg/N0058/P0091
image_list, image_dir = get_image_list(image_path)    
#====================================================================================
#预测
#=========================================
#预测输出结果保存到save_dir目录下 
from paddleseg.core import predict
predict(
        model,
        model_path='output/best_model/model.pdparams',
        transforms=transforms,
        image_list=image_list,
        image_dir=image_dir,
        save_dir='Seq/output/results'
    )
#=========================================
#copy old image to output dir
import os
from shutil import copyfile
copyfile(image_path,'Seq/output/'+os.path.basename(image_path))
               

—the—end—

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:/a/73750.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

Android 项目导入高德SDK初次上手

文章目录 一、前置知识&#xff1a;二、学习目标三、学习资料四、操作过程1、创建空项目2、高德 SDK 环境接入2.1 获取高德 key2.2下载 SDK 并导入2.2.1、下载SDK 文件2.2.2、SDK 导入项目2.2.3、清单文件配置2.2.4、隐私权限 3、显示地图 一、前置知识&#xff1a; 1、Java 基…

Server - 文字转语音 (Text to Speech) 的在线服务 TTSMaker

欢迎关注我的CSDN&#xff1a;https://spike.blog.csdn.net/ 本文地址&#xff1a;https://spike.blog.csdn.net/article/details/132287193 TTSMaker 是一款免费的文本转语音工具&#xff0c;提供语音合成服务&#xff0c;支持多种语言&#xff0c;包括英语、法语、德语、西班…

每日一题——对称的二叉树

题目 给定一棵二叉树&#xff0c;判断其是否是自身的镜像&#xff08;即&#xff1a;是否对称&#xff09; 例如&#xff1a; 下面这棵二叉树是对称的 下面这棵二叉树不对称。 数据范围&#xff1a;节点数满足 0≤n≤1000&#xff0c;节点上的值满足 ∣val∣≤1000 要求&…

Rust 复数运算,重载加减乘除运算

复数 基本概念 复数定义 由实数部分和虚数部分所组成的数&#xff0c;形如a&#xff0b;bi 。 其中a、b为实数&#xff0c;i 为“虚数单位”&#xff0c;i 的平方等于&#xff0d;1。 a、b分别叫做复数a&#xff0b;bi的实部和虚部。 当b&#xff1d;0时&#xff0c;a&am…

Java8函数式编程

ISBN: 978-7-115-38488-1 作者&#xff1a;【英】Richard Warburton 页数&#xff1a;132页 阅读时间&#xff1a;2023-08-05 推荐指数&#xff1a;★★★★★ 练习项目&#xff1a;https://github.com/RichardWarburton/java-8-lambdas-exercises 虽然这本书出版于2014年&…

前端食堂技术周刊第 93 期:7 月登陆 Web 平台的新功能、Node.js 工具箱、Nuxt3 开发技巧、MF 重构方案

美味值&#xff1a;&#x1f31f;&#x1f31f;&#x1f31f;&#x1f31f;&#x1f31f; 口味&#xff1a;橙橙冰萃美式 食堂技术周刊仓库地址&#xff1a;https://github.com/Geekhyt/weekly 大家好&#xff0c;我是童欧巴。欢迎来到前端食堂技术周刊&#xff0c;我们先来…

SQLyog中导入CSV文件入库到MySQL中

1.在数据库中新建一个表&#xff0c;设置列名&#xff08;与待导入文件一致&#xff09;&#xff0c;字段可以多出几个都可以 2.右键表名&#xff0c;导入- - >导入使用本地加载的CSV数据 选择使用加载本地CVS数据 3.指定好转义字符&#xff0c;将终止设置为,号(英文状态下…

2023牛客暑期多校训练营9-Non-Puzzle: Segment Pair

2023牛客暑期多校训练营9-Non-Puzzle: Segment Pair https://ac.nowcoder.com/acm/contest/57363/I 文章目录 2023牛客暑期多校训练营9-Non-Puzzle: Segment Pair题目大意解题思路代码 题目大意 解题思路 对于每一对 [ l i , r i ] [l_i,r_i] [li​,ri​]和 [ l i ′ , r i …

cmake-ibmtpm1682编译

1、error Ossl library is using different radix 异常解决 RADIX_BITS由 64改成32 --whole-archive CMakeFiles\ibm-tpm-my.dir/objects.a -Wl, --no-whole-archive CMakeFiles\ibm-tpm-my.dir\linklibs.rsp CMake中的 --whole-archive以及–no-whole-archive两者都是编译器…

AppStream下载元数据失败

错误&#xff1a;为仓库 AppStream 下载元数据失败 : Cannot prepare internal mirrorlist: No URLs in mirrorlist 目录 一、域名解析 二、CentOS-AppStream.repo 三、CentOS-Base.repo 四、CentOS-Extras.repo 五、rpm更新 一、域名解析 先验证 ping www.baidu.com 不…

基于C#UI Automation自动化测试

步骤 UI Automation 只适用于&#xff0c;标准的win32和 WPF程序 需要添加对UIAutomationClient、 UIAutomationProvider、 UIAutomationTypes的引用 代码 using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.D…

【ARM 调试】如何从 crash 信息找出问题原因

一、问题背景 粉丝在进行 ARM-A 系列软件编程时遇到以下问题&#xff0c;串口打印这段日志后就重启了&#xff0c;粉丝求助问是什么原因&#xff1f; Unhandled Exception in EL3. x30 0x0000000000b99b84 x0 0x00000000179a25b0 x1 …

Prometheus技术文档-基本使用-配置文件全解!!!!!

简介&#xff1a; Prometheus是一个开源的系统监控和告警系统&#xff0c;由Google的BorgMon监控系统发展而来。它主要用于监控和度量各种时间序列数据&#xff0c;比如系统性能、网络延迟、应用程序错误等。Prometheus通过采集监控数据并存储在时间序列数据库中&#xff0c;…

【apifox】如何写一份合格的 API 文档?

要想弄清楚如何开始写出一份合格的 API 文档&#xff0c;我们需要首先了解什么是 API&#xff0c;它的使用场景有哪些&#xff0c;应该具备什么样的能力。 什么是 API&#xff1f; 想象一下&#xff0c;当小 A 购入了一台新的电脑后&#xff0c;希望将显示画面投射至一块色准…

对比学习论文综述总结

第一阶段:百花齐放(18-19中) 有InstDisc(Instance Discrimination)、CPC、CMC代表工作。在这个阶段方法模型都还没有统一,目标函数也没有统一,代理任务也没有统一,所以说是一个百花齐放的时代 1 判别式代理任务---个体判别任务 1.1 Inst Dict---一个编码器+一个memory…

Redis_主从复制

8. 主从复制 8.1 简介 主从库采用读写分离的方式 读操作&#xff1a;主库、从库都可以处理写操作&#xff1a;首先写到主库执行&#xff0c;然后再将主库同步给从库。 实现读写分离&#xff0c;性能扩展 容灾快速恢复 8.2 主从复制步骤 创建一个目录 ,在root下创建一个m…

2009年下半年 软件设计师 上午试卷

博主介绍&#xff1a;✌全网粉丝3W&#xff0c;全栈开发工程师&#xff0c;从事多年软件开发&#xff0c;在大厂呆过。持有软件中级、六级等证书。可提供微服务项目搭建与毕业项目实战&#xff0c;博主也曾写过优秀论文&#xff0c;查重率极低&#xff0c;在这方面有丰富的经验…

RedisDesktopManage

RDM 简介下载安装 简介 RedisDesktopManager&#xff08;RDM&#xff09;是一个开源的跨平台图形界面工具&#xff0c;用于管理和操作 Redis 数据库。它提供了一个用户友好的界面&#xff0c;使用户能够轻松地连接、浏览、查询和修改 Redis 数据&#xff0c;而无需使用命令行界…

ubuntu部署haproxy

HAProxy是可提供高可用性、负载均衡以及基于TCP和HTTP应用的代理. 1、更新系统报 通过在终端中运行以下命令,确保所有系统包都是最新的 sudo apt updatesudo apt upgrade 2、安装Haproxy sudo apt install haproxy 设置开机自动启动haproxy服务 sudo systemctl enable h…

都说go协程性能好,这次我们来试试java协程

java 协程原理 在Java中&#xff0c;协程&#xff08;Coroutine&#xff09;是一种轻量级的线程解决方案&#xff0c;它可以在代码中实现类似于多线程的并发操作&#xff0c;但不涉及线程的创建和切换开销。 在传统的Java多线程编程模型中&#xff0c;线程的切换开销较大&…