Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

SqueezeNet.py 7.1 KB

You have to be logged in to leave a comment. Sign In
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
  1. import h5py
  2. from keras.models import Model
  3. from keras.layers import Input, Activation, Concatenate
  4. from keras.layers import Flatten, Dropout
  5. from keras.layers import Convolution2D, MaxPooling2D
  6. from keras.layers import GlobalAveragePooling2D
  7. def SqueezeNet(nb_classes, inputs):
  8. """ Keras Implementation of SqueezeNet(arXiv 1602.07360)
  9. @param nb_classes: total number of final categories
  10. Arguments:
  11. inputs -- shape of the input images (channel, cols, rows)
  12. """
  13. input_img = Input(shape=inputs)
  14. conv1 = Convolution2D(96, (7, 7), activation='relu', kernel_initializer='glorot_uniform',
  15. strides=(2, 2), padding='same', name='conv1',
  16. data_format="channels_first")(input_img)
  17. maxpool1 = MaxPooling2D(
  18. pool_size=(3, 3), strides=(2, 2), name='maxpool1',
  19. data_format="channels_first")(conv1)
  20. fire2_squeeze = Convolution2D(
  21. 16, (1, 1), activation='relu', kernel_initializer='glorot_uniform',
  22. padding='same', name='fire2_squeeze',
  23. data_format="channels_first")(maxpool1)
  24. fire2_expand1 = Convolution2D(
  25. 64, (1, 1), activation='relu', kernel_initializer='glorot_uniform',
  26. padding='same', name='fire2_expand1',
  27. data_format="channels_first")(fire2_squeeze)
  28. fire2_expand2 = Convolution2D(
  29. 64, (3, 3), activation='relu', kernel_initializer='glorot_uniform',
  30. padding='same', name='fire2_expand2',
  31. data_format="channels_first")(fire2_squeeze)
  32. merge2 = Concatenate(axis=1)([fire2_expand1, fire2_expand2])
  33. fire3_squeeze = Convolution2D(
  34. 16, (1, 1), activation='relu', kernel_initializer='glorot_uniform',
  35. padding='same', name='fire3_squeeze',
  36. data_format="channels_first")(merge2)
  37. fire3_expand1 = Convolution2D(
  38. 64, (1, 1), activation='relu', kernel_initializer='glorot_uniform',
  39. padding='same', name='fire3_expand1',
  40. data_format="channels_first")(fire3_squeeze)
  41. fire3_expand2 = Convolution2D(
  42. 64, (3, 3), activation='relu', kernel_initializer='glorot_uniform',
  43. padding='same', name='fire3_expand2',
  44. data_format="channels_first")(fire3_squeeze)
  45. merge3 = Concatenate(axis=1)([fire3_expand1, fire3_expand2])
  46. fire4_squeeze = Convolution2D(
  47. 32, (1, 1), activation='relu', kernel_initializer='glorot_uniform',
  48. padding='same', name='fire4_squeeze',
  49. data_format="channels_first")(merge3)
  50. fire4_expand1 = Convolution2D(
  51. 128, (1, 1), activation='relu', kernel_initializer='glorot_uniform',
  52. padding='same', name='fire4_expand1',
  53. data_format="channels_first")(fire4_squeeze)
  54. fire4_expand2 = Convolution2D(
  55. 128, (3, 3), activation='relu', kernel_initializer='glorot_uniform',
  56. padding='same', name='fire4_expand2',
  57. data_format="channels_first")(fire4_squeeze)
  58. merge4 = Concatenate(axis=1)([fire4_expand1, fire4_expand2])
  59. maxpool4 = MaxPooling2D(
  60. pool_size=(3, 3), strides=(2, 2), name='maxpool4',
  61. data_format="channels_first")(merge4)
  62. fire5_squeeze = Convolution2D(
  63. 32, (1, 1), activation='relu', kernel_initializer='glorot_uniform',
  64. padding='same', name='fire5_squeeze',
  65. data_format="channels_first")(maxpool4)
  66. fire5_expand1 = Convolution2D(
  67. 128, (1, 1), activation='relu', kernel_initializer='glorot_uniform',
  68. padding='same', name='fire5_expand1',
  69. data_format="channels_first")(fire5_squeeze)
  70. fire5_expand2 = Convolution2D(
  71. 128, (3, 3), activation='relu', kernel_initializer='glorot_uniform',
  72. padding='same', name='fire5_expand2',
  73. data_format="channels_first")(fire5_squeeze)
  74. merge5 = Concatenate(axis=1)([fire5_expand1, fire5_expand2])
  75. fire6_squeeze = Convolution2D(
  76. 48, (1, 1), activation='relu', kernel_initializer='glorot_uniform',
  77. padding='same', name='fire6_squeeze',
  78. data_format="channels_first")(merge5)
  79. fire6_expand1 = Convolution2D(
  80. 192, (1, 1), activation='relu', kernel_initializer='glorot_uniform',
  81. padding='same', name='fire6_expand1',
  82. data_format="channels_first")(fire6_squeeze)
  83. fire6_expand2 = Convolution2D(
  84. 192, (3, 3), activation='relu', kernel_initializer='glorot_uniform',
  85. padding='same', name='fire6_expand2',
  86. data_format="channels_first")(fire6_squeeze)
  87. merge6 = Concatenate(axis=1)([fire6_expand1, fire6_expand2])
  88. fire7_squeeze = Convolution2D(
  89. 48, (1, 1), activation='relu', kernel_initializer='glorot_uniform',
  90. padding='same', name='fire7_squeeze',
  91. data_format="channels_first")(merge6)
  92. fire7_expand1 = Convolution2D(
  93. 192, (1, 1), activation='relu', kernel_initializer='glorot_uniform',
  94. padding='same', name='fire7_expand1',
  95. data_format="channels_first")(fire7_squeeze)
  96. fire7_expand2 = Convolution2D(
  97. 192, (3, 3), activation='relu', kernel_initializer='glorot_uniform',
  98. padding='same', name='fire7_expand2',
  99. data_format="channels_first")(fire7_squeeze)
  100. merge7 = Concatenate(axis=1)([fire7_expand1, fire7_expand2])
  101. fire8_squeeze = Convolution2D(
  102. 64, (1, 1), activation='relu', kernel_initializer='glorot_uniform',
  103. padding='same', name='fire8_squeeze',
  104. data_format="channels_first")(merge7)
  105. fire8_expand1 = Convolution2D(
  106. 256, (1, 1), activation='relu', kernel_initializer='glorot_uniform',
  107. padding='same', name='fire8_expand1',
  108. data_format="channels_first")(fire8_squeeze)
  109. fire8_expand2 = Convolution2D(
  110. 256, (3, 3), activation='relu', kernel_initializer='glorot_uniform',
  111. padding='same', name='fire8_expand2',
  112. data_format="channels_first")(fire8_squeeze)
  113. merge8 = Concatenate(axis=1)([fire8_expand1, fire8_expand2])
  114. maxpool8 = MaxPooling2D(
  115. pool_size=(3, 3), strides=(2, 2), name='maxpool8',
  116. data_format="channels_first")(merge8)
  117. fire9_squeeze = Convolution2D(
  118. 64, (1, 1), activation='relu', kernel_initializer='glorot_uniform',
  119. padding='same', name='fire9_squeeze',
  120. data_format="channels_first")(maxpool8)
  121. fire9_expand1 = Convolution2D(
  122. 256, (1, 1), activation='relu', kernel_initializer='glorot_uniform',
  123. padding='same', name='fire9_expand1',
  124. data_format="channels_first")(fire9_squeeze)
  125. fire9_expand2 = Convolution2D(
  126. 256, (3, 3), activation='relu', kernel_initializer='glorot_uniform',
  127. padding='same', name='fire9_expand2',
  128. data_format="channels_first")(fire9_squeeze)
  129. merge9 = Concatenate(axis=1)([fire9_expand1, fire9_expand2])
  130. fire9_dropout = Dropout(0.5, name='fire9_dropout')(merge9)
  131. conv10 = Convolution2D(
  132. nb_classes, (1, 1), activation='relu', kernel_initializer='glorot_uniform',
  133. padding='valid', name='conv10',
  134. data_format="channels_first")(fire9_dropout)
  135. global_avgpool10 = GlobalAveragePooling2D(data_format='channels_first')(conv10)
  136. softmax = Activation("softmax", name='softmax')(global_avgpool10)
  137. return Model(inputs=input_img, outputs=softmax)
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...