Skip to content

Commit

Permalink
Grid indices overflow bug fix (#1313)
Browse files Browse the repository at this point in the history
  • Loading branch information
glenn-jocher committed Nov 6, 2020
1 parent bd5cfff commit fed5d9c
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions utils/general.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import glob
import logging
import math
import os
import platform
import random
Expand All @@ -12,7 +13,6 @@
from pathlib import Path

import cv2
import math
import matplotlib
import matplotlib.pyplot as plt
import numpy as np
Expand Down Expand Up @@ -589,7 +589,7 @@ def build_targets(p, targets, model):

# Append
a = t[:, 6].long() # anchor indices
indices.append((b, a, gj, gi)) # image, anchor, grid indices
indices.append((b, a, gj.clamp_(0, gain[3]), gi.clamp_(0, gain[2]))) # image, anchor, grid indices
tbox.append(torch.cat((gxy - gij, gwh), 1)) # box
anch.append(anchors[a]) # anchors
tcls.append(c) # class
Expand Down Expand Up @@ -1096,7 +1096,8 @@ def plot_images(images, targets, paths=None, fname='images.jpg', names=None, max
cv2.rectangle(mosaic, (block_x, block_y), (block_x + w, block_y + h), (255, 255, 255), thickness=3)

if fname is not None:
mosaic = cv2.resize(mosaic, (int(ns * w * 0.5), int(ns * h * 0.5)), interpolation=cv2.INTER_AREA)
r = min(1280. / max(h, w) / ns, 1.0) # ratio to limit image size
mosaic = cv2.resize(mosaic, (int(ns * w * r), int(ns * h * r)), interpolation=cv2.INTER_AREA)
# cv2.imwrite(fname, cv2.cvtColor(mosaic, cv2.COLOR_BGR2RGB)) # cv2 save
Image.fromarray(mosaic).save(fname) # PIL save
return mosaic
Expand Down

0 comments on commit fed5d9c

Please sign in to comment.