API - Pretrained Models

TensorLayerX provides many pretrained models, you can easily use the whole or a part of the pretrained models via these APIs.

vgg16([pretrained, end_with, mode, name])

Pre-trained VGG16 model.

vgg19([pretrained, end_with, mode, name])

Pre-trained VGG19 model.

YOLOv4(NUM_CLASS[, pretrained])

Pre-trained YOLOv4 model.

ResNet50([pretrained, end_with, n_classes])

Pre-trained ResNet50 model.

vgg16

examples.model_zoo.vgg16(pretrained=False, end_with='outputs', mode='dynamic', name=None)[source]

Pre-trained VGG16 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 ‘static’. Default ‘dynamic’.

  • name (None or str) – A unique layer name.

Examples

Classify ImageNet classes with VGG16, see tutorial_models_vgg.py With TensorLayer TODO Modify the usage example according to the model storage location

>>> # get the whole model, without pre-trained VGG parameters
>>> vgg = vgg16()
>>> # get the whole model, restore pre-trained VGG parameters
>>> vgg = vgg16(pretrained=True)
>>> # use for inferencing
>>> output = vgg(img)
>>> probs = tlx.softmax(output)[0].numpy()

vgg19

examples.model_zoo.vgg19(pretrained=False, end_with='outputs', mode='dynamic', name=None)[source]

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 ‘static’. Default ‘dynamic’.

  • name (None or str) – A unique layer name.

Examples

Classify ImageNet classes with VGG19, see tutorial_models_vgg.py With TensorLayer

>>> # get the whole model, without pre-trained VGG parameters
>>> vgg = vgg19()
>>> # get the whole model, restore pre-trained VGG parameters
>>> vgg = vgg19(pretrained=True)
>>> # use for inferencing
>>> output = vgg(img)
>>> probs = tlx.softmax(output)[0].numpy()

YOLOv4

examples.model_zoo.YOLOv4(NUM_CLASS, pretrained=False)[source]

Pre-trained YOLOv4 model.

Parameters
  • NUM_CLASS (int) – Number of classes in final prediction.

  • pretrained (boolean) – Whether to load pretrained weights. Default False.

Examples

Object Detection with YOLOv4, see computer_vision.py With TensorLayer

>>> # get the whole model, without pre-trained YOLOv4 parameters
>>> yolov4 = YOLOv4(NUM_CLASS=80, pretrained=False)
>>> # get the whole model, restore pre-trained YOLOv4 parameters
>>> yolov4 = YOLOv4(NUM_CLASS=80, pretrained=True)
>>> # use for inferencing
>>> output = yolov4(img)

ResNet50

examples.model_zoo.ResNet50(pretrained=False, end_with='fc1000', n_classes=1000)[source]

Pre-trained ResNet50 model. Input shape [?, 224, 224, 3].

To use pretrained model, input should be in BGR format and subtracted from ImageNet mean [103.939, 116.779, 123.68].

Parameters
  • pretrained (boolean) – Whether to load pretrained weights. Default False.

  • end_with (str) – The end point of the model [conv, depth1, depth2 … depth13, globalmeanpool, out]. Default out i.e. the whole model.

  • n_classes (int) – Number of classes in final prediction.

  • name (None or str) – Name for this model.

Examples

Classify ImageNet classes, see tutorial_models_resnet50.py TODO Modify the usage example according to the model storage location

>>> # get the whole model with pretrained weights
>>> resnet = ResNet50(pretrained=True)
>>> # use for inferencing
>>> output = resnet(img1)
>>> prob = tlx.softmax(output)[0].numpy()

Extract the features before fc layer

>>> resnet = ResNet50(pretrained=True, end_with='5c')
>>> output = resnet(img1)
Returns

Return type

ResNet50 model.