img_data
ImgData
¶
Bases: OrderedDict
A container for image related data.
This class is intentionally not @traceable.
This class is useful for automatically laying out collections of images for comparison and visualization.
d = fe.util.ImgData(y=tf.ones((4,)), x=0.5*tf.ones((4, 32, 32, 3)))
fig = d.paint_figure()
plt.show()
img = 0.5*np.ones((4, 32, 32, 3))
mask = np.zeros_like(img)
mask[0, 10:20, 10:30, :] = [1, 0, 0]
mask[1, 5:15, 5:20, :] = [0, 1, 0]
bbox = np.array([[[3,7,10,6,'box1'], [20,20,8,8,'box2']]]*4)
d = fe.util.ImgData(y=tf.ones((4,)), x=[img, mask, bbox])
fig = d.paint_figure()
plt.show()
Parameters:
Name | Type | Description | Default |
---|---|---|---|
colormap |
str
|
What colormap to use when rendering greyscale images. A good colorization option is 'inferno'. |
'Greys'
|
**kwargs |
Union[Tensor, List[Tensor]]
|
image_title / image pairs for visualization. Images with the same batch dimensions will be laid out side-by-side, with earlier kwargs entries displayed further to the left. The value part of the key/value pair can be a list of tensors, in which case the elements of the list are overlaid. This can be useful for displaying masks and bounding boxes on top of images. In such cases, the largest image should be put as the first entry in the list. Bounding boxes should be shaped like (batch, n_boxes, box), where each box is formatted like (x0, y0, width, height[, label]). |
{}
|
Raises:
Type | Description |
---|---|
AssertionError
|
If a list of Tensors is provided as an input, but that list has an inconsistent batch dimension. |
Source code in fastestimator\fastestimator\util\img_data.py
30 31 32 33 34 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 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 |
|
paint_figure
¶
Visualize the current ImgData entries in a matplotlib figure.
d = fe.util.ImgData(y=tf.ones((4,)), x=0.5*tf.ones((4, 32, 32, 3)))
fig = d.paint_figure()
plt.show()
Parameters:
Name | Type | Description | Default |
---|---|---|---|
height_gap |
int
|
How much space to put between each row. |
100
|
min_height |
int
|
The minimum height of a row. |
200
|
width_gap |
int
|
How much space to put between each column. |
50
|
min_width |
int
|
The minimum width of a column. |
200
|
dpi |
int
|
The resolution of the image to display. |
96
|
save_path |
Optional[str]
|
If provided, the figure will be saved to the given path. |
None
|
Returns:
Type | Description |
---|---|
plt.Figure
|
The handle to the generated matplotlib figure. |
Source code in fastestimator\fastestimator\util\img_data.py
paint_numpy
¶
Visualize the current ImgData entries into an image stored in a numpy array.
d = fe.util.ImgData(y=tf.ones((4,)), x=0.5*tf.ones((4, 32, 32, 3)))
img = d.paint_numpy()
plt.imshow(img[0])
plt.show()
Parameters:
Name | Type | Description | Default |
---|---|---|---|
height_gap |
int
|
How much space to put between each row. |
100
|
min_height |
int
|
The minimum height of a row. |
200
|
width_gap |
int
|
How much space to put between each column. |
50
|
min_width |
int
|
The minimum width of a column. |
200
|
dpi |
int
|
The resolution of the image to display. |
96
|
Returns:
Type | Description |
---|---|
np.ndarray
|
A numpy array with dimensions (1, height, width, 3) containing an image representation of this ImgData. |