Plot the input tensor with the optional bounding box and save it to disk. Args: tensor (tensor): a tensor with shape of `NxCxHxW`. bboxes (tuple): bounding boxes with format of [[x, y, h, w]]. texts (tuple): a tuple of string to plot. path (str): path to the
(tensor, bboxes=(), texts=(), path="./tmp_vis.png")
| 222 | |
| 223 | |
| 224 | def plot_input(tensor, bboxes=(), texts=(), path="./tmp_vis.png"): |
| 225 | """ |
| 226 | Plot the input tensor with the optional bounding box and save it to disk. |
| 227 | Args: |
| 228 | tensor (tensor): a tensor with shape of `NxCxHxW`. |
| 229 | bboxes (tuple): bounding boxes with format of [[x, y, h, w]]. |
| 230 | texts (tuple): a tuple of string to plot. |
| 231 | path (str): path to the image to save to. |
| 232 | """ |
| 233 | tensor = tensor.float() |
| 234 | tensor = tensor - tensor.min() |
| 235 | tensor = tensor / tensor.max() |
| 236 | f, ax = plt.subplots(nrows=1, ncols=tensor.shape[0], figsize=(50, 20)) |
| 237 | for i in range(tensor.shape[0]): |
| 238 | ax[i].axis("off") |
| 239 | ax[i].imshow(tensor[i].permute(1, 2, 0)) |
| 240 | # ax[1][0].axis('off') |
| 241 | if bboxes is not None and len(bboxes) > i: |
| 242 | for box in bboxes[i]: |
| 243 | x1, y1, x2, y2 = box |
| 244 | ax[i].vlines(x1, y1, y2, colors="g", linestyles="solid") |
| 245 | ax[i].vlines(x2, y1, y2, colors="g", linestyles="solid") |
| 246 | ax[i].hlines(y1, x1, x2, colors="g", linestyles="solid") |
| 247 | ax[i].hlines(y2, x1, x2, colors="g", linestyles="solid") |
| 248 | |
| 249 | if texts is not None and len(texts) > i: |
| 250 | ax[i].text(0, 0, texts[i]) |
| 251 | f.savefig(path) |
| 252 | |
| 253 | |
| 254 | def frozen_bn_stats(model): |
nothing calls this directly
no outgoing calls
no test coverage detected