Update README.md
Browse files
README.md
CHANGED
|
@@ -6,13 +6,46 @@ license: unknown
|
|
| 6 |
๋ก๋งจ์ค ์ค์บ ์์ ์นด๋ฉ๋ผ์ ์ฃผ๋ก ๋น์ถฐ์ง ์ฌ์ง์ ์กฐ์ฌํด ์ง์ด๋ฃ์ด ์ ์ฌ๋ ํ๋จ์ ์ฌ์ฉํ ์ ์๋๋ก ๊ตฌ์ฑํ์ต๋๋ค.
|
| 7 |
๋ค์๊ณผ ๊ฐ์ด ์ฌ์ฉํ ์ ์์ต๋๋ค
|
| 8 |
```python
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
try:
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
```
|
|
|
|
| 6 |
๋ก๋งจ์ค ์ค์บ ์์ ์นด๋ฉ๋ผ์ ์ฃผ๋ก ๋น์ถฐ์ง ์ฌ์ง์ ์กฐ์ฌํด ์ง์ด๋ฃ์ด ์ ์ฌ๋ ํ๋จ์ ์ฌ์ฉํ ์ ์๋๋ก ๊ตฌ์ฑํ์ต๋๋ค.
|
| 7 |
๋ค์๊ณผ ๊ฐ์ด ์ฌ์ฉํ ์ ์์ต๋๋ค
|
| 8 |
```python
|
| 9 |
+
import tensorflow as tf
|
| 10 |
+
import numpy as np
|
| 11 |
+
from PIL import Image
|
| 12 |
+
import requests
|
| 13 |
+
|
| 14 |
+
# CNN ๋ชจ๋ธ ๋ค์ด๋ก๋ ๋ฐ ๋ก๋
|
| 15 |
+
model_url = "https://huggingface.co/gihakkk/CNN_modle/resolve/main/cnn_similarity_model.keras"
|
| 16 |
+
model_path = "cnn_similarity_model.keras"
|
| 17 |
+
|
| 18 |
+
# ๋ชจ๋ธ ํ์ผ ๋ค์ด๋ก๋
|
| 19 |
+
response = requests.get(model_url)
|
| 20 |
+
with open(model_path, "wb") as f:
|
| 21 |
+
f.write(response.content)
|
| 22 |
+
|
| 23 |
+
# Keras ๋ชจ๋ธ ๋ก๋
|
| 24 |
+
cnn_model = tf.keras.models.load_model(model_path)
|
| 25 |
+
|
| 26 |
+
# ์ด๋ฏธ์ง ์ ์ฒ๋ฆฌ ํจ์
|
| 27 |
+
def preprocess_image(image_path):
|
| 28 |
try:
|
| 29 |
+
img = Image.open(image_path).convert('RGB')
|
| 30 |
+
img = img.resize((224, 224)) # ๋ชจ๋ธ์ด ์๊ตฌํ๋ ํฌ๊ธฐ
|
| 31 |
+
img_array = np.array(img) / 255.0
|
| 32 |
+
img_array = np.expand_dims(img_array, axis=0)
|
| 33 |
+
return img_array
|
| 34 |
+
except Exception as e:
|
| 35 |
+
print(f"Error processing image: {e}")
|
| 36 |
+
|
| 37 |
+
# ์ด๋ฏธ์ง ์์ธก ํจ์
|
| 38 |
+
def predict_image(image_path):
|
| 39 |
+
img_array = preprocess_image(image_path)
|
| 40 |
+
if img_array is not None:
|
| 41 |
+
predictions = cnn_model.predict(img_array)
|
| 42 |
+
return predictions
|
| 43 |
+
else:
|
| 44 |
+
return "Image preprocessing failed."
|
| 45 |
+
|
| 46 |
+
# ํ
์คํธ ์ด๋ฏธ์ง ์์ธก
|
| 47 |
+
image_path = r'์ด๋ฏธ์ง ์
๋ ฅ ๊ฒฝ๋ก' #์ํ๋ ์ด๋ฏธ์ง ์์น
|
| 48 |
+
prediction_result = predict_image(image_path)
|
| 49 |
+
print("Prediction:", prediction_result)
|
| 50 |
+
|
| 51 |
```
|