CNN_modle / README.md
gihakkk's picture
Update README.md
71e6fbc verified
---
license: unknown
---
์ถ”ํ›„ ViT๋ชจ๋ธ๋กœ ๊ต์ฒด๋  ์˜ˆ์ •์ž…๋‹ˆ๋‹ค.
# [https://huggingface.co/gihakkk/vit_modle](https://huggingface.co/gihakkk/vit_modle)
์œ„ ๋ชจ๋ธ๋กœ ๋Œ€์ฒด๋˜์—ˆ์Šต๋‹ˆ๋‹ค
์œ„ ๋ชจ๋ธ์ด ์„ฑ๋Šฅ ๋ฉด์—์„œ ํ›จ์‹  ์••๋„์  ์ž…๋‹ˆ๋‹ค.
๋”ฐ๋ผ์„œ, ๋”์ด์ƒ CNN๋ชจ๋ธ์€ ์‚ฌ์šฉํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.
ํ—ˆ๊น… ํŽ˜์ด์Šค์—์„œ ๋ฐ›์•„ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋„๋ก config ํŒŒ์ผ์„ ๋งŒ๋“ค์—ˆ์œผ๋ฉฐ, ์ž˜ ์ž‘๋™ํ•˜๋Š”๊ฒƒ์„ ํ™•์ธํ–ˆ์Šต๋‹ˆ๋‹ค.
๋กœ๋งจ์Šค ์Šค์บ ์—์„œ ์นด๋ฉ”๋ผ์— ์ฃผ๋กœ ๋น„์ถฐ์ง„ ์‚ฌ์ง„์„ ์กฐ์‚ฌํ•ด ์ง‘์–ด๋„ฃ์–ด ์œ ์‚ฌ๋„ ํŒ๋‹จ์— ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋„๋ก ๊ตฌ์„ฑํ–ˆ์Šต๋‹ˆ๋‹ค.
๋ชจ๋ธ ํ•™์Šต์— ํ™œ์šฉ๋œ ๋ฐ์ดํ„ฐ๋Š” ์ „๋ถ€ ์ง์ ‘ ๊ณต์ˆ˜ํ•œ ๊ฒƒ์ด๋ฉฐ, ๋กœ๋งจ์Šค์Šค์บ , ๋ชธ์บ  ํ”ผ์‹ฑ ํ”ผํ•ด๋ฅผ ์ž…์€ ์ง€์ธ์„ ํ†ตํ•ด ์–ป์€ ๋ฐ์ดํ„ฐ์™€, ๊ทธ ํŠน์ง•์„ ํ†ตํ•ด ์ถ”๊ฐ€๋กœ ๋งŒ๋“  ๋ฐ์ดํ„ฐ๋ฅผ ํ†ตํ•ด ๋งŒ๋“ค์—ˆ์Šต๋‹ˆ๋‹ค.
11์›” ์ดˆ์— ์—…๋กœ๋“œ ํ•  ์ƒˆ๋กœ์šด ๋ฒ„์ ผ์€ ๋ฐ์ดํ„ฐ๋ฅผ ์–ป๊ธฐ ์œ„ํ•ด ์ง์ ‘ ๋ชธ์บ  ํ”ผ์‹ฑ์„ ๋‹นํ•ด ์ƒˆ๋กœ์šด ๋ฐ์ดํ„ฐ๋ฅผ ์–ป๊ณ , ์ด๋ฅผ ๋ชจ๋ธํ•™์Šตํ•˜์—ฌ ์˜ฌ๋ฆด๊ฒƒ ์ž…๋‹ˆ๋‹ค.
๋‹ค์Œ๊ณผ ๊ฐ™์ด ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค
```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)
```