Upload 4 files
Browse files
similarity_model_0.6.onnx
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:c6da469b468a640af58f3f5c4c3e2c7a84063ade75aeb36a8186e1e59ee91d00
|
| 3 |
+
size 82433310
|
similarity_model_0.6.pth
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:49a0cfa74e3706800013658d1ec64f56427625000d0a5b7354bd3fd890c33453
|
| 3 |
+
size 82951851
|
similarity_model_0.6_inference_example.py
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""
|
| 3 |
+
ONNX ๋ชจ๋ธ์ ์ฌ์ฉํ ์ด๋ฏธ์ง ์ ์ฌ๋ ์ถ๋ก ์์
|
| 4 |
+
"""
|
| 5 |
+
|
| 6 |
+
import onnxruntime as ort
|
| 7 |
+
import numpy as np
|
| 8 |
+
from PIL import Image
|
| 9 |
+
import torchvision.transforms as transforms
|
| 10 |
+
|
| 11 |
+
# ์ ์ฒ๋ฆฌ ํ์ดํ๋ผ์ธ
|
| 12 |
+
transform = transforms.Compose([
|
| 13 |
+
transforms.Resize((224, 224)),
|
| 14 |
+
transforms.CenterCrop(224),
|
| 15 |
+
transforms.ToTensor(),
|
| 16 |
+
transforms.Normalize(mean=[0.485, 0.456, 0.406],
|
| 17 |
+
std=[0.229, 0.224, 0.225])
|
| 18 |
+
])
|
| 19 |
+
|
| 20 |
+
def preprocess_image(image_path):
|
| 21 |
+
"""์ด๋ฏธ์ง ์ ์ฒ๋ฆฌ"""
|
| 22 |
+
image = Image.open(image_path).convert('RGB')
|
| 23 |
+
tensor = transform(image)
|
| 24 |
+
return tensor.unsqueeze(0).numpy() # ๋ฐฐ์น ์ฐจ์ ์ถ๊ฐ
|
| 25 |
+
|
| 26 |
+
def predict_similarity(onnx_model_path, image1_path, image2_path):
|
| 27 |
+
"""์ด๋ฏธ์ง ์ ์ ์ฌ๋ ์์ธก"""
|
| 28 |
+
|
| 29 |
+
# ONNX ์ธ์
์์ฑ
|
| 30 |
+
session = ort.InferenceSession(onnx_model_path)
|
| 31 |
+
|
| 32 |
+
# ์ด๋ฏธ์ง ์ ์ฒ๋ฆฌ
|
| 33 |
+
img1 = preprocess_image(image1_path)
|
| 34 |
+
img2 = preprocess_image(image2_path)
|
| 35 |
+
|
| 36 |
+
# ์ถ๋ก ์คํ
|
| 37 |
+
inputs = {'image1': img1, 'image2': img2}
|
| 38 |
+
logits = session.run(None, inputs)[0]
|
| 39 |
+
|
| 40 |
+
# ์๊ทธ๋ชจ์ด๋๋ก ํ๋ฅ ๋ณํ
|
| 41 |
+
similarity = 1 / (1 + np.exp(-logits[0][0]))
|
| 42 |
+
|
| 43 |
+
return similarity
|
| 44 |
+
|
| 45 |
+
# ์ฌ์ฉ ์์
|
| 46 |
+
if __name__ == "__main__":
|
| 47 |
+
onnx_path = "room_image_comparator.onnx"
|
| 48 |
+
img1_path = "room1.jpg"
|
| 49 |
+
img2_path = "room2.jpg"
|
| 50 |
+
|
| 51 |
+
similarity = predict_similarity(onnx_path, img1_path, img2_path)
|
| 52 |
+
print(f"์ ์ฌ๋: {similarity:.4f}")
|
similarity_model_0.6_model_info.json
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"image_size": [
|
| 3 |
+
224,
|
| 4 |
+
224
|
| 5 |
+
],
|
| 6 |
+
"channels": 3,
|
| 7 |
+
"pixel_range": [
|
| 8 |
+
0.0,
|
| 9 |
+
1.0
|
| 10 |
+
],
|
| 11 |
+
"normalization": {
|
| 12 |
+
"mean": [
|
| 13 |
+
0.485,
|
| 14 |
+
0.456,
|
| 15 |
+
0.406
|
| 16 |
+
],
|
| 17 |
+
"std": [
|
| 18 |
+
0.229,
|
| 19 |
+
0.224,
|
| 20 |
+
0.225
|
| 21 |
+
],
|
| 22 |
+
"description": "ImageNet normalization for EfficientNet"
|
| 23 |
+
},
|
| 24 |
+
"input_format": "RGB",
|
| 25 |
+
"resize_method": "bilinear",
|
| 26 |
+
"center_crop": true,
|
| 27 |
+
"batch_dimension": 0,
|
| 28 |
+
"tensor_layout": "NCHW"
|
| 29 |
+
}
|