MCPcopy Create free account
hub / github.com/JDAI-CV/DNNLibrary / worker

Function worker

quant.py:215–233  ·  view source on GitHub ↗
(paths)

Source from the content-addressed store, hash-verified

213 q = Queue()
214
215 def worker(paths):
216 def read_img(path, norm=True):
217 import cv2
218 a = cv2.imread(path)
219 a = cv2.resize(a, (224, 224))
220 a = a.astype(np.float32)
221 a = cv2.cvtColor(a, cv2.COLOR_BGR2RGB)
222 if norm:
223 a /= 255
224 # mean and std for RGB images
225 a -= [0.485, 0.456, 0.406]
226 a /= [0.229, 0.224, 0.225]
227 a = np.moveaxis(a, -1, 0)
228 return a
229
230 for i in range(0, len(paths), batch_size):
231 xs = np.stack(list(map(lambda x: read_img(x, True), paths[i:i + batch_size])))
232 q.put(xs)
233 q.put(None)
234
235 image_exts = ['JPEG', 'jpg', 'jpeg', 'png']
236 filenames = list(itertools.chain(*[glob.glob(os.path.join(image_dir, '**/*.' + ext), recursive=True)

Callers

nothing calls this directly

Calls 1

read_imgFunction · 0.85

Tested by

no test coverage detected