model
Base class for models.
ModelBase
¶
Bases: ABC
Base class for all models
Source code in otbtf/model.py
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 |
|
__getattr__(name)
¶
This method is called when the default attribute access fails. We
choose to try to access the attribute of self.model. Thus, any method
of keras.Model()
can be used transparently, e.g. model.summary()
or model.fit()
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name |
str
|
name of the attribute |
required |
Returns:
Type | Description |
---|---|
Any
|
attribute |
Source code in otbtf/model.py
__init__(dataset_element_spec, input_keys=None, inference_cropping=None)
¶
Model initializer, must be called inside the strategy.scope().
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dataset_element_spec |
TensorSpec
|
the dataset elements specification (shape,
dtype, etc). Can be retrieved from a dataset instance |
required |
input_keys |
List[str]
|
Optional keys of the inputs used in the model. If not specified, all inputs from the dataset will be considered. |
None
|
inference_cropping |
List[int]
|
list of number of pixels to be removed on each side of the output for inference. Additional outputs are created in the model, not used during training, only during inference. Default [16, 32, 64, 96, 128] |
None
|
Source code in otbtf/model.py
create_network()
¶
This method returns the Keras model. This needs to be called inside the strategy.scope(). Can be reimplemented depending on the needs.
Returns:
Type | Description |
---|---|
Model
|
the keras model |
Source code in otbtf/model.py
get_inputs()
¶
This method returns the dict of keras.Input
Source code in otbtf/model.py
get_outputs(normalized_inputs)
abstractmethod
¶
Implementation of the model, from the normalized inputs.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
normalized_inputs |
TensorsDict
|
normalized inputs, as generated from
|
required |
Returns:
Type | Description |
---|---|
TensorsDict
|
model outputs |
Source code in otbtf/model.py
normalize_inputs(inputs)
¶
Normalize the model inputs. Takes the dict of inputs and returns a dict of normalized inputs.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
inputs |
TensorsDict
|
model inputs |
required |
Returns:
Type | Description |
---|---|
TensorsDict
|
a dict of normalized model inputs |
Source code in otbtf/model.py
plot(output_path, strategy=None, show_shapes=False)
¶
Enables to save a figure representing the architecture of the network.
Needs pydot and graphviz to work (pip install pydot
and
https://graphviz.gitlab.io/download/)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
output_path |
str
|
output path for the schema |
required |
strategy |
strategy |
None
|
|
show_shapes |
bool
|
annotate with shapes values (True or False) |
False
|
Source code in otbtf/model.py
postprocess_outputs(outputs, inputs=None, normalized_inputs=None)
¶
Post-process the model outputs. Takes the dicts of inputs and outputs, and returns a dict of post-processed outputs. The default implementation provides a set of cropped output tensors.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
outputs |
TensorsDict
|
dict of model outputs |
required |
inputs |
TensorsDict
|
dict of model inputs (optional) |
None
|
normalized_inputs |
TensorsDict
|
dict of normalized model inputs (optional) |
None
|
Returns:
Type | Description |
---|---|
TensorsDict
|
a dict of post-processed model outputs |
Source code in otbtf/model.py
summary(strategy=None)
¶
Wraps the summary printing of the model. When multiworker strategy, only prints if the worker is chief
Parameters:
Name | Type | Description | Default |
---|---|---|---|
strategy |
strategy |
None
|
Source code in otbtf/model.py
cropped_tensor_name(tensor_name, crop)
¶
A name for the padded tensor
Parameters:
Name | Type | Description | Default |
---|---|---|---|
tensor_name |
str
|
tensor name |
required |
crop |
int
|
cropping value |
required |
Returns:
Type | Description |
---|---|
name for the cropped tensor |