Upload 8 files
Browse files- .gitattributes +1 -0
- ax650/realesrgan-x4-256.axmodel +3 -0
- ax650/realesrgan-x4.axmodel +3 -0
- config.json +0 -0
- main.py +93 -0
- onnx/realesrgan-x4-256.onnx +3 -0
- onnx/realesrgan-x4.onnx +3 -0
- out_test-256.jpg +3 -0
- test_256.jpeg +0 -0
.gitattributes
CHANGED
@@ -34,3 +34,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
*.axmodel filter=lfs diff=lfs merge=lfs -text
|
36 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
*.axmodel filter=lfs diff=lfs merge=lfs -text
|
36 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
37 |
+
out_test-256.jpg filter=lfs diff=lfs merge=lfs -text
|
ax650/realesrgan-x4-256.axmodel
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:c14f22de6970fa4dc5a6bb70a6286f856070d4a5cdd8eaf444ea174222fc17fb
|
3 |
+
size 22633271
|
ax650/realesrgan-x4.axmodel
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:42d96844928ecc7269e2842dcc95935f9e539d8fc0207accd96f0777f87f7acc
|
3 |
+
size 19253211
|
config.json
ADDED
File without changes
|
main.py
ADDED
@@ -0,0 +1,93 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import cv2
|
2 |
+
import numpy as np
|
3 |
+
import axengine as ort
|
4 |
+
import time
|
5 |
+
import argparse
|
6 |
+
|
7 |
+
def get_model(model_path: str) -> ort.InferenceSession:
|
8 |
+
model = ort.InferenceSession(model_path)
|
9 |
+
|
10 |
+
for input in model.get_inputs():
|
11 |
+
print(input.name, input.shape, input.dtype)
|
12 |
+
|
13 |
+
for output in model.get_outputs():
|
14 |
+
print(output.name, output.shape, output.dtype)
|
15 |
+
width = model.get_inputs()[0].shape[2]
|
16 |
+
height = model.get_inputs()[0].shape[1]
|
17 |
+
|
18 |
+
return model, width, height
|
19 |
+
|
20 |
+
|
21 |
+
def preprocess_image(image, width=64, height=64):
|
22 |
+
# 获取原始图像的高度和宽度
|
23 |
+
h, w = image.shape[:2]
|
24 |
+
|
25 |
+
# 计算调整大小的比例
|
26 |
+
scale_ratio = min(width / w, height / h)
|
27 |
+
|
28 |
+
# 根据比例计算新的高度和宽度,同时保持原图宽高比
|
29 |
+
new_w = int(w * scale_ratio)
|
30 |
+
new_h = int(h * scale_ratio)
|
31 |
+
|
32 |
+
# 调整图像大小,保持原图宽高比
|
33 |
+
resized_img = cv2.resize(image, (new_w, new_h))
|
34 |
+
|
35 |
+
# 创建一个具有目标尺寸的空白图像(黑色背景)
|
36 |
+
letterboxed_img = np.full((height, width, 3), (0, 0, 0), dtype=np.uint8)
|
37 |
+
|
38 |
+
# 计算将调整大小后的图像放置在letterbox中的起始点
|
39 |
+
top = (height - new_h) // 2
|
40 |
+
left = (width - new_w) // 2
|
41 |
+
|
42 |
+
# 将调整大小后的图像放入letterboxed图像中
|
43 |
+
letterboxed_img[top:top + new_h, left:left + new_w] = resized_img
|
44 |
+
|
45 |
+
# 添加批次维度
|
46 |
+
data = np.expand_dims(letterboxed_img, axis=0)
|
47 |
+
|
48 |
+
return data
|
49 |
+
|
50 |
+
|
51 |
+
'''
|
52 |
+
def preprocess_image(image, width=64, height=64):
|
53 |
+
data = cv2.resize(image, (width, height))
|
54 |
+
data = np.expand_dims(data, axis=0)
|
55 |
+
return data
|
56 |
+
'''
|
57 |
+
|
58 |
+
if __name__ == "__main__":
|
59 |
+
parser = argparse.ArgumentParser(description="Process an image with a given model.")
|
60 |
+
parser.add_argument('--input', type=str, required=True, help='Path to the input image.')
|
61 |
+
parser.add_argument('--output', type=str, required=True, help='Path to save the output image.')
|
62 |
+
parser.add_argument('--model', type=str, required=True, help='Path to the model file (.axmodel).')
|
63 |
+
|
64 |
+
args = parser.parse_args()
|
65 |
+
|
66 |
+
model, width, height = get_model(args.model)
|
67 |
+
|
68 |
+
img = cv2.imread(args.input)
|
69 |
+
|
70 |
+
print("Original Image Shape:", img.shape)
|
71 |
+
img = preprocess_image(img, width, height)
|
72 |
+
print("Preprocessed Image Shape:", img.shape)
|
73 |
+
|
74 |
+
# 开始计时
|
75 |
+
start_time = time.time()
|
76 |
+
|
77 |
+
# 执行推理
|
78 |
+
output = model.run(None, {"input.1": img})[0]
|
79 |
+
|
80 |
+
# 结束计时并计算耗时(毫秒)
|
81 |
+
end_time = time.time()
|
82 |
+
elapsed_ms = (end_time - start_time) * 1000 # 秒转毫秒
|
83 |
+
print(f"Inference Time: {elapsed_ms:.2f} ms")
|
84 |
+
|
85 |
+
print("Output Shape:", output.shape)
|
86 |
+
|
87 |
+
output[output>1] = 1
|
88 |
+
output[output<0] = 0
|
89 |
+
output_img = (output * 255).astype(np.uint8)[0]
|
90 |
+
|
91 |
+
print("Final Output Image Shape:", output_img.shape)
|
92 |
+
cv2.imwrite(args.output, output_img)
|
93 |
+
|
onnx/realesrgan-x4-256.onnx
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:279da2949cfc4f4f87ca90df784e443e304ed82b8cbc27b40b995c745cbd3d5c
|
3 |
+
size 66993533
|
onnx/realesrgan-x4.onnx
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:10a7a075719220ee6627124473ce57c74b7ef336b57bed4508d9353eaa8f17ef
|
3 |
+
size 66991363
|
out_test-256.jpg
ADDED
![]() |
Git LFS Details
|
test_256.jpeg
ADDED
![]() |