mxnet.gluon.model_zoo.vision

Module for pre-defined neural network models.

This module contains definitions for the following model architectures: - AlexNet - DenseNet - Inception V3 - ResNet V1 - ResNet V2 - SqueezeNet - VGG - MobileNet - MobileNetV2

You can construct a model with random weights by calling its constructor:

from mxnet.gluon.model_zoo import vision
resnet18 = vision.resnet18_v1()
alexnet = vision.alexnet()
squeezenet = vision.squeezenet1_0()
densenet = vision.densenet_161()

We provide pre-trained models for all the listed models. These models can constructed by passing pretrained=True:

from mxnet.gluon.model_zoo import vision
resnet18 = vision.resnet18_v1(pretrained=True)
alexnet = vision.alexnet(pretrained=True)

All pre-trained models expect input images normalized in the same way, i.e. mini-batches of 3-channel RGB images of shape (N x 3 x H x W), where N is the batch size, and H and W are expected to be at least 224. The images have to be loaded in to a range of [0, 1] and then normalized using mean = [0.485, 0.456, 0.406] and std = [0.229, 0.224, 0.225]. The transformation should preferrably happen at preprocessing. You can use mx.image.color_normalize for such transformation:

image = image/255
normalized = mx.image.color_normalize(image,
                                      mean=mx.np.array([0.485, 0.456, 0.406]),
                                      std=mx.np.array([0.229, 0.224, 0.225]))

Functions

get_model(name, **kwargs)

Returns a pre-defined model by name

mxnet.gluon.model_zoo.vision.get_model(name, **kwargs)[source]

Returns a pre-defined model by name

Parameters:
  • name (str) – Name of the model.

  • pretrained (bool) – Whether to load the pretrained weights for model.

  • classes (int) – Number of classes for the output layer.

  • ctx (Context, default CPU) – The context in which to load the pretrained weights.

  • root (str, default '$MXNET_HOME/models') – Location for keeping the model parameters.

Returns:

The model.

Return type:

gluon.HybridBlock

Modules

alexnet([pretrained, device, root])

AlexNet model from the "One weird trick..." paper.

densenet

DenseNet, implemented in Gluon.

inception

Inception, implemented in Gluon.

mobilenet

MobileNet and MobileNetV2, implemented in Gluon.

resnet

ResNets, implemented in Gluon.

squeezenet

SqueezeNet, implemented in Gluon.

vgg

VGG, implemented in Gluon.