-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathalexnet.py
48 lines (41 loc) · 2.34 KB
/
alexnet.py
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
import tensorflow as tf
from constants import IMAGE_WIDTH,IMAGE_HEIGHT
def alexnet(image_height=IMAGE_HEIGHT,image_width=IMAGE_WIDTH):
return tf.keras.models.Sequential([
# Here, we use a larger 11 x 11 window to capture objects. At the same
# time, we use a stride of 4 to greatly reduce the height and width of
# the output. Here, the number of output channels is much larger than
# that in LeNet
tf.keras.layers.Conv2D(filters=96, kernel_size=11, strides=4,
activation='relu',input_shape=(image_height, image_width, 3)),
tf.keras.layers.MaxPool2D(pool_size=3, strides=2),
# Make the convolution window smaller, set padding to 2 for consistent
# height and width across the input and output, and increase the
# number of output channels
tf.keras.layers.Conv2D(filters=256, kernel_size=5, padding='same',
activation='relu'),
tf.keras.layers.MaxPool2D(pool_size=3, strides=2),
# Use three successive convolutional layers and a smaller convolution
# window. Except for the final convolutional layer, the number of
# output channels is further increased. Pooling layers are not used to
# reduce the height and width of input after the first two
# convolutional layers
tf.keras.layers.Conv2D(filters=384, kernel_size=3, padding='same',
activation='relu'),
tf.keras.layers.Conv2D(filters=384, kernel_size=3, padding='same',
activation='relu'),
tf.keras.layers.Conv2D(filters=256, kernel_size=3, padding='same',
activation='relu'),
tf.keras.layers.MaxPool2D(pool_size=3, strides=2),
tf.keras.layers.Flatten(),
# Here, the number of outputs of the fully-connected layer is several
# times larger than that in LeNet. Use the dropout layer to mitigate
# overfitting
tf.keras.layers.Dense(4096, activation='relu'),
tf.keras.layers.Dropout(0.5),
tf.keras.layers.Dense(4096, activation='relu'),
tf.keras.layers.Dropout(0.5),
# Output layer. Since we are using Fashion-MNIST, the number of
# classes is 9, instead of 1000 as in the paper
tf.keras.layers.Dense(9,activation='softmax')])
# alexnet()