瀏覽代碼

Cache bug fix (#1513)

* Caching bug fix #1508

* np.zeros((0,5)) x2
5.0
Glenn Jocher GitHub 4 年之前
父節點
當前提交
e9a0ae6f19
沒有發現已知的金鑰在資料庫的簽署中 GPG Key ID: 4AEE18F83AFDEB23
共有 3 個文件被更改,包括 6 次插入21 次删除
  1. +1
    -1
      test.py
  2. +2
    -2
      utils/datasets.py
  3. +3
    -18
      utils/plots.py

+ 1
- 1
test.py 查看文件

@@ -209,7 +209,7 @@ def test(data,
f = save_dir / f'test_batch{batch_i}_labels.jpg' # filename
plot_images(img, targets, paths, f, names) # labels
f = save_dir / f'test_batch{batch_i}_pred.jpg'
plot_images(img, output_to_target(output, width, height), paths, f, names) # predictions
plot_images(img, output_to_target(output), paths, f, names) # predictions

# Compute statistics
stats = [np.concatenate(x, 0) for x in zip(*stats)] # to numpy

+ 2
- 2
utils/datasets.py 查看文件

@@ -443,7 +443,6 @@ class LoadImagesAndLabels(Dataset): # for training/testing
assert (shape[0] > 9) & (shape[1] > 9), 'image size <10 pixels'

# verify labels
l = []
if os.path.isfile(lb_file):
nf += 1 # label found
with open(lb_file, 'r') as f:
@@ -458,6 +457,7 @@ class LoadImagesAndLabels(Dataset): # for training/testing
l = np.zeros((0, 5), dtype=np.float32)
else:
nm += 1 # label missing
l = np.zeros((0, 5), dtype=np.float32)
x[im_file] = [l, shape]
except Exception as e:
nc += 1
@@ -470,7 +470,7 @@ class LoadImagesAndLabels(Dataset): # for training/testing
print(f'WARNING: No labels found in {path}. See {help_url}')

x['hash'] = get_hash(self.label_files + self.img_files)
x['results'] = [nf, nm, ne, nc, i]
x['results'] = [nf, nm, ne, nc, i + 1]
torch.save(x, path) # save for next time
logging.info(f"New cache created: {path}")
return x

+ 3
- 18
utils/plots.py 查看文件

@@ -86,25 +86,12 @@ def plot_wh_methods(): # from utils.plots import *; plot_wh_methods()
fig.savefig('comparison.png', dpi=200)


def output_to_target(output, width, height):
def output_to_target(output):
# Convert model output to target format [batch_id, class_id, x, y, w, h, conf]
if isinstance(output, torch.Tensor):
output = output.cpu().numpy()

targets = []
for i, o in enumerate(output):
if o is not None:
for pred in o:
box = pred[:4]
w = (box[2] - box[0]) / width
h = (box[3] - box[1]) / height
x = box[0] / width + w / 2
y = box[1] / height + h / 2
conf = pred[4]
cls = int(pred[5])

targets.append([i, cls, x, y, w, h, conf])

for *box, conf, cls in o.cpu().numpy():
targets.append([i, cls, *list(*xyxy2xywh(np.array(box)[None])), conf])
return np.array(targets)


@@ -153,9 +140,7 @@ def plot_images(images, targets, paths=None, fname='images.jpg', names=None, max
labels = image_targets.shape[1] == 6 # labels if no conf column
conf = None if labels else image_targets[:, 6] # check for confidence presence (label vs pred)

boxes[[0, 2]] *= w
boxes[[0, 2]] += block_x
boxes[[1, 3]] *= h
boxes[[1, 3]] += block_y
for j, box in enumerate(boxes.T):
cls = int(classes[j])

Loading…
取消
儲存