sakshamkr1 commited on
Commit
203d916
·
verified ·
1 Parent(s): 7dffa2c

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +28 -12
README.md CHANGED
@@ -46,23 +46,39 @@ from transformers import AutoModel
46
  # Load model
47
  model = AutoModel.from_pretrained("your-huggingface-username/model-name")
48
  model.eval()
 
49
 
50
- # Define image preprocessing
 
51
  transform = transforms.Compose([
52
- transforms.Resize((224, 224)),
53
- transforms.ToTensor(),
54
- transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]),
55
  ])
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
56
 
57
- # Load and preprocess image
58
- image = Image.open("path/to/image.jpg")
59
- image = transform(image).unsqueeze(0)
60
 
61
- # Perform inference
62
- with torch.no_grad():
63
- output = model(image)
64
- prediction = torch.argmax(output, dim=1).item()
65
- print(f"Predicted DR severity: {prediction}")
66
  ```
67
 
68
  ## License
 
46
  # Load model
47
  model = AutoModel.from_pretrained("your-huggingface-username/model-name")
48
  model.eval()
49
+ ```
50
 
51
+ ### Transformer Application
52
+ ```python
53
  transform = transforms.Compose([
54
+ transforms.Resize((224, 224)), # Resize image to match input size
55
+ transforms.ToTensor(), # Convert image to tensor
56
+ transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]) # Normalize using ImageNet stats
57
  ])
58
+ ```
59
+
60
+ ### Function to preprocess image and get predictions
61
+ ```python
62
+ def predict(image_path):
63
+ # Load and preprocess the input image
64
+ image = Image.open(image_path).convert('RGB') # Ensure RGB format
65
+ input_tensor = transform(image).unsqueeze(0).to(device) # Add batch dimension
66
+
67
+ # Perform inference
68
+ with torch.no_grad():
69
+ outputs = model(input_tensor) # Forward pass
70
+ probabilities = torch.nn.functional.softmax(outputs, dim=1) # Get class probabilities
71
+
72
+ return probabilities.cpu().numpy()[0] # Return probabilities as a NumPy array
73
 
74
+ # Test with an example image
75
+ image_path = "your_image_path" # Replace with your test image path
76
+ class_probs = predict(image_path)
77
 
78
+ # Print results
79
+ print(f"Class probabilities: {class_probs}")
80
+ predicted_class = np.argmax(class_probs) # Get the class with highest probability
81
+ print(f"Predicted class: {predicted_class}")
 
82
  ```
83
 
84
  ## License