Pre-trained MobileNetV1 model (static mode). 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. Defa
(pretrained=False, end_with='fc1000', n_classes=1000, name=None)
| 112 | |
| 113 | |
| 114 | def ResNet50(pretrained=False, end_with='fc1000', n_classes=1000, name=None): |
| 115 | """Pre-trained MobileNetV1 model (static mode). Input shape [?, 224, 224, 3]. |
| 116 | To use pretrained model, input should be in BGR format and subtracted from ImageNet mean [103.939, 116.779, 123.68]. |
| 117 | |
| 118 | Parameters |
| 119 | ---------- |
| 120 | pretrained : boolean |
| 121 | Whether to load pretrained weights. Default False. |
| 122 | end_with : str |
| 123 | The end point of the model [conv, depth1, depth2 ... depth13, globalmeanpool, out]. |
| 124 | Default ``out`` i.e. the whole model. |
| 125 | n_classes : int |
| 126 | Number of classes in final prediction. |
| 127 | name : None or str |
| 128 | Name for this model. |
| 129 | |
| 130 | Examples |
| 131 | --------- |
| 132 | Classify ImageNet classes, see `tutorial_models_resnet50.py` |
| 133 | |
| 134 | >>> # get the whole model with pretrained weights |
| 135 | >>> resnet = tl.models.ResNet50(pretrained=True) |
| 136 | >>> # use for inferencing |
| 137 | >>> output = resnet(img1, is_train=False) |
| 138 | >>> prob = tf.nn.softmax(output)[0].numpy() |
| 139 | |
| 140 | Extract the features before fc layer |
| 141 | >>> resnet = tl.models.ResNet50(pretrained=True, end_with='5c') |
| 142 | >>> output = resnet(img1, is_train=False) |
| 143 | |
| 144 | Returns |
| 145 | ------- |
| 146 | ResNet50 model. |
| 147 | |
| 148 | """ |
| 149 | ni = Input([None, 224, 224, 3], name="input") |
| 150 | n = Conv2d(64, (7, 7), strides=(2, 2), padding='SAME', W_init=tf.initializers.he_normal(), name='conv1')(ni) |
| 151 | n = BatchNorm(name='bn_conv1', act='relu')(n) |
| 152 | n = MaxPool2d((3, 3), strides=(2, 2), name='max_pool1')(n) |
| 153 | |
| 154 | for i, block_name in enumerate(block_names): |
| 155 | if len(block_name) == 2: |
| 156 | stage = int(block_name[0]) |
| 157 | block = block_name[1] |
| 158 | if block == 'a': |
| 159 | strides = (1, 1) if stage == 2 else (2, 2) |
| 160 | n = conv_block(n, 3, block_filters[stage - 2], stage=stage, block=block, strides=strides) |
| 161 | else: |
| 162 | n = identity_block(n, 3, block_filters[stage - 2], stage=stage, block=block) |
| 163 | elif block_name == 'avg_pool': |
| 164 | n = GlobalMeanPool2d(name='avg_pool')(n) |
| 165 | elif block_name == 'fc1000': |
| 166 | n = Dense(n_classes, name='fc1000')(n) |
| 167 | |
| 168 | if block_name == end_with: |
| 169 | break |
| 170 | |
| 171 | network = Model(inputs=ni, outputs=n, name=name) |
nothing calls this directly
no test coverage detected
searching dependent graphs…