MCPcopy
hub / github.com/qqwweee/keras-yolo3 / create_tiny_model

Function create_tiny_model

train.py:135–163  ·  view source on GitHub ↗

create the training model, for Tiny YOLOv3

(input_shape, anchors, num_classes, load_pretrained=True, freeze_body=2,
            weights_path='model_data/tiny_yolo_weights.h5')

Source from the content-addressed store, hash-verified

133 return model
134
135def create_tiny_model(input_shape, anchors, num_classes, load_pretrained=True, freeze_body=2,
136 weights_path='model_data/tiny_yolo_weights.h5'):
137 '''create the training model, for Tiny YOLOv3'''
138 K.clear_session() # get a new session
139 image_input = Input(shape=(None, None, 3))
140 h, w = input_shape
141 num_anchors = len(anchors)
142
143 y_true = [Input(shape=(h//{0:32, 1:16}[l], w//{0:32, 1:16}[l], \
144 num_anchors//2, num_classes+5)) for l in range(2)]
145
146 model_body = tiny_yolo_body(image_input, num_anchors//2, num_classes)
147 print('Create Tiny YOLOv3 model with {} anchors and {} classes.'.format(num_anchors, num_classes))
148
149 if load_pretrained:
150 model_body.load_weights(weights_path, by_name=True, skip_mismatch=True)
151 print('Load weights {}.'.format(weights_path))
152 if freeze_body in [1, 2]:
153 # Freeze the darknet body or freeze all but 2 output layers.
154 num = (20, len(model_body.layers)-2)[freeze_body-1]
155 for i in range(num): model_body.layers[i].trainable = False
156 print('Freeze the first {} layers of total {} layers.'.format(num, len(model_body.layers)))
157
158 model_loss = Lambda(yolo_loss, output_shape=(1,), name='yolo_loss',
159 arguments={'anchors': anchors, 'num_classes': num_classes, 'ignore_thresh': 0.7})(
160 [*model_body.output, *y_true])
161 model = Model([model_body.input, *y_true], model_loss)
162
163 return model
164
165def data_generator(annotation_lines, batch_size, input_shape, anchors, num_classes):
166 '''data generator for fit_generator'''

Callers 1

_mainFunction · 0.85

Calls 1

tiny_yolo_bodyFunction · 0.90

Tested by

no test coverage detected