Grid indices overflow bug fix (#1313)
Browse files- utils/general.py +4 -3
utils/general.py
CHANGED
@@ -1,5 +1,6 @@
|
|
1 |
import glob
|
2 |
import logging
|
|
|
3 |
import os
|
4 |
import platform
|
5 |
import random
|
@@ -12,7 +13,6 @@ from copy import copy
|
|
12 |
from pathlib import Path
|
13 |
|
14 |
import cv2
|
15 |
-
import math
|
16 |
import matplotlib
|
17 |
import matplotlib.pyplot as plt
|
18 |
import numpy as np
|
@@ -589,7 +589,7 @@ def build_targets(p, targets, model):
|
|
589 |
|
590 |
# Append
|
591 |
a = t[:, 6].long() # anchor indices
|
592 |
-
indices.append((b, a, gj, gi)) # image, anchor, grid indices
|
593 |
tbox.append(torch.cat((gxy - gij, gwh), 1)) # box
|
594 |
anch.append(anchors[a]) # anchors
|
595 |
tcls.append(c) # class
|
@@ -1096,7 +1096,8 @@ def plot_images(images, targets, paths=None, fname='images.jpg', names=None, max
|
|
1096 |
cv2.rectangle(mosaic, (block_x, block_y), (block_x + w, block_y + h), (255, 255, 255), thickness=3)
|
1097 |
|
1098 |
if fname is not None:
|
1099 |
-
|
|
|
1100 |
# cv2.imwrite(fname, cv2.cvtColor(mosaic, cv2.COLOR_BGR2RGB)) # cv2 save
|
1101 |
Image.fromarray(mosaic).save(fname) # PIL save
|
1102 |
return mosaic
|
|
|
1 |
import glob
|
2 |
import logging
|
3 |
+
import math
|
4 |
import os
|
5 |
import platform
|
6 |
import random
|
|
|
13 |
from pathlib import Path
|
14 |
|
15 |
import cv2
|
|
|
16 |
import matplotlib
|
17 |
import matplotlib.pyplot as plt
|
18 |
import numpy as np
|
|
|
589 |
|
590 |
# Append
|
591 |
a = t[:, 6].long() # anchor indices
|
592 |
+
indices.append((b, a, gj.clamp_(0, gain[3]), gi.clamp_(0, gain[2]))) # image, anchor, grid indices
|
593 |
tbox.append(torch.cat((gxy - gij, gwh), 1)) # box
|
594 |
anch.append(anchors[a]) # anchors
|
595 |
tcls.append(c) # class
|
|
|
1096 |
cv2.rectangle(mosaic, (block_x, block_y), (block_x + w, block_y + h), (255, 255, 255), thickness=3)
|
1097 |
|
1098 |
if fname is not None:
|
1099 |
+
r = min(1280. / max(h, w) / ns, 1.0) # ratio to limit image size
|
1100 |
+
mosaic = cv2.resize(mosaic, (int(ns * w * r), int(ns * h * r)), interpolation=cv2.INTER_AREA)
|
1101 |
# cv2.imwrite(fname, cv2.cvtColor(mosaic, cv2.COLOR_BGR2RGB)) # cv2 save
|
1102 |
Image.fromarray(mosaic).save(fname) # PIL save
|
1103 |
return mosaic
|