Skip to content

Commit

Permalink
Set auto=False for int8 calibration
Browse files Browse the repository at this point in the history
  • Loading branch information
zldrobit committed Oct 12, 2020
1 parent e6f309c commit 23fe35e
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions utils/datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def __iter__(self):


class LoadImages: # for inference
def __init__(self, path, img_size=640):
def __init__(self, path, img_size=640, auto=True):
p = str(Path(path)) # os-agnostic
p = os.path.abspath(p) # absolute path
if '*' in p:
Expand All @@ -128,6 +128,7 @@ def __init__(self, path, img_size=640):
self.nf = ni + nv # number of files
self.video_flag = [False] * ni + [True] * nv
self.mode = 'images'
self.auto = auto
if any(videos):
self.new_video(videos[0]) # new video
else:
Expand Down Expand Up @@ -169,7 +170,7 @@ def __next__(self):
print('image %g/%g %s: ' % (self.count, self.nf, path), end='')

# Padded resize
img = letterbox(img0, new_shape=self.img_size)[0]
img = letterbox(img0, new_shape=self.img_size, auto=self.auto)[0]

# Convert
img = img[:, :, ::-1].transpose(2, 0, 1) # BGR to RGB, to 3x416x416
Expand Down Expand Up @@ -253,7 +254,7 @@ def __len__(self):


class LoadStreams: # multiple IP or RTSP cameras
def __init__(self, sources='streams.txt', img_size=640):
def __init__(self, sources='streams.txt', img_size=640, auto=True):
self.mode = 'images'
self.img_size = img_size

Expand All @@ -266,6 +267,7 @@ def __init__(self, sources='streams.txt', img_size=640):
n = len(sources)
self.imgs = [None] * n
self.sources = sources
self.auto = auto
for i, s in enumerate(sources):
# Start the thread to read frames from the video stream
print('%g/%g: %s... ' % (i + 1, n, s), end='')
Expand All @@ -281,7 +283,7 @@ def __init__(self, sources='streams.txt', img_size=640):
print('') # newline

# check for common shapes
s = np.stack([letterbox(x, new_shape=self.img_size)[0].shape for x in self.imgs], 0) # inference shapes
s = np.stack([letterbox(x, new_shape=self.img_size, auto=self.auto)[0].shape for x in self.imgs], 0) # inference shapes
self.rect = np.unique(s, axis=0).shape[0] == 1 # rect inference if all shapes equal
if not self.rect:
print('WARNING: Different stream shapes detected. For optimal performance supply similarly-shaped streams.')
Expand Down Expand Up @@ -310,7 +312,7 @@ def __next__(self):
raise StopIteration

# Letterbox
img = [letterbox(x, new_shape=self.img_size, auto=self.rect)[0] for x in img0]
img = [letterbox(x, new_shape=self.img_size, auto=self.rect and self.auto)[0] for x in img0]

# Stack
img = np.stack(img, 0)
Expand Down

0 comments on commit 23fe35e

Please sign in to comment.