From e8a15ac1d7a10cc8096383291d2fd27331a8903d Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Sat, 10 Aug 2019 22:11:55 +0200 Subject: [PATCH] updates --- models.py | 13 +++++++++++-- utils/utils.py | 31 +++++++++++-------------------- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/models.py b/models.py index 1e952420..a453993e 100755 --- a/models.py +++ b/models.py @@ -32,9 +32,10 @@ def create_modules(module_defs): bias=not bn)) if bn: modules.add_module('BatchNorm2d', nn.BatchNorm2d(filters, momentum=0.1)) - if mdef['activation'] == 'leaky': - # modules.add_module('activation', nn.PReLU(num_parameters=filters, init=0.1)) + if mdef['activation'] == 'leaky': # TODO: activation study https://github.com/ultralytics/yolov3/issues/441 modules.add_module('activation', nn.LeakyReLU(0.1, inplace=True)) + # modules.add_module('activation', nn.PReLU(num_parameters=1)) + # modules.add_module('activation', Swish()) elif mdef['type'] == 'maxpool': kernel_size = int(mdef['size']) @@ -82,6 +83,14 @@ def create_modules(module_defs): return hyperparams, module_list +class Swish(nn.Module): + def __init__(self): + super(Swish, self).__init__() + + def forward(self, x): + return x * torch.sigmoid(x) + + class YOLOLayer(nn.Module): def __init__(self, anchors, nc, img_size, yolo_index): super(YOLOLayer, self).__init__() diff --git a/utils/utils.py b/utils/utils.py index 1af93d49..dc2353dd 100755 --- a/utils/utils.py +++ b/utils/utils.py @@ -766,8 +766,14 @@ def plot_results(start=0, stop=0): # from utils.utils import *; plot_results() n = results.shape[1] # number of rows x = range(start, min(stop, n) if stop else n) for i in range(10): - ax[i].plot(x, results[i, x], marker='.', label=f.replace('.txt', '')) + y = results[i, x] + if i in [0, 1, 2, 5, 6, 7]: + y[y == 0] = np.nan # dont show zero loss values + ax[i].plot(x, y, marker='.', label=f.replace('.txt', '')) ax[i].set_title(s[i]) + if i in [5, 6, 7]: # share train and val loss y axes + ax[i].get_shared_y_axes().join(ax[i], ax[i - 5]) + fig.tight_layout() ax[4].legend() fig.savefig('results.png', dpi=200) @@ -785,7 +791,10 @@ def plot_results_overlay(start=1, stop=0): # from utils.utils import *; plot_re ax = ax.ravel() for i in range(5): for j in [i, i + 5]: - ax[i].plot(x, results[j, x], marker='.', label=s[j]) + y = results[j, x] + if i in [0, 1, 2]: + y[y == 0] = np.nan # dont show zero loss values + ax[i].plot(x, y, marker='.', label=s[j]) ax[i].set_title(t[i]) ax[i].legend() ax[i].set_ylabel(f) if i == 0 else None # add filename @@ -793,24 +802,6 @@ def plot_results_overlay(start=1, stop=0): # from utils.utils import *; plot_re fig.savefig(f.replace('.txt', '.png'), dpi=200) -def plot_results_orig(start=0, stop=0): # from utils.utils import *; plot_results_orig() - # Plot training results files 'results*.txt' in original format - fig, ax = plt.subplots(2, 5, figsize=(14, 7)) - ax = ax.ravel() - s = ['GIoU/XY', 'Width/Height', 'Confidence', 'Classification', 'Train Loss', 'Precision', 'Recall', 'mAP', 'F1', - 'Test Loss'] - for f in sorted(glob.glob('results*.txt') + glob.glob('../../Google Drive/results*.txt')): - results = np.loadtxt(f, usecols=[2, 3, 4, 5, 6, 9, 10, 11, 12, 13]).T - n = results.shape[1] # number of rows - x = range(start, min(stop, n) if stop else n) - for i in range(10): - ax[i].plot(x, results[i, x], marker='.', label=f.replace('.txt', '')) - ax[i].set_title(s[i]) - fig.tight_layout() - ax[4].legend() - fig.savefig('results.png', dpi=200) - - def version_to_tuple(version): # Used to compare versions of library return tuple(map(int, (version.split("."))))