MCPcopy
hub / github.com/tensorlayer/TensorLayer / vgg19

Function vgg19

tensorlayer/models/vgg.py:261–320  ·  view source on GitHub ↗

Pre-trained VGG19 model. Parameters ------------ pretrained : boolean Whether to load pretrained weights. Default False. end_with : str The end point of the model. Default ``fc3_relu`` i.e. the whole model. mode : str. Model building mode, 'dynamic' or 's

(pretrained=False, end_with='outputs', mode='dynamic', name=None)

Source from the content-addressed store, hash-verified

259
260
261def vgg19(pretrained=False, end_with='outputs', mode='dynamic', name=None):
262 """Pre-trained VGG19 model.
263
264 Parameters
265 ------------
266 pretrained : boolean
267 Whether to load pretrained weights. Default False.
268 end_with : str
269 The end point of the model. Default ``fc3_relu`` i.e. the whole model.
270 mode : str.
271 Model building mode, 'dynamic' or 'static'. Default 'dynamic'.
272 name : None or str
273 A unique layer name.
274
275 Examples
276 ---------
277 Classify ImageNet classes with VGG19, see `tutorial_models_vgg.py <https://github.com/tensorlayer/tensorlayer/blob/master/example/tutorial_models_vgg.py>`__
278 With TensorLayer
279
280 >>> # get the whole model, without pre-trained VGG parameters
281 >>> vgg = tl.models.vgg19()
282 >>> # get the whole model, restore pre-trained VGG parameters
283 >>> vgg = tl.models.vgg19(pretrained=True)
284 >>> # use for inferencing
285 >>> output = vgg(img, is_train=False)
286 >>> probs = tf.nn.softmax(output)[0].numpy()
287
288 Extract features with VGG19 and Train a classifier with 100 classes
289
290 >>> # get VGG without the last layer
291 >>> cnn = tl.models.vgg19(end_with='fc2_relu', mode='static').as_layer()
292 >>> # add one more layer and build a new model
293 >>> ni = Input([None, 224, 224, 3], name="inputs")
294 >>> nn = cnn(ni)
295 >>> nn = tl.layers.Dense(n_units=100, name='out')(nn)
296 >>> model = tl.models.Model(inputs=ni, outputs=nn)
297 >>> # train your own classifier (only update the last layer)
298 >>> train_params = model.get_layer('out').trainable_weights
299
300 Reuse model
301
302 >>> # in dynamic model, we can directly use the same model
303 >>> # in static model
304 >>> vgg_layer = tl.models.vgg19().as_layer()
305 >>> ni_1 = tl.layers.Input([None, 224, 244, 3])
306 >>> ni_2 = tl.layers.Input([None, 224, 244, 3])
307 >>> a_1 = vgg_layer(ni_1)
308 >>> a_2 = vgg_layer(ni_2)
309 >>> M = Model(inputs=[ni_1, ni_2], outputs=[a_1, a_2])
310
311 """
312 if mode == 'dynamic':
313 model = VGG(layer_type='vgg19', batch_norm=False, end_with=end_with, name=name)
314 elif mode == 'static':
315 model = VGG_static(layer_type='vgg19', batch_norm=False, end_with=end_with, name=name)
316 else:
317 raise Exception("No such mode %s" % mode)
318 if pretrained:

Callers

nothing calls this directly

Calls 3

VGGClass · 0.85
VGG_staticFunction · 0.85
restore_modelFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…