Pre-trained SqueezeNetV1 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 [conv1, maxpool1, fire2, fire3, f
(pretrained=False, end_with='out', name=None)
| 43 | |
| 44 | |
| 45 | def SqueezeNetV1(pretrained=False, end_with='out', name=None): |
| 46 | """Pre-trained SqueezeNetV1 model (static mode). Input shape [?, 224, 224, 3], value range [0, 1]. |
| 47 | |
| 48 | Parameters |
| 49 | ------------ |
| 50 | pretrained : boolean |
| 51 | Whether to load pretrained weights. Default False. |
| 52 | end_with : str |
| 53 | The end point of the model [conv1, maxpool1, fire2, fire3, fire4, ..., out]. Default ``out`` i.e. the whole model. |
| 54 | name : None or str |
| 55 | Name for this model. |
| 56 | |
| 57 | Examples |
| 58 | --------- |
| 59 | Classify ImageNet classes, see `tutorial_models_squeezenetv1.py <https://github.com/tensorlayer/tensorlayer/blob/master/example/tutorial_models_squeezenetv1.py>`__ |
| 60 | |
| 61 | >>> # get the whole model |
| 62 | >>> squeezenet = tl.models.SqueezeNetV1(pretrained=True) |
| 63 | >>> # use for inferencing |
| 64 | >>> output = squeezenet(img1, is_train=False) |
| 65 | >>> prob = tf.nn.softmax(output)[0].numpy() |
| 66 | |
| 67 | Extract features and Train a classifier with 100 classes |
| 68 | |
| 69 | >>> # get model without the last layer |
| 70 | >>> cnn = tl.models.SqueezeNetV1(pretrained=True, end_with='drop1').as_layer() |
| 71 | >>> # add one more layer and build new model |
| 72 | >>> ni = Input([None, 224, 224, 3], name="inputs") |
| 73 | >>> nn = cnn(ni) |
| 74 | >>> nn = Conv2d(100, (1, 1), (1, 1), padding='VALID', name='conv10')(nn) |
| 75 | >>> nn = GlobalMeanPool2d(name='globalmeanpool')(nn) |
| 76 | >>> model = tl.models.Model(inputs=ni, outputs=nn) |
| 77 | >>> # train your own classifier (only update the last layer) |
| 78 | >>> train_params = model.get_layer('conv10').trainable_weights |
| 79 | |
| 80 | Returns |
| 81 | ------- |
| 82 | static SqueezeNetV1. |
| 83 | |
| 84 | """ |
| 85 | ni = Input([None, 224, 224, 3], name="input") |
| 86 | n = Lambda(lambda x: x * 255, name='scale')(ni) |
| 87 | |
| 88 | for i in range(len(layer_names)): |
| 89 | if layer_names[i] == 'conv1': |
| 90 | n = Conv2d(64, (3, 3), (2, 2), tf.nn.relu, 'SAME', name='conv1')(n) |
| 91 | elif layer_names[i] == 'maxpool1': |
| 92 | n = MaxPool2d((3, 3), (2, 2), 'VALID', name='maxpool1')(n) |
| 93 | elif layer_names[i] == 'drop1': |
| 94 | n = Dropout(keep=0.5, name='drop1')(n) |
| 95 | elif layer_names[i] == 'out': |
| 96 | n = Conv2d(1000, (1, 1), (1, 1), padding='VALID', name='conv10')(n) # 13, 13, 1000 |
| 97 | n = GlobalMeanPool2d(name='globalmeanpool')(n) |
| 98 | elif layer_names[i] in ['fire3', 'fire5']: |
| 99 | n = fire_block(n, n_filters[i - 2], max_pool=True, name=layer_names[i]) |
| 100 | else: |
| 101 | n = fire_block(n, n_filters[i - 2], max_pool=False, name=layer_names[i]) |
| 102 |
nothing calls this directly
no test coverage detected
searching dependent graphs…