基于tensorflow和keras的语义分割
semantic-segmentation的Python项目详细描述
惊人的语义分割
Amazing Semantic Segmentation on Tensorflow && Keras (include FCN, UNet, SegNet, PSPNet, PAN, RefineNet, DeepLabV3, DeepLabV3+, DenseASPP, BiSegNet ...)
型号
该项目支持以下语义分割模型:
- FCN-8s/16s/32s - Fully Convolutional Networks for Semantic Segmentation
- UNet - U-Net: Convolutional Networks for Biomedical Image Segmentation
- SegNet - SegNet:A Deep Convolutional Encoder-Decoder Architecture for Image Segmentation
- Bayesian-SegNet - Bayesian SegNet: Model Uncertainty in Deep Convolutional Encoder-Decoder Architectures for Scene Understanding
- PSPNet - Pyramid Scene Parsing Network
- RefineNet - RefineNet: Multi-Path Refinement Networks for High-Resolution Semantic Segmentation
- PAN - Pyramid Attention Network for Semantic Segmentation
- DeepLabV3 - Rethinking Atrous Convolution for Semantic Image Segmentation
- DeepLabV3Plus - Encoder-Decoder with Atrous Separable Convolution for Semantic Image Segmentation
- DenseASPP - DenseASPP for Semantic Segmentation in Street Scenes
- BiSegNet - BiSeNet: Bilateral Segmentation Network for Real-time Semantic Segmentation
基本型号
该项目支持这些骨干模型如下,您可以根据需要选择合适的基础模型。
- VGG16/19 - Very Deep Convolutional Networks for Large-Scale Image Recognition
- ResNet50/101/152 - Deep Residual Learning for Image Recognition
- DenseNet121/169/201/264 - Densely Connected Convolutional Networks
- MobileNetV1 - MobileNets: Efficient Convolutional Neural Networks for Mobile Vision Applications
- MobileNetV2 - MobileNetV2: Inverted Residuals and Linear Bottlenecks
- Xception - Xception: Deep Learning with Depthwise Separable Convolutions
- Xception-DeepLab - Encoder-Decoder with Atrous Separable Convolution for Semantic Image Segmentation
数据集设置
数据集的折叠必须满足以下结构:
|-- dataset | |-- train | | |-- images | | |-- labels | |-- valid | | |-- images | | |-- labels | |-- test | | |-- images | | |-- labels
安装
- 努比
pip install numpy
- 枕头
pip install pillow
- opencv
pip install opencv-python
- 张量流
pip install tensorflow-gpu
注意:TensorFlow GPU的推荐版本是1.14或2.0。如果你的tensorflow版本更低 需要修改一些api或升级tensorflow。
用法
下载:
您可以通过以下命令下载项目:git clone git@github.com:luyanger1799/Amazing-Semantic-Segmentation.git
培训: 该项目包含完整的培训、测试和预测代码。 您可以执行这样一个简单的命令,在数据集上构建模型:
python train.py --model FCN-8s --base_model ResNet50 --dataset "dataset_path" --num_classes "num_classes"
详细的命令行参数如下:
usage: train.py [-h] --model MODEL [--base_model BASE_MODEL] --dataset DATASET --num_classes NUM_CLASSES [--random_crop RANDOM_CROP] [--crop_height CROP_HEIGHT] [--crop_width CROP_WIDTH] [--batch_size BATCH_SIZE] [--valid_batch_size VALID_BATCH_SIZE] [--num_epochs NUM_EPOCHS] [--initial_epoch INITIAL_EPOCH] [--h_flip H_FLIP] [--v_flip V_FLIP] [--brightness BRIGHTNESS [BRIGHTNESS ...]] [--rotation ROTATION] [--zoom_range ZOOM_RANGE [ZOOM_RANGE ...]] [--channel_shift CHANNEL_SHIFT] [--data_aug_rate DATA_AUG_RATE] [--checkpoint_freq CHECKPOINT_FREQ] [--validation_freq VALIDATION_FREQ] [--num_valid_images NUM_VALID_IMAGES] [--data_shuffle DATA_SHUFFLE] [--random_seed RANDOM_SEED] [--weights WEIGHTS]
optional arguments: -h, --help show this help message and exit --model MODEL Choose the semantic segmentation methods. --base_model BASE_MODEL Choose the backbone model. --dataset DATASET The path of the dataset. --num_classes NUM_CLASSES The number of classes to be segmented. --random_crop RANDOM_CROP Whether to randomly crop the image. --crop_height CROP_HEIGHT The height to crop the image. --crop_width CROP_WIDTH The width to crop the image. --batch_size BATCH_SIZE The training batch size. --valid_batch_size VALID_BATCH_SIZE The validation batch size. --num_epochs NUM_EPOCHS The number of epochs to train for. --initial_epoch INITIAL_EPOCH The initial epoch of training. --h_flip H_FLIP Whether to randomly flip the image horizontally. --v_flip V_FLIP Whether to randomly flip the image vertically. --brightness BRIGHTNESS [BRIGHTNESS ...] Randomly change the brightness (list). --rotation ROTATION The angle to randomly rotate the image. --zoom_range ZOOM_RANGE [ZOOM_RANGE ...] The times for zooming the image. --channel_shift CHANNEL_SHIFT The channel shift range. --data_aug_rate DATA_AUG_RATE The rate of data augmentation. --checkpoint_freq CHECKPOINT_FREQ How often to save a checkpoint. --validation_freq VALIDATION_FREQ How often to perform validation. --num_valid_images NUM_VALID_IMAGES The number of images used for validation. --data_shuffle DATA_SHUFFLE Whether to shuffle the data. --random_seed RANDOM_SEED The random shuffle seed. --weights WEIGHTS The path of weights to be loaded.
如果您只想在自己的培训代码中使用该模型,可以这样做:
from builders.model_builder import builder model, base_model = builder(num_classes, input_size, model='SegNet', base_model=None)
注意:如果不提供参数“base_model”,则将使用默认主干网。
测试: 类似地,您可以在自己的数据集上评估模型:
python test.py --model FCN-8s --base_model ResNet50 --dataset "dataset_path" --num_classes "num_classes" --weights "weights_path"
注意:如果参数“weights”为“none”,则将加载保存在默认路径中的重量。
预测: 您可以得到单个rgb图像的预测,如下所示:
python predict.py --model FCN-8s --base_model ResNet50 --num_classes "num_classes" --weights "weights_path" --image_path "image_path"
PYPI
或者,可以通过pypi安装项目。
pip install semantic-segmentation
您可以使用模型构建器来构建不同的模型,或者直接调用语义分割类。
from semantic_segmentation import model_builders
net, base_net = model_builders(num_classes, input_size, model='SegNet', base_model=None)
或
from semantic_segmentation import models
net = models.FCN(num_classes, version='FCN-8s')(input_size=input_size)
预先培训
由于我的计算资源有限,目前还没有预培训模式。也许将来会增加。
反馈
如果你喜欢这个作品,请给我一颗星星!如果你发现 如有任何错误或建议,请与我联系。
github:luyanger1799
电子邮件:luyanger1799@outlook.com