Upload utils.py
Browse files
utils.py
CHANGED
|
@@ -275,6 +275,7 @@ def plot_image(image, boxes):
|
|
| 275 |
)
|
| 276 |
|
| 277 |
plt.show()
|
|
|
|
| 278 |
|
| 279 |
|
| 280 |
def get_evaluation_bboxes(
|
|
@@ -521,6 +522,34 @@ def plot_couple_examples(model, loader, thresh, iou_thresh, anchors):
|
|
| 521 |
bboxes[i], iou_threshold=iou_thresh, threshold=thresh, box_format="midpoint",
|
| 522 |
)
|
| 523 |
plot_image(x[i].permute(1,2,0).detach().cpu(), nms_boxes)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 524 |
|
| 525 |
|
| 526 |
|
|
|
|
| 275 |
)
|
| 276 |
|
| 277 |
plt.show()
|
| 278 |
+
return plt
|
| 279 |
|
| 280 |
|
| 281 |
def get_evaluation_bboxes(
|
|
|
|
| 522 |
bboxes[i], iou_threshold=iou_thresh, threshold=thresh, box_format="midpoint",
|
| 523 |
)
|
| 524 |
plot_image(x[i].permute(1,2,0).detach().cpu(), nms_boxes)
|
| 525 |
+
|
| 526 |
+
def plot_single_image(model, image, thresh, iou_thresh, anchors):
|
| 527 |
+
print('calling to plot single image')
|
| 528 |
+
model.eval()
|
| 529 |
+
with torch.no_grad():
|
| 530 |
+
x = image
|
| 531 |
+
print('Train begin')
|
| 532 |
+
out = model(x)
|
| 533 |
+
print('Train end')
|
| 534 |
+
bboxes = [[] for _ in range(x.shape[0])]
|
| 535 |
+
for i in range(3):
|
| 536 |
+
batch_size, A, S, _, _ = out[i].shape
|
| 537 |
+
anchor = anchors[i]
|
| 538 |
+
boxes_scale_i = cells_to_bboxes(
|
| 539 |
+
out[i], anchor, S=S, is_preds=True
|
| 540 |
+
)
|
| 541 |
+
for idx, (box) in enumerate(boxes_scale_i):
|
| 542 |
+
bboxes[idx] += box
|
| 543 |
+
|
| 544 |
+
model.train()
|
| 545 |
+
print('batch size = ',batch_size)
|
| 546 |
+
for i in range(batch_size):
|
| 547 |
+
nms_boxes = non_max_suppression(
|
| 548 |
+
bboxes[i], iou_threshold=iou_thresh, threshold=thresh, box_format="midpoint",
|
| 549 |
+
)
|
| 550 |
+
print('calling to plot bounding boxes image')
|
| 551 |
+
fig = plot_image(x[i].permute(1,2,0).detach().cpu(), nms_boxes)
|
| 552 |
+
return fig
|
| 553 |
|
| 554 |
|
| 555 |
|