Initial model ensemble capability #318

This commit is contained in:
Glenn Jocher committed 2020-07-07 15:40:50 -07:00
1 parent 121d90b3f2
commit e8cf24b6c8
4 files changed
+33 -20

No files matched your search

+17
View File
@@ -1,6 +1,7 @@
# This file contains experimental modules
from models.common import *
from utils import google_utils
class CrossConv(nn.Module):
@@ -119,3 +120,19 @@ class Ensemble(nn.ModuleList):
for module in self:
y.append(module(x, augment)[0])
return torch.cat(y, 1), None # ensembled inference output, train output
def attempt_load(weights, map_location=None):
# Loads an ensemble of models weights=[a,b,c] or a single model weights=[a] or weights=a
model = Ensemble()
for w in weights if isinstance(weights, list) else [weights]:
google_utils.attempt_download(w)
model.append(torch.load(w, map_location=map_location)['model'].float().fuse().eval()) # load FP32 model
if len(model) == 1:
return model[-1] # return model
else:
print('Ensemble created with %s\n' % weights)
for k in ['names', 'stride']:
setattr(model, k, getattr(model[-1], k))
return model # return ensemble