updates
This commit is contained in:
parent
ccfd44c2f8
commit
7652365b28
|
@ -180,7 +180,7 @@ class LoadImagesAndLabels(Dataset): # for training/testing
|
||||||
|
|
||||||
# Preload labels (required for weighted CE training)
|
# Preload labels (required for weighted CE training)
|
||||||
self.labels = [np.array([])] * n
|
self.labels = [np.array([])] * n
|
||||||
iter = tqdm(self.label_files, desc='Reading labels') if n > 5000 else self.label_files
|
iter = tqdm(self.label_files, desc='Reading labels') if n > 1000 else self.label_files
|
||||||
for i, file in enumerate(iter):
|
for i, file in enumerate(iter):
|
||||||
try:
|
try:
|
||||||
with open(file, 'r') as f:
|
with open(file, 'r') as f:
|
||||||
|
|
|
@ -52,12 +52,11 @@ def model_info(model):
|
||||||
def labels_to_class_weights(labels, nc=80):
|
def labels_to_class_weights(labels, nc=80):
|
||||||
# Get class weights (inverse frequency) from training labels
|
# Get class weights (inverse frequency) from training labels
|
||||||
labels = np.concatenate(labels, 0) # labels.shape = (866643, 5) for COCO
|
labels = np.concatenate(labels, 0) # labels.shape = (866643, 5) for COCO
|
||||||
classes = labels[:, 0].astype(np.int)
|
classes = labels[:, 0].astype(np.int) # labels = [class xywh]
|
||||||
n = np.bincount(classes, minlength=nc)
|
weights = np.bincount(classes, minlength=nc) # occurences per class
|
||||||
weights = np.zeros(nc)
|
weights[weights == 0] = 1 # replace empty bins with 1
|
||||||
i = n.nonzero()
|
weights = 1 / weights # number of targets per class
|
||||||
weights[i] = 1 / n[i] # number of targets per class
|
weights /= weights.sum() # normalize
|
||||||
weights /= weights.sum()
|
|
||||||
return torch.Tensor(weights)
|
return torch.Tensor(weights)
|
||||||
|
|
||||||
|
|
||||||
|
@ -527,7 +526,7 @@ def plot_images(imgs, targets, fname='images.jpg'):
|
||||||
plt.close()
|
plt.close()
|
||||||
|
|
||||||
|
|
||||||
def plot_results(start=0, stop=0): # from utils.utils import *; plot_results()
|
def plot_results(start=1, stop=0): # from utils.utils import *; plot_results()
|
||||||
# Plot training results files 'results*.txt'
|
# Plot training results files 'results*.txt'
|
||||||
# import os; os.system('wget https://storage.googleapis.com/ultralytics/yolov3/results_v3.txt')
|
# import os; os.system('wget https://storage.googleapis.com/ultralytics/yolov3/results_v3.txt')
|
||||||
|
|
||||||
|
@ -542,6 +541,6 @@ def plot_results(start=0, stop=0): # from utils.utils import *; plot_results()
|
||||||
for i in range(10):
|
for i in range(10):
|
||||||
ax[i].plot(x, results[i, x], marker='.', label=f.replace('.txt', ''))
|
ax[i].plot(x, results[i, x], marker='.', label=f.replace('.txt', ''))
|
||||||
ax[i].set_title(s[i])
|
ax[i].set_title(s[i])
|
||||||
ax[0].legend()
|
|
||||||
fig.tight_layout()
|
fig.tight_layout()
|
||||||
|
ax[4].legend()
|
||||||
fig.savefig('results.png', dpi=300)
|
fig.savefig('results.png', dpi=300)
|
||||||
|
|
Loading…
Reference in New Issue