1 parent
ec7a926163
commit
d5b6416c87
10 files changed
+93
-43
No files matched your search
+1
-1
@@ -14,7 +14,7 @@ from PIL import Image, ExifTags
|
||||
from torch.utils.data import Dataset
|
||||
from tqdm import tqdm
|
||||
|
||||
from utils.utils import xyxy2xywh, xywh2xyxy, torch_distributed_zero_first
|
||||
from utils.general import xyxy2xywh, xywh2xyxy, torch_distributed_zero_first
|
||||
|
||||
help_url = 'https://github.com/ultralytics/yolov5/wiki/Train-Custom-Data'
|
||||
img_formats = ['.bmp', '.jpg', '.jpeg', '.png', '.tif', '.tiff', '.dng']
|
||||
|
||||
@@ -18,10 +18,11 @@ import torch
|
||||
import torch.nn as nn
|
||||
import torchvision
|
||||
import yaml
|
||||
from scipy.cluster.vq import kmeans
|
||||
from scipy.signal import butter, filtfilt
|
||||
from tqdm import tqdm
|
||||
|
||||
from . import torch_utils # torch_utils, google_utils
|
||||
from utils.torch_utils import init_seeds, is_parallel
|
||||
|
||||
# Set printoptions
|
||||
torch.set_printoptions(linewidth=320, precision=5, profile='long')
|
||||
@@ -47,7 +48,7 @@ def torch_distributed_zero_first(local_rank: int):
|
||||
def init_seeds(seed=0):
|
||||
random.seed(seed)
|
||||
np.random.seed(seed)
|
||||
torch_utils.init_seeds(seed=seed)
|
||||
init_seeds(seed=seed)
|
||||
|
||||
|
||||
def get_latest_run(search_dir='./runs'):
|
||||
@@ -505,7 +506,7 @@ def compute_loss(p, targets, model): # predictions, targets, model
|
||||
|
||||
def build_targets(p, targets, model):
|
||||
# Build targets for compute_loss(), input targets(image,class,x,y,w,h)
|
||||
det = model.module.model[-1] if torch_utils.is_parallel(model) else model.model[-1] # Detect() module
|
||||
det = model.module.model[-1] if is_parallel(model) else model.model[-1] # Detect() module
|
||||
na, nt = det.na, targets.shape[0] # number of anchors, targets
|
||||
tcls, tbox, indices, anch = [], [], [], []
|
||||
gain = torch.ones(7, device=targets.device) # normalized to gridspace gain
|
||||
@@ -779,7 +780,6 @@ def kmean_anchors(path='./data/coco128.yaml', n=9, img_size=640, thr=4.0, gen=10
|
||||
wh = wh0[(wh0 >= 2.0).any(1)] # filter > 2 pixels
|
||||
|
||||
# Kmeans calculation
|
||||
from scipy.cluster.vq import kmeans
|
||||
print('Running kmeans for %g anchors on %g points...' % (n, len(wh)))
|
||||
s = wh.std(0) # sigmas for whitening
|
||||
k, dist = kmeans(wh / s, n, iter=30) # points, mean distance
|
||||
Reference in new issue
Block a user