YOLOv5 AWS Inferentia Inplace compatibility updates (#2953)

* Added flag to enable/disable all inplace and assignment operations

* Removed shape print statements

* Scope Detect/Model import to avoid circular dependency

* PEP8

* create _descale_pred()

* replace lost space

* replace list with tuple

Co-authored-by: Glenn Jocher <glenn.jocher@ultralytics.com>
This commit is contained in:
jluntamazonandGlenn Jocher authored and GitHub committed 2021-04-30 12:54:48 +02:00
1 parent 955eea8b96
commit 41f5cc5637
2 files changed
+47 -21

No files matched your search

+5 -3
View File
@@ -110,7 +110,9 @@ class Ensemble(nn.ModuleList):
return y, None # inference, train output
def attempt_load(weights, map_location=None):
def attempt_load(weights, map_location=None, inplace=True):
from models.yolo import Detect, Model
# 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]:
@@ -120,8 +122,8 @@ def attempt_load(weights, map_location=None):
# Compatibility updates
for m in model.modules():
if type(m) in [nn.Hardswish, nn.LeakyReLU, nn.ReLU, nn.ReLU6, nn.SiLU]:
m.inplace = True # pytorch 1.7.0 compatibility
if type(m) in [nn.Hardswish, nn.LeakyReLU, nn.ReLU, nn.ReLU6, nn.SiLU, Detect, Model]:
m.inplace = inplace # pytorch 1.7.0 compatibility
elif type(m) is Conv:
m._non_persistent_buffers_set = set() # pytorch 1.6.0 compatibility