Update README.md
Browse files21 unmodified lines2223242526272829303132333435363738394041424344454621 unmodified lines## 🖼️ Quick Usage```pythonfrom transformers import AutoFeatureExtractor, AutoModelForImageClassificationfrom PIL import Imageimport torch# Load model & feature extractorextractor = AutoFeatureExtractor.from_pretrained("your-username/RistoNet")model = AutoModelForImageClassification.from_pretrained("your-username/RistoNet")# Load an imageimage = Image.open("my_dish.jpg")# Preprocessinputs = extractor(images=image, return_tensors="pt")# Predictwith torch.no_grad():outputs = model(**inputs)predictions = torch.nn.functional.softmax(outputs.logits, dim=-1)# Top classpredicted_class = predictions.argmax().item()print(f"Predicted class: {predicted_class}")21 unmodified lines222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707121 unmodified lines## 🖼️ Quick Usage```python## 🔎 Inference Example```pythonimport torchfrom PIL import Imagefrom torchvision import models, transformsfrom huggingface_hub import hf_hub_download# ------------------------------# 1. Load model# ------------------------------MODEL_REPO = "Orkidee/RistoNet"MODEL_FILE = "ristonet.pth"model = models.efficientnet_b0(weights=None) # no pretrained weightsnum_features = model.classifier[1].in_featuresmodel.classifier[1] = torch.nn.Linear(num_features, 2) # 2 classes# Download weights from Hub and loadmodel_path = hf_hub_download(repo_id=MODEL_REPO, filename=MODEL_FILE)model.load_state_dict(torch.load(model_path, map_location="cpu"))model.eval()# ------------------------------# 2. Define preprocessing# ------------------------------transform = transforms.Compose([transforms.Resize((224, 224)),transforms.ToTensor(),transforms.Normalize(mean=[0.485, 0.456, 0.406],std=[0.229, 0.224, 0.225])])# ------------------------------# 3. Run inference on an image# ------------------------------image = Image.open("my_food.jpg").convert("RGB")input_tensor = transform(image).unsqueeze(0) # add batch dimwith torch.no_grad():outputs = model(input_tensor)probs = torch.nn.functional.softmax(outputs, dim=1)predicted_class = probs.argmax().item()print("Predicted class:", predicted_class)print("Probabilities:", probs.numpy())
README.md+40-15