| 89 | |
| 90 | |
| 91 | class VGG(Model): |
| 92 | |
| 93 | def __init__(self, layer_type, batch_norm=False, end_with='outputs', name=None): |
| 94 | super(VGG, self).__init__(name=name) |
| 95 | self.end_with = end_with |
| 96 | |
| 97 | config = cfg[mapped_cfg[layer_type]] |
| 98 | self.layers = make_layers(config, batch_norm, end_with) |
| 99 | |
| 100 | def forward(self, inputs): |
| 101 | """ |
| 102 | inputs : tensor |
| 103 | Shape [None, 224, 224, 3], value range [0, 1]. |
| 104 | """ |
| 105 | |
| 106 | inputs = inputs * 255 - np.array([123.68, 116.779, 103.939], dtype=np.float32).reshape([1, 1, 1, 3]) |
| 107 | |
| 108 | out = self.layers.forward(inputs) |
| 109 | return out |
| 110 | |
| 111 | |
| 112 | def make_layers(config, batch_norm=False, end_with='outputs'): |