123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- # D:/workplace/python
- # -*- coding: utf-8 -*-
- # @File :temp_multinetV1.py
- # @Author:Guido LuXiaohao
- # @Date :2020/4/13
- # @Software:PyCharm
- from keras.layers import Conv2D, MaxPooling2D, Flatten, Softmax, Activation, Dense, Dropout, Input, GlobalMaxPooling2D,GlobalAveragePooling2D,Concatenate
- from nets.ghostnet.utils import GhostBottleneck, reshapes, softmaxs, squeezes
- from keras.models import Model
- from keras.layers import Input, Conv2D, GlobalAveragePooling2D, Reshape, Dropout, Dense
- from nets.mobilenet.mobilenet_base import MobileNetBase
- class mutinet(MobileNetBase):
- def __init__(self, shape, n_class, alpha=1.0, include_top=True):
- super(mutinet, self).__init__(shape, n_class, alpha)
- self.include_top = include_top
- def build(self):
- inputs = Input(shape=self.shape)
- x = self._conv_block(inputs, 16, (3, 3), strides=(2, 2), nl='HS')
- x1 = self._bottleneck(x, 8, (3, 3), e=8, s=2, squeeze=True, nl='RE')
- x1 = self._bottleneck(x1, 6, (3, 3), e=18, s=2, squeeze=False, nl='RE')
- x1 = self._bottleneck(x1, 6, (3, 3), e=22, s=1, squeeze=False, nl='RE')
- x1 = self._bottleneck(x1, 10, (5, 5), e=24, s=2, squeeze=True, nl='HS')
- x1 = self._bottleneck(x1, 10, (5, 5), e=60, s=1, squeeze=True, nl='HS')
- x1 = self._bottleneck(x1, 10, (5, 5), e=60, s=1, squeeze=True, nl='HS')
- x1 = self._bottleneck(x1, 10, (5, 5), e=30, s=1, squeeze=True, nl='HS')
- x1 = self._bottleneck(x1, 12, (5, 5), e=36, s=1, squeeze=True, nl='HS')
- x1 = self._bottleneck(x1, 24, (5, 5), e=72, s=2, squeeze=True, nl='HS')
- x1 = self._bottleneck(x1, 24, (5, 5), e=144, s=1, squeeze=True, nl='HS')
- x1 = self._bottleneck(x1, 24, (5, 5), e=144, s=1, squeeze=True, nl='HS')
- x1 = self._conv_block(x1, 144, (1, 1), strides=(1, 1), nl='HS')
- x1 = GlobalAveragePooling2D()(x1)
- x2 = GhostBottleneck(x, 3, 1, 8, 8, 2, False)
- x2 = GhostBottleneck(x2, 3, 2, 16, 9, 2, False)
- x2 = GhostBottleneck(x2, 3, 1, 18, 9, 2, False)
- x2 = GhostBottleneck(x2, 5, 2, 24, 16, 2, True)
- x2 = GhostBottleneck(x2, 5, 1, 30, 20, 2, True)
- x2 = GhostBottleneck(x2, 3, 2, 60, 20, 2, False)
- x2 = GhostBottleneck(x2, 3, 1, 50, 20, 2, False)
- x2 = GhostBottleneck(x2, 3, 1, 46, 20, 2, False)
- x2 = GhostBottleneck(x2, 3, 1, 46, 20, 2, False)
- x2 = GhostBottleneck(x2, 3, 1, 120, 30, 2, True)
- x2 = GhostBottleneck(x2, 3, 1, 168, 28, 2, True)
- x2 = GhostBottleneck(x2, 5, 2, 168, 40, 2, True)
- x2 = GhostBottleneck(x2, 5, 1, 240, 40, 2, False)
- x2 = GhostBottleneck(x2, 5, 1, 240, 40, 2, True)
- x2 = GhostBottleneck(x2, 5, 1, 240, 40, 2, False)
- x2 = GhostBottleneck(x2, 5, 1, 240, 40, 2, True)
- x2 = self._conv_block(x2, 240, (1, 1), strides=(1, 1), nl='HS')
- x2 = GlobalAveragePooling2D()(x2)
- cat_layer = Concatenate(axis=-1)([x1, x2])
- out = Dense(256, activation='relu')(cat_layer)
- out = Dropout(0.5)(out)
- out = Dense(self.n_class, activation='softmax')(out)
- model = Model(inputs, out)
- model.summary()
- return model
|