-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtrafficSignCnn_v2.py
More file actions
36 lines (26 loc) · 1.14 KB
/
Copy pathtrafficSignCnn_v2.py
File metadata and controls
36 lines (26 loc) · 1.14 KB
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
import tensorflow as tf
from tensorflow.keras.layers import Activation
from tensorflow.keras.layers import Dense
from tensorflow.keras.layers import Dropout
# learning transfer from MobileNetV2
# learning transfer using different base network
class TrafficSignNet_v2:
@staticmethod
def build(width, height, depth, classes):
IMG_SHAPE = (width, height, 3)
chanDim = -1
base_model = tf.keras.applications.VGG16(input_shape=IMG_SHAPE,
include_top=False,
weights='imagenet')
base_model.trainable = False
# fine_tune_at = 80 * len(base_model.layers) / 100
# for layer in base_model.layers[:int(fine_tune_at)]:
# layer.trainable = False
global_average_layer = tf.keras.layers.GlobalAveragePooling2D()
model = tf.keras.Sequential()
model.add(base_model)
model.add(global_average_layer)
model.add(Dropout(0.3))
model.add(Dense(classes, kernel_regularizer=tf.keras.regularizers.l2(0.01)))
model.add(Activation("softmax"))
return model