-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathssd300_training.py
64 lines (28 loc) · 1019 Bytes
/
ssd300_training.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# -*- coding: utf-8 -*-
"""
Created on Wed Jul 4 20:59:55 2018
@author: yy
"""
from keras.optimizers import Adam, SGD
from keras import backend as K
from ssd300 import SSD300
from keras_loss_function.keras_ssd_loss import SSDLoss
img_height = 300
img_width = 300
img_channels = 3
n_classes = 20
K.clear_session()
# 1: 创建模型
model = SSD300(image_size=(img_height, img_width, img_channels),
n_classes=n_classes,
mode='training')
# 2: 加载VGG16模型权重
weights_path = 'vgg/VGG_ILSVRC_16_layers_fc_reduced.h5'
model.load_weights(weights_path, by_name=True)
# 3: 优化器及loss
#adam = Adam(lr=0.001, beta_1=0.9, beta_2=0.999, epsilon=1e-08, decay=0.0)
sgd = SGD(lr=0.001, momentum=0.9, decay=0.0, nesterov=False)
ssd_loss = SSDLoss(neg_pos_ratio=3, alpha=1.0)
model.compile(optimizer=sgd, loss=ssd_loss.compute_loss)
model_path = 'path/to/trained/model.h5'
#数据加载