keras-deeplab-v3-plus-master

所属分类:人工智能/神经网络/深度学习
开发工具:Python
文件大小:2717KB
下载次数:4
上传日期:2020-08-01 19:53:52
上 传 者prime267
说明:  deeplab-v3-plus网络结构,利用该网络结构可以实现语义分割,分割普通影像或者遥感影像。
(Deep lab-v3-plus network structure, using this network structure can achieve semantic segmentation, segmentation of ordinary images or remote sensing images.)

文件列表:
.ipynb_checkpoints (0, 2020-04-24)
.ipynb_checkpoints\Untitled-checkpoint.ipynb (107345, 2020-04-24)
.ipynb_checkpoints\model-Copy1-checkpoint.py (23442, 2020-04-24)
.ipynb_checkpoints\model-checkpoint.py (22448, 2020-04-24)
.ipynb_checkpoints\test-checkpoint.ipynb (267811, 2020-04-24)
LICENSE (1069, 2020-04-24)
extract_weights.py (3648, 2020-04-24)
imgs (0, 2020-04-24)
imgs\image1.jpg (151959, 2020-04-24)
imgs\image2.jpg (106187, 2020-04-24)
imgs\image3.jpg (108846, 2020-04-24)
imgs\my_seg_results1.png (202212, 2020-04-24)
imgs\my_seg_results1_OS16.png (201701, 2020-04-24)
imgs\my_seg_results1_OS8.png (201618, 2020-04-24)
imgs\my_seg_results2_OS16.png (191858, 2020-04-24)
imgs\my_seg_results2_OS8.png (192425, 2020-04-24)
imgs\my_seg_results3.png (233976, 2020-04-24)
imgs\my_seg_results3_OS16.png (233169, 2020-04-24)
imgs\my_seg_results3_OS8.png (232881, 2020-04-24)
imgs\seg_results1.png (206312, 2020-04-24)
imgs\seg_results2.png (206122, 2020-04-24)
imgs\seg_results3.png (244053, 2020-04-24)
load_weights.py (1149, 2020-04-24)
model.py (22559, 2020-04-24)
requirements.txt (68, 2020-04-24)

# Keras implementation of Deeplabv3+ **This repo is not longer maintained. I won't respond to issues but will merge PR** DeepLab is a state-of-art deep learning model for semantic image segmentation. Model is based on the original TF frozen graph. It is possible to load pretrained weights into this model. Weights are directly imported from original TF checkpoint. Segmentation results of original TF model. __Output Stride = 8__




Segmentation results of this repo model with loaded weights and __OS = 8__ Results are identical to the TF model




Segmentation results of this repo model with loaded weights and __OS = 16__ Results are still good




### How to get labels Model will return tensor of shape `(batch_size, height, width, num_classes)`. To obtain labels, you need to apply argmax to logits at exit layer. Example of predicting on `image1.jpg`: ```python import numpy as np from PIL import Image from matplotlib import pyplot as plt from model import Deeplabv3 # Generates labels using most basic setup. Supports various image sizes. Returns image labels in same format # as original image. Normalization matches MobileNetV2 trained_image_width=512 mean_subtraction_value=127.5 image = np.array(Image.open('imgs/image1.jpg')) # resize to max dimension of images from training dataset w, h, _ = image.shape ratio = float(trained_image_width) / np.max([w, h]) resized_image = np.array(Image.fromarray(image.astype('uint8')).resize((int(ratio * h), int(ratio * w)))) # apply normalization for trained dataset images resized_image = (resized_image / mean_subtraction_value) - 1. # pad array to square image to match training images pad_x = int(trained_image_width - resized_image.shape[0]) pad_y = int(trained_image_width - resized_image.shape[1]) resized_image = np.pad(resized_image, ((0, pad_x), (0, pad_y), (0, 0)), mode='constant') # make prediction deeplab_model = Deeplabv3() res = deeplab_model.predict(np.expand_dims(resized_image, 0)) labels = np.argmax(res.squeeze(), -1) # remove padding and resize back to original image if pad_x > 0: labels = labels[:-pad_x] if pad_y > 0: labels = labels[:, :-pad_y] labels = np.array(Image.fromarray(labels.astype('uint8')).resize((h, w))) plt.imshow(labels) plt.waitforbuttonpress() ``` ### How to use this model with custom input shape and custom number of classes ```python from model import Deeplabv3 deeplab_model = Deeplabv3(input_shape=(384, 384, 3), classes=4) #or you can use None as shape deeplab_model = Deeplabv3(input_shape=(None, None, 3), classes=4) ``` After that you will get a usual Keras model which you can train using `.fit` and `.fit_generator` methods. ### How to train this model Useful parameters can be found in the [original repository](https://github.com/tensorflow/models/blob/master/research/deeplab/train.py). Important notes: 1. This model doesn’t provide default weight decay, user needs to add it themselves. 2. Due to huge memory use with `OS=8`, Xception backbone should be trained with `OS=16` and only inferenced with `OS=8`. 3. User can freeze feature extractor for Xception backbone (first 356 layers) and only fine-tune decoder. Right now (March 2019), there is a problem with finetuning Keras models with BN. You can read more about it [here](https://github.com/keras-team/keras/pull/9965). #### Known issues This model can be retrained [check this notebook](https://github.com/Golbstein/Keras-segmentation-deeplab-v3.1/blob/master/segmentation.ipynb). Finetuning is tricky and difficult because of the confusion between `training` and `trainable` in Keras. See [this issue](https://github.com/bonlime/keras-deeplab-v3-plus/issues/56) for a discussion and possible alternatives. ### How to load model In order to load model after using model.save() use this code: ```python from model import relu6 deeplab_model = load_model('example.h5') ``` ### Xception vs MobileNetv2 There are 2 available backbones. Xception backbone is more accurate, but has 25 times more parameters than MobileNetv2. For MobileNetv2 there are pretrained weights only for `alpha=1`. However, you can initiate model with different values of alpha. ### Requirement The latest vesrion of this repo uses TF Keras, so you only need TF 2.0+ installed tensorflow-gpu==2.0.0a0 CUDA==9.0 -------- If you want to use older version, use following commands: ```bash git clone https://github.com/bonlime/keras-deeplab-v3-plus/ cd keras-deeplab-v3-plus/ git checkout 714a6b7d1a069a07547c5c08282f1a706db92e20 ``` tensorflow-gpu==1.13 Keras==2.2.4

近期下载者

相关文件


收藏者