Update README.md
Browse files
README.md
CHANGED
@@ -1,3 +1,38 @@
|
|
1 |
-
---
|
2 |
-
license: unknown
|
3 |
-
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
license: unknown
|
3 |
+
---
|
4 |
+
|
5 |
+
๋ก๋งจ์ค ์ค์บ ์ฌ์ง๊ณผ, ๊ทธ๋ฅ ์ฌ์ง์ ๊ตฌ๋ณํ ์ ์๋ ViT ๋ชจ๋ธ ์
๋๋ค.
|
6 |
+
๊ธฐ์กด์ CNN ๋ชจ๋ธ์ ๋นํด ํจ์ ์ฑ๋ฅ์ด ์ข์ต๋๋ค.
|
7 |
+
์ฌ์ฉ ์ฝ๋๋ ๋ค์๊ณผ ๊ฐ์ต๋๋ค.
|
8 |
+
|
9 |
+
```python
|
10 |
+
import torch
|
11 |
+
from transformers import ViTForImageClassification, ViTFeatureExtractor
|
12 |
+
from PIL import Image
|
13 |
+
|
14 |
+
# Hugging Face์์ ๋ชจ๋ธ ๋ฐ ํน์ง ์ถ์ถ๊ธฐ ๋ถ๋ฌ์ค๊ธฐ
|
15 |
+
model = ViTForImageClassification.from_pretrained("gihakkk/vit_modle")
|
16 |
+
feature_extractor = ViTFeatureExtractor.from_pretrained("gihakkk/vit_modle")
|
17 |
+
|
18 |
+
# ์๋ก์ด ์ด๋ฏธ์ง ์์ธก ํจ์ ์ ์
|
19 |
+
def predict_image(image_path):
|
20 |
+
# ์ด๋ฏธ์ง๋ฅผ ๋ก๋ํ๊ณ RGB๋ก ๋ณํ
|
21 |
+
image = Image.open(image_path).convert("RGB")
|
22 |
+
|
23 |
+
# ์ด๋ฏธ์ง๋ฅผ ํน์ง ์ถ์ถ๊ธฐ๋ก ์ ์ฒ๋ฆฌํ์ฌ ๋ชจ๋ธ ์
๋ ฅ ํ์์ผ๋ก ๋ณํ
|
24 |
+
inputs = feature_extractor(images=image, return_tensors="pt")
|
25 |
+
|
26 |
+
# ์์ธก ์ํ
|
27 |
+
with torch.no_grad():
|
28 |
+
outputs = model(**inputs).logits
|
29 |
+
predicted_class = torch.argmax(outputs, dim=-1).item()
|
30 |
+
|
31 |
+
return "๊ทธ๋ฅ ์ฌ์ง" if predicted_class == 1 else "๋ก๋งจ์ค ์ค์บ ์ฌ์ง"
|
32 |
+
|
33 |
+
# ์์ธก ์์
|
34 |
+
image_path = r'path\to\your\img.jpg'
|
35 |
+
result = predict_image(image_path)
|
36 |
+
print(result)
|
37 |
+
|
38 |
+
```
|