Fix for python models/yolo.py --profile (#4541)
Profiling fix copies input to Detect layer to circumvent inplace changes to the feature maps.
This commit is contained in:
1 parent
79af1144c2
commit
2da6444c92
1 file changed
+3
-3
+3
-3
@@ -48,7 +48,6 @@ class Detect(nn.Module):
|
|||||||
self.inplace = inplace # use in-place ops (e.g. slice assignment)
|
self.inplace = inplace # use in-place ops (e.g. slice assignment)
|
||||||
|
|
||||||
def forward(self, x):
|
def forward(self, x):
|
||||||
# x = x.copy() # for profiling
|
|
||||||
z = [] # inference output
|
z = [] # inference output
|
||||||
for i in range(self.nl):
|
for i in range(self.nl):
|
||||||
x[i] = self.m[i](x[i]) # conv
|
x[i] = self.m[i](x[i]) # conv
|
||||||
@@ -143,10 +142,11 @@ class Model(nn.Module):
|
|||||||
x = y[m.f] if isinstance(m.f, int) else [x if j == -1 else y[j] for j in m.f] # from earlier layers
|
x = y[m.f] if isinstance(m.f, int) else [x if j == -1 else y[j] for j in m.f] # from earlier layers
|
||||||
|
|
||||||
if profile:
|
if profile:
|
||||||
o = thop.profile(m, inputs=(x,), verbose=False)[0] / 1E9 * 2 if thop else 0 # FLOPs
|
c = isinstance(m, Detect) # copy input as inplace fix
|
||||||
|
o = thop.profile(m, inputs=(x.copy() if c else x,), verbose=False)[0] / 1E9 * 2 if thop else 0 # FLOPs
|
||||||
t = time_sync()
|
t = time_sync()
|
||||||
for _ in range(10):
|
for _ in range(10):
|
||||||
_ = m(x)
|
m(x.copy() if c else x)
|
||||||
dt.append((time_sync() - t) * 100)
|
dt.append((time_sync() - t) * 100)
|
||||||
if m == self.model[0]:
|
if m == self.model[0]:
|
||||||
LOGGER.info(f"{'time (ms)':>10s} {'GFLOPs':>10s} {'params':>10s} {'module'}")
|
LOGGER.info(f"{'time (ms)':>10s} {'GFLOPs':>10s} {'params':>10s} {'module'}")
|
||||||
|
|||||||
Reference in new issue
Block a user