MCPcopy Index your code
hub / github.com/AgentMaker/PaddleQuickInference / preprocess

Function preprocess

examples/MiDaS/processor.py:11–40  ·  view source on GitHub ↗
(img_path, size)

Source from the content-addressed store, hash-verified

9
10# 数据预处理函数
11def preprocess(img_path, size):
12 # 图像变换
13 transform = Compose([
14 Resize(
15 size,
16 size,
17 resize_target=None,
18 keep_aspect_ratio=False,
19 ensure_multiple_of=32,
20 resize_method="upper_bound",
21 image_interpolation_method=cv2.INTER_CUBIC,
22 ),
23 NormalizeImage(mean=[0.485, 0.456, 0.406],
24 std=[0.229, 0.224, 0.225]),
25 PrepareForNet()
26 ])
27
28 # 读取图片
29 img = cv2.imread(img_path)
30
31 # 归一化
32 img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB) / 255.0
33
34 # 图像变换
35 img = transform({"image": img})["image"]
36
37 # 新增维度
38 img = img[np.newaxis, ...]
39
40 return img
41
42# 数据后处理函数
43def postprocess(results, output_dir, img_path, model_name):

Callers 1

main.pyFile · 0.90

Calls 3

ResizeClass · 0.90
NormalizeImageClass · 0.90
PrepareForNetClass · 0.90

Tested by

no test coverage detected