Download example.py from Hyunil/CSATv2: direct link, hf CLI and curl.
- Browser
- Download file 732 Bytes
-
https://huggingface.co/Hyunil/CSATv2/resolve/main/example.py
- Command line
-
hf download hf://Hyunil/CSATv2/example.py
-
curl -L -o example.py https://huggingface.co/Hyunil/CSATv2/resolve/main/example.py
732 Bytes
| import torch | |
| from datasets import load_dataset | |
| from transformers import AutoImageProcessor, AutoModelForImageClassification | |
| # 예시 데이터: 고양이 이미지 | |
| dataset = load_dataset("huggingface/cats-image") | |
| image = dataset["test"]["image"][0] | |
| # 👉 CSATv2 모델로 교체 | |
| model_name = "Hyunil/CSATv2" | |
| # Preprocessor + Model 로드 | |
| processor = AutoImageProcessor.from_pretrained(model_name, trust_remote_code=True) | |
| model = AutoModelForImageClassification.from_pretrained(model_name, trust_remote_code=True) | |
| # 전처리 | |
| inputs = processor(image, return_tensors="pt") | |
| # 추론 | |
| with torch.no_grad(): | |
| logits = model(**inputs).logits | |
| pred = logits.argmax(-1).item() | |
| print("Predicted label:", model.config.id2label[pred]) |