Add feature map visualization (#3804)

* Add feature map visualization

Add a feature_visualization function to visualize the mid feature map of the model.

* Update yolo.py

* remove boolean from forward and reorder if statement

* remove print from forward

* General cleanup

* Indent

* Update plots.py

Co-authored-by: Glenn Jocher <glenn.jocher@ultralytics.com>
This commit is contained in:
ZigarssandGlenn Jocher authored and GitHub committed 2021-06-28 13:18:45 +02:00
1 parent 3974d725b6
commit 20d45aa4f1
2 files changed
+33 -3

No files matched your search

+5 -1
View File
@@ -17,6 +17,7 @@ from models.common import *
from models.experimental import *
from utils.autoanchor import check_anchor_order
from utils.general import make_divisible, check_file, set_logging
from utils.plots import feature_visualization
from utils.torch_utils import time_synchronized, fuse_conv_and_bn, model_info, scale_img, initialize_weights, \
select_device, copy_attr
@@ -135,7 +136,7 @@ class Model(nn.Module):
y.append(yi)
return torch.cat(y, 1), None # augmented inference, train
def forward_once(self, x, profile=False):
def forward_once(self, x, profile=False, feature_vis=False):
y, dt = [], [] # outputs
for m in self.model:
if m.f != -1: # if not from previous layer
@@ -153,6 +154,9 @@ class Model(nn.Module):
x = m(x) # run
y.append(x if m.i in self.save else None) # save output
if feature_vis and m.type == 'models.common.SPP':
feature_visualization(x, m.type, m.i)
if profile:
logger.info('%.1fms total' % sum(dt))