temp_multinetV1.py 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. # D:/workplace/python
  2. # -*- coding: utf-8 -*-
  3. # @File :temp_multinetV1.py
  4. # @Author:Guido LuXiaohao
  5. # @Date :2020/4/13
  6. # @Software:PyCharm
  7. from keras.layers import Conv2D, MaxPooling2D, Flatten, Softmax, Activation, Dense, Dropout, Input, GlobalMaxPooling2D,GlobalAveragePooling2D,Concatenate
  8. from nets.ghostnet.utils import GhostBottleneck, reshapes, softmaxs, squeezes
  9. from keras.models import Model
  10. from keras.layers import Input, Conv2D, GlobalAveragePooling2D, Reshape, Dropout, Dense
  11. from nets.mobilenet.mobilenet_base import MobileNetBase
  12. class mutinet(MobileNetBase):
  13. def __init__(self, shape, n_class, alpha=1.0, include_top=True):
  14. super(mutinet, self).__init__(shape, n_class, alpha)
  15. self.include_top = include_top
  16. def build(self):
  17. inputs = Input(shape=self.shape)
  18. x = self._conv_block(inputs, 16, (3, 3), strides=(2, 2), nl='HS')
  19. x1 = self._bottleneck(x, 8, (3, 3), e=8, s=2, squeeze=True, nl='RE')
  20. x1 = self._bottleneck(x1, 6, (3, 3), e=18, s=2, squeeze=False, nl='RE')
  21. x1 = self._bottleneck(x1, 6, (3, 3), e=22, s=1, squeeze=False, nl='RE')
  22. x1 = self._bottleneck(x1, 10, (5, 5), e=24, s=2, squeeze=True, nl='HS')
  23. x1 = self._bottleneck(x1, 10, (5, 5), e=60, s=1, squeeze=True, nl='HS')
  24. x1 = self._bottleneck(x1, 10, (5, 5), e=60, s=1, squeeze=True, nl='HS')
  25. x1 = self._bottleneck(x1, 10, (5, 5), e=30, s=1, squeeze=True, nl='HS')
  26. x1 = self._bottleneck(x1, 12, (5, 5), e=36, s=1, squeeze=True, nl='HS')
  27. x1 = self._bottleneck(x1, 24, (5, 5), e=72, s=2, squeeze=True, nl='HS')
  28. x1 = self._bottleneck(x1, 24, (5, 5), e=144, s=1, squeeze=True, nl='HS')
  29. x1 = self._bottleneck(x1, 24, (5, 5), e=144, s=1, squeeze=True, nl='HS')
  30. x1 = self._conv_block(x1, 144, (1, 1), strides=(1, 1), nl='HS')
  31. x1 = GlobalAveragePooling2D()(x1)
  32. x2 = GhostBottleneck(x, 3, 1, 8, 8, 2, False)
  33. x2 = GhostBottleneck(x2, 3, 2, 16, 9, 2, False)
  34. x2 = GhostBottleneck(x2, 3, 1, 18, 9, 2, False)
  35. x2 = GhostBottleneck(x2, 5, 2, 24, 16, 2, True)
  36. x2 = GhostBottleneck(x2, 5, 1, 30, 20, 2, True)
  37. x2 = GhostBottleneck(x2, 3, 2, 60, 20, 2, False)
  38. x2 = GhostBottleneck(x2, 3, 1, 50, 20, 2, False)
  39. x2 = GhostBottleneck(x2, 3, 1, 46, 20, 2, False)
  40. x2 = GhostBottleneck(x2, 3, 1, 46, 20, 2, False)
  41. x2 = GhostBottleneck(x2, 3, 1, 120, 30, 2, True)
  42. x2 = GhostBottleneck(x2, 3, 1, 168, 28, 2, True)
  43. x2 = GhostBottleneck(x2, 5, 2, 168, 40, 2, True)
  44. x2 = GhostBottleneck(x2, 5, 1, 240, 40, 2, False)
  45. x2 = GhostBottleneck(x2, 5, 1, 240, 40, 2, True)
  46. x2 = GhostBottleneck(x2, 5, 1, 240, 40, 2, False)
  47. x2 = GhostBottleneck(x2, 5, 1, 240, 40, 2, True)
  48. x2 = self._conv_block(x2, 240, (1, 1), strides=(1, 1), nl='HS')
  49. x2 = GlobalAveragePooling2D()(x2)
  50. cat_layer = Concatenate(axis=-1)([x1, x2])
  51. out = Dense(256, activation='relu')(cat_layer)
  52. out = Dropout(0.5)(out)
  53. out = Dense(self.n_class, activation='softmax')(out)
  54. model = Model(inputs, out)
  55. model.summary()
  56. return model