CNN_modle / README.md
gihakkk's picture
Update README.md
914790b verified
|
raw
history blame
2.04 kB
---
license: unknown
---
ํ—ˆ๊น… ํŽ˜์ด์Šค์—์„œ ๋ฐ›์•„ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋„๋ก config ํŒŒ์ผ์„ ๋งŒ๋“ค์—ˆ์œผ๋ฉฐ, ์ž˜ ์ž‘๋™ํ•˜๋Š”๊ฒƒ์„ ํ™•์ธํ–ˆ์Šต๋‹ˆ๋‹ค
๋กœ๋งจ์Šค ์Šค์บ ์—์„œ ์นด๋ฉ”๋ผ์— ์ฃผ๋กœ ๋น„์ถฐ์ง„ ์‚ฌ์ง„์„ ์กฐ์‚ฌํ•ด ์ง‘์–ด๋„ฃ์–ด ์œ ์‚ฌ๋„ ํŒ๋‹จ์— ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋„๋ก ๊ตฌ์„ฑํ–ˆ์Šต๋‹ˆ๋‹ค.
๋‹ค์Œ๊ณผ ๊ฐ™์ด ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค
```python
import tensorflow as tf
import numpy as np
from PIL import Image
import requests
# CNN ๋ชจ๋ธ ๋‹ค์šด๋กœ๋“œ ๋ฐ ๋กœ๋“œ
model_url = "https://huggingface.co/gihakkk/CNN_modle/resolve/main/cnn_similarity_model.keras"
model_path = "cnn_similarity_model.keras"
# ๋ชจ๋ธ ํŒŒ์ผ ๋‹ค์šด๋กœ๋“œ
response = requests.get(model_url)
with open(model_path, "wb") as f:
f.write(response.content)
# Keras ๋ชจ๋ธ ๋กœ๋“œ
cnn_model = tf.keras.models.load_model(model_path)
# ์ด๋ฏธ์ง€ ์ „์ฒ˜๋ฆฌ ํ•จ์ˆ˜
def preprocess_image(image_path):
try:
img = Image.open(image_path).convert('RGB')
img = img.resize((152, 152)) # ๋ชจ๋ธ์ด ์š”๊ตฌํ•˜๋Š” ํฌ๊ธฐ
img_array = np.array(img) / 255.0 # ์ด๋ฏธ์ง€๋ฅผ 0-1 ์‚ฌ์ด๋กœ ์ •๊ทœํ™”
img_array = np.expand_dims(img_array, axis=0) # ๋ฐฐ์น˜ ์ฐจ์› ์ถ”๊ฐ€
return img_array
except Exception as e:
print(f"Error processing image: {e}")
return None
# ์œ ์‚ฌ๋„ ์˜ˆ์ธก ํ•จ์ˆ˜
def predict_similarity(image_path):
img_array = preprocess_image(image_path)
if img_array is not None:
predictions = cnn_model.predict(img_array) # ๋ชจ๋ธ์„ ํ†ตํ•ด ์˜ˆ์ธก
similarity_score = np.mean(predictions) # ์œ ์‚ฌ๋„ ์ ์ˆ˜์˜ ํ‰๊ท  ๊ณ„์‚ฐ
if similarity_score > 0.5: # ์ž„๊ณ„๊ฐ’์„ ๊ธฐ์ค€์œผ๋กœ ์œ ์‚ฌ๋„ ํŒ๋‹จ
return "๋กœ๋งจ์Šค ์Šค์บ  ์ด๋ฏธ์ง€์ž…๋‹ˆ๋‹ค."
else:
return "๋กœ๋งจ์Šค ์Šค์บ  ์ด๋ฏธ์ง€๊ฐ€ ์•„๋‹™๋‹ˆ๋‹ค."
else:
return "์ด๋ฏธ์ง€ ์ „์ฒ˜๋ฆฌ์— ์‹คํŒจํ–ˆ์Šต๋‹ˆ๋‹ค."
# ํ…Œ์ŠคํŠธ ์ด๋ฏธ์ง€ ์˜ˆ์ธก
image_path = r'์‚ฌ์ง„ ์œ„์น˜ ์ž…๋ ฅ' # ํ…Œ์ŠคํŠธํ•  ์ด๋ฏธ์ง€ ๊ฒฝ๋กœ
result = predict_similarity(image_path)
print(result)
```