gihakkk commited on
Commit
f126235
โ€ข
1 Parent(s): 3d6c251

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +38 -3
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
+ ```