File size: 2,619 Bytes
e22b55b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Conv2D, Activation, BatchNormalization, Dropout, MaxPool2D
from tensorflow.keras.layers import Flatten, Dense
from tensorflow import nn as tfn
import tensorflow.keras.backend as K

class MiniVgg:
    @staticmethod
    def build(width,height,depth,classes):
        model=Sequential()
        inputShape=(height,width,depth)
        chanDim=-1

        if K.image_data_format()=="channel_first":
            inputShape=(depth,height,width)
            chanDim=1

        model.add(Conv2D(32,(5,5),input_shape=inputShape))
        model.add(Activation(tfn.relu))
        model.add(BatchNormalization(chanDim))

        model.add(Conv2D(32, (5, 5)))
        model.add(Activation(tfn.relu))
        model.add(BatchNormalization(chanDim))

        model.add(Conv2D(32, (5, 5)))
        model.add(Activation(tfn.relu))
        model.add(BatchNormalization(chanDim))

        model.add(MaxPool2D(pool_size=(2,2)))
        model.add(Dropout(0.25))
#-----------------------------------#
        model.add(Conv2D(32, (5, 5), input_shape=inputShape))
        model.add(Activation(tfn.relu))
        model.add(BatchNormalization(chanDim))

        model.add(Conv2D(32, (5, 5)))
        model.add(Activation(tfn.relu))
        model.add(BatchNormalization(chanDim))

        model.add(Conv2D(64, (5, 5)))
        model.add(Activation(tfn.relu))
        model.add(BatchNormalization(chanDim))

        model.add(MaxPool2D(pool_size=(2, 2)))
        model.add(Dropout(0.25))

#-----------------------------#

        model.add(Conv2D(64, (5, 5), input_shape=inputShape))
        model.add(Activation(tfn.relu))
        model.add(BatchNormalization(chanDim))

        model.add(Conv2D(64, (5, 5)))
        model.add(Activation(tfn.relu))
        model.add(BatchNormalization(chanDim))

        model.add(Conv2D(64, (5, 5)))
        model.add(Activation(tfn.relu))
        model.add(BatchNormalization(chanDim))

        model.add(MaxPool2D(pool_size=(2, 2)))
        model.add(Dropout(0.25))
        #-----------------------------#

        model.add(Conv2D(64, (5, 5)))
        model.add(Activation(tfn.relu))
        model.add(BatchNormalization(chanDim))
        model.add(Conv2D(64, (5, 5)))
        model.add(Activation(tfn.relu))
        model.add(BatchNormalization(chanDim))

        model.add(Flatten())
        model.add(Dense(1024))
        model.add(Activation(tfn.relu))
        model.add(BatchNormalization())
        model.add(Dropout(0.5))
        model.add(Dense(classes))
        model.add(Activation(tfn.relu))

        return model