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

Function MobileNetV1

tensorlayer/models/mobilenetv1.py:54–118  ·  view source on GitHub ↗

Pre-trained MobileNetV1 model (static mode). Input shape [?, 224, 224, 3], value range [0, 1]. Parameters ---------- pretrained : boolean Whether to load pretrained weights. Default False. end_with : str The end point of the model [conv, depth1, depth2 ... depth13, g

(pretrained=False, end_with='out', name=None)

Source from the content-addressed store, hash-verified

52
53
54def MobileNetV1(pretrained=False, end_with='out', name=None):
55 """Pre-trained MobileNetV1 model (static mode). Input shape [?, 224, 224, 3], value range [0, 1].
56
57 Parameters
58 ----------
59 pretrained : boolean
60 Whether to load pretrained weights. Default False.
61 end_with : str
62 The end point of the model [conv, depth1, depth2 ... depth13, globalmeanpool, out]. Default ``out`` i.e. the whole model.
63 name : None or str
64 Name for this model.
65
66 Examples
67 ---------
68 Classify ImageNet classes, see `tutorial_models_mobilenetv1.py <https://github.com/tensorlayer/tensorlayer/blob/master/example/tutorial_models_mobilenetv1.py>`__
69
70 >>> # get the whole model with pretrained weights
71 >>> mobilenetv1 = tl.models.MobileNetV1(pretrained=True)
72 >>> # use for inferencing
73 >>> output = mobilenetv1(img1, is_train=False)
74 >>> prob = tf.nn.softmax(output)[0].numpy()
75
76 Extract features and Train a classifier with 100 classes
77
78 >>> # get model without the last layer
79 >>> cnn = tl.models.MobileNetV1(pretrained=True, end_with='reshape').as_layer()
80 >>> # add one more layer and build new model
81 >>> ni = Input([None, 224, 224, 3], name="inputs")
82 >>> nn = cnn(ni)
83 >>> nn = Conv2d(100, (1, 1), (1, 1), name='out')(nn)
84 >>> nn = Flatten(name='flatten')(nn)
85 >>> model = tl.models.Model(inputs=ni, outputs=nn)
86 >>> # train your own classifier (only update the last layer)
87 >>> train_params = model.get_layer('out').trainable_weights
88
89 Returns
90 -------
91 static MobileNetV1.
92 """
93 ni = Input([None, 224, 224, 3], name="input")
94
95 for i in range(len(layer_names)):
96 if i == 0:
97 n = conv_block(ni, n_filters[i], strides=(2, 2), name=layer_names[i])
98 elif layer_names[i] in ['depth2', 'depth4', 'depth6', 'depth12']:
99 n = depthwise_conv_block(n, n_filters[i], strides=(2, 2), name=layer_names[i])
100 elif layer_names[i] == 'globalmeanpool':
101 n = GlobalMeanPool2d(name='globalmeanpool')(n)
102 elif layer_names[i] == 'reshape':
103 n = Reshape([-1, 1, 1, 1024], name='reshape')(n)
104 elif layer_names[i] == 'out':
105 n = Conv2d(1000, (1, 1), (1, 1), name='out')(n)
106 n = Flatten(name='flatten')(n)
107 else:
108 n = depthwise_conv_block(n, n_filters[i], name=layer_names[i])
109
110 if layer_names[i] == end_with:
111 break

Callers

nothing calls this directly

Calls 9

InputFunction · 0.90
GlobalMeanPool2dClass · 0.90
ReshapeClass · 0.90
Conv2dClass · 0.90
FlattenClass · 0.90
ModelClass · 0.90
depthwise_conv_blockFunction · 0.85
conv_blockFunction · 0.70
restore_paramsFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…