DeepLabV3+代码地址:https://github.com/bonlime/keras-deeplab-v3-plus
一、本机环境:
Keras=2.2.4
Tensorflow=1.8.0
二、测试时出现的问题
在本地测试时,出现一些问题,主要原因是我的tensorflow的版本太低,一些函数方法的用法在不同版本上不一致导致的,我主要遇到下面两个问题
2.1、导入包问题
get_source_inputs导入错误
from tensorflow.python.keras.utils.layer_utils import get_source_inputs
改为:
from keras.engine.topology import get_source_inputs
get_file导入错误
from tensorflow.python.keras.utils.data_utils import get_file
改为:
from tensorflow.python.keras.utils import get_file
2.2、AttributeError: module ‘tensorflow.tools.api.generator.api.compat’ has no attribute ‘v1’ 错误
这里主要用到了tensorflow的resize()方法.
如下面这句话
x = Lambda(lambda xx: tf.compat.v1.image.resize(xx,size_before3[1:3],method='bilinear', align_corners=True))(x)
在我的1.8版本的tensorflow中使用直接报错
改为:
x = Lambda(lambda xx: tf.image.resize_bilinear(xx, size_before3[1:3], align_corners=True))(x)
3、模型输出测试
from tensorflow.python.keras.utils import plot_model
from model import Deeplabv3
# deeplab_model = Deeplabv3(input_shape=(512,512,3),classes=3)
deeplab_model = Deeplabv3(input_shape=(512,512,3),classes=3,backbone='xception')
print(deeplab_model.summary())
plot_model(deeplab_model,"deeplab_model_xception.png")