基于tensorflow和keras的语义分割

semantic-segmentation的Python项目详细描述


惊人的语义分割

pythontensorflowOpenCVApache

Amazing Semantic Segmentation on Tensorflow && Keras (include FCN, UNet, SegNet, PSPNet, PAN, RefineNet, DeepLabV3, DeepLabV3+, DenseASPP, BiSegNet ...)


型号

该项目支持以下语义分割模型:

  1. FCN-8s/16s/32s - Fully Convolutional Networks for Semantic Segmentation
  2. UNet - U-Net: Convolutional Networks for Biomedical Image Segmentation
  3. SegNet - SegNet:A Deep Convolutional Encoder-Decoder Architecture for Image Segmentation
  4. Bayesian-SegNet - Bayesian SegNet: Model Uncertainty in Deep Convolutional Encoder-Decoder Architectures for Scene Understanding
  5. PSPNet - Pyramid Scene Parsing Network
  6. RefineNet - RefineNet: Multi-Path Refinement Networks for High-Resolution Semantic Segmentation
  7. PAN - Pyramid Attention Network for Semantic Segmentation
  8. DeepLabV3 - Rethinking Atrous Convolution for Semantic Image Segmentation
  9. DeepLabV3Plus - Encoder-Decoder with Atrous Separable Convolution for Semantic Image Segmentation
  10. DenseASPP - DenseASPP for Semantic Segmentation in Street Scenes
  11. BiSegNet - BiSeNet: Bilateral Segmentation Network for Real-time Semantic Segmentation

基本型号

该项目支持这些骨干模型如下,您可以根据需要选择合适的基础模型。

  1. VGG16/19 - Very Deep Convolutional Networks for Large-Scale Image Recognition
  2. ResNet50/101/152 - Deep Residual Learning for Image Recognition
  3. DenseNet121/169/201/264 - Densely Connected Convolutional Networks
  4. MobileNetV1 - MobileNets: Efficient Convolutional Neural Networks for Mobile Vision Applications
  5. MobileNetV2 - MobileNetV2: Inverted Residuals and Linear Bottlenecks
  6. Xception - Xception: Deep Learning with Depthwise Separable Convolutions
  7. 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
  • opencvpip 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

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
JavaSpringMVC控制器测试打印结果JSON字符串   若catch语句返回,那个么为什么它最终会阻塞呢?   java Grails中servletContext在哪里可用?   java Jhipster:如何为现有项目启用多种语言   java异常评估SpringEL表达式:“#fields.hasErrors('something')”   java如何验证SeleniumWebDriver中的文本颜色?   java在绘图时使用JPanel坐标   java如何初始化spring启动到project?   java如何通过JDBC的PreparedStatement将UUID数组插入HyperSQL数据库   java修改JVM以跨线程序列化文件访问   Javascript到Java正则表达式   使用Java运行时调用aspell程序时出现字符集问题。getRuntime()。执行官   执行RDP时的java Sukuli按钮识别   java如何使用okhttp更改connect请求的标头   java无法创建Maven Eclipse项目