安装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.0Downloading 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: protobufAttempting uninstall: protobufFound existing installation: protobuf 3.19.0Uninstalling 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.0Downloading 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.0Downloading 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: sklearnBuilding wheel for sklearn (setup.py) ... doneCreated wheel for sklearn: filename=sklearn-0.0-py2.py3-none-any.whl size=1304 sha256=292bc45b32f83827cb71ee7501b63c818b0b845e39c063fe776f07399e395fd6Stored in directory: c:\users\hsgpc\appdata\local\pip\cache\wheels\e4\7b\98\b6466d71b8d738a0c547008b9eb39bf8676d1ff6ca4b22af1c
Successfully built sklearn
Installing collected packages: sklearn, PaddleSegAttempting uninstall: PaddleSegFound existing installation: paddleseg 2.8.0Uninstalling 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.float32warnings.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]* 5print(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 = Noneif 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_pathfor 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—

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

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

相关文章

Oracle 开发篇+Java调用OJDBC访问Oracle数据库

标签&#xff1a;JAVA语言、Oracle数据库、Java访问Oracle数据库释义&#xff1a;OJDBC是Oracle公司提供的Java数据库连接驱动程序 ★ 实验环境 ※ Oracle 19c ※ OJDBC8 ※ JDK 8 ★ Java代码案例 package PAC_001; import java.sql.Connection; import java.sql.ResultSet…

【TensorFlow】P0 Windows GPU 安装 TensorFlow、CUDA Toolkit、cuDNN

Windows 安装 TensorFlow、CUDA Toolkit、cuDNN 整体流程概述TensorFlow 与 CUDA ToolkitTensorFlow 是一个基于数据流图的深度学习框架CUDA 充分利用 NIVIDIA GPU 的计算能力CUDA Toolkit cuDNN 安装详细流程整理流程一&#xff1a;安装 CUDA Toolkit步骤一&#xff1a;获取CU…

XML 数据传输格式

目录 XML简介 一、初识XML 1.什么是 XML&#xff1f; 2.XML 和 HTML 之间的差异 3.XML 不会做任何事情 4.通过 XML 您可以发明自己的标签 5.XML 不是对 HTML 的替代 二、XML 用途 1.XML 把数据从 HTML 分离 2.XML 简化数据共享 3.XML 简化数据传输 三、XML 树结构 1.一个 XML 文…

QML HTTP 请求

作者: 一去、二三里 个人微信号: iwaleon 微信公众号: 高效程序员 在 Web 开发中,实现与服务器的通信至关重要,其中 HTTP 便是最常用的方式之一。它是一种客户端 - 服务器协议,客户端向服务器发送请求,服务器则返回响应。常被用于在浏览器/客户端和 Web 服务器之间传输消…

1. 如何爬取自己的CSDN博客文章列表(获取列表)(博客列表)(手动+python代码方式)

文章目录 写在最前步骤打开chrome浏览器&#xff0c;登录网页按pagedown一直往下刷呀刷呀刷&#xff0c;直到把自己所有的博文刷出来然后我们按F12&#xff0c;点击选取元素按钮然后随便点一篇博文&#xff0c;产生如下所示代码然后往上翻&#xff0c;找到头&#xff0c;复制然…

Java-类型和变量(基于C语言的补充)

一个简单的Java程序 args){ System.out.println("Hello,world"); } }通过上述代码&#xff0c;我们可以看到一个完整的Java程序的结构&#xff0c;Java程序的结构由如下三个部分组成&#xff1a; 1.源文件&#xff08;扩展名为*.java)&#xff1a;源文件带有类的定义…

[保研/考研机试] KY7 质因数的个数 清华大学复试上机题 C++实现

描述 求正整数N(N>1)的质因数的个数。 相同的质因数需要重复计算。如1202*2*2*3*5&#xff0c;共有5个质因数。 输入描述&#xff1a; 可能有多组测试数据&#xff0c;每组测试数据的输入是一个正整数N&#xff0c;(1<N<10^9)。 输出描述&#xff1a; 对于每组数…

leetcode 6914. 翻倍以链表形式表示的数字

给你一个 非空 链表的头节点 head &#xff0c;表示一个不含前导零的非负数整数。 将链表 翻倍 后&#xff0c;返回头节点 head 。 示例 1&#xff1a; 输入&#xff1a;head [1,8,9] 输出&#xff1a;[3,7,8] 解释&#xff1a;上图中给出的链表&#xff0c;表示数字 189 。返…

Photoshop快捷键大全

Photoshop是一款非常强大的图像处理软件&#xff0c;它提供了许多快捷键&#xff0c;可以帮助用户更快地完成操作。熟练掌握这些快捷键&#xff0c;可以大大提高工作效率&#xff0c;让您更加专注于创作。 Photoshop快捷键汇总&#xff1a; 一、基本操作快捷键 1. 新建文档…

什么是CSS中的渐变(gradient)?如何使用CSS创建线性渐变和径向渐变?

聚沙成塔每天进步一点点 ⭐ 专栏简介⭐ 渐变&#xff08;Gradient&#xff09;在CSS中的应用⭐ 线性渐变&#xff08;Linear Gradient&#xff09;语法&#xff1a;示例&#xff1a; ⭐ 径向渐变&#xff08;Radial Gradient&#xff09;语法&#xff1a;示例&#xff1a; ⭐ 写…

第06天 静态代理和动态代理

✅作者简介&#xff1a;大家好&#xff0c;我是Leo&#xff0c;热爱Java后端开发者&#xff0c;一个想要与大家共同进步的男人&#x1f609;&#x1f609; &#x1f34e;个人主页&#xff1a;Leo的博客 &#x1f49e;当前专栏&#xff1a;每天一个知识点 ✨特色专栏&#xff1a…

【ARM Cache 系列文章 9 番外篇 -- ARMv9 系列 Core 介绍】

文章目录 ARMv9 系列CoreARM Cortex-A510 介绍ARM Cortex-A715ARM Cortex-A720 ARMv9 系列Core 2021年5月Arm公布了其最新3款CPU和3款GPU核心设计&#xff0c;三款新CPU分别是旗舰核心Cortex-X2、高性能核心Cortex-A710、高能效核心Cortex-A510 CPU&#xff0c;三款新GPU核心则…

【Unity每日一记】向量操作摄像机的移动(向量加减)

&#x1f468;‍&#x1f4bb;个人主页&#xff1a;元宇宙-秩沅 &#x1f468;‍&#x1f4bb; hallo 欢迎 点赞&#x1f44d; 收藏⭐ 留言&#x1f4dd; 加关注✅! &#x1f468;‍&#x1f4bb; 本文由 秩沅 原创 &#x1f468;‍&#x1f4bb; 收录于专栏&#xff1a;uni…

TCP消息传输可靠性保证

TCP链接与断开 -- 三次握手&四次挥手 三次握手 TCP 提供面向有连接的通信传输。面向有连接是指在数据通信开始之前先做好两端之间的准备工作。 所谓三次握手是指建立一个 TCP 连接时需要客户端和服务器端总共发送三个包以确认连接的建立。在socket编程中&#xff0c;这一…

面试热题(合并K个升序链表)

给定一个链表数组&#xff0c;每个链表都已经按升序排列。 请将所有链表合并到一个升序链表中&#xff0c;返回合并后的链表。 输入&#xff1a;lists [[1,4,5],[1,3,4],[2,6]] 输出&#xff1a;[1,1,2,3,4,4,5,6] 解释&#xff1a;链表数组如下&#xff1a; [1->4->5,1…

【软件工程】面向对象方法-RUP

RUP&#xff08;Rational Unified Process&#xff0c;统一软件开发过程&#xff09;。 RUP特点 以用况驱动的&#xff0c;以体系结构为中心的&#xff0c;迭代增量式开发 用况驱动 用况是能够向用户提供有价值结果的系统中的一种功能用况获取的是功能需求 在系统的生存周期中…

uni-app日期选择器

写个简单的日期选择器&#xff0c;还没搞样式&#xff0c;所以有点丑 大概长这样吧 首先是这个picker选择器&#xff0c;mode选择日期&#xff0c;end是写一个范围前日期&#xff0c;:end就是这个日期是动态变化的&#xff0c;还有change函数 <template><view>&l…

【pinia】Pinia入门和基本使用:

文章目录 一、 什么是pinia二、 创建空Vue项目并安装Pinia1. 创建空Vue项目2. 安装Pinia并注册 三、 实现counter四、 实现getters五、 异步action六、 storeToRefs保持响应式解构七、基本使用&#xff1a;【1】main.js【2】store》index.js【3】member.ts 一、 什么是pinia P…

安达发APS|生产计划排产软件助力加工制造业智能化转型

随着全球经济一体化的不断深入&#xff0c;市场竞争日益激烈&#xff0c;加工制造企业面临着巨大的生存压力。在这种情况下&#xff0c;企业对于生产计划的精细化管理需求日益迫切。为了适应这一市场需求&#xff0c;安达发推出了专门针对加工企业的APS生产计划排产软件&#x…

新一代构建工具 maven-mvnd

新一代构建工具 maven-mvnd mvnd的前世今生下载安装 mvndIDEA集成 mvnd的前世今生 maven 作为一代经典的构建工具&#xff0c;流行了很多年&#xff0c;知道现在依然是大部分Java项目的构建工具的首选&#xff1b;但随着项目复杂度提高&#xff0c;代码量及依赖库的增多使得ma…