tribber93 commited on
Commit
b95d011
·
verified ·
1 Parent(s): 6414762

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +9 -14
README.md CHANGED
@@ -23,26 +23,21 @@ The trained model is accessible on Hugging Face Hub at: [tribber93/my-trash-clas
23
 
24
  To use the model for inference, follow these steps:
25
 
26
- 1. Load the pre-trained model from Hugging Face:
27
-
28
  ```python
 
 
 
29
  from transformers import AutoModelForImageClassification, AutoImageProcessor
30
 
 
 
 
31
  model_name = "tribber93/my-trash-classification"
32
  model = AutoModelForImageClassification.from_pretrained(model_name)
33
- image_processor = AutoImageProcessor.from_pretrained(model_name)
34
- ```
35
-
36
- 2. Prepare an image for prediction:
37
-
38
- ```python
39
- from PIL import Image
40
- import torch
41
-
42
- image = Image.open("path_to_image.jpg").convert("RGB")
43
- pixel_values = image_processor(image, return_tensors="pt").pixel_values
44
 
45
- outputs = model(pixel_values)
46
  predictions = torch.argmax(outputs.logits, dim=-1)
47
  print("Predicted class:", model.config.id2label[predictions.item()])
48
  ```
 
23
 
24
  To use the model for inference, follow these steps:
25
 
 
 
26
  ```python
27
+ import torch
28
+ import requests
29
+ from PIL import Image
30
  from transformers import AutoModelForImageClassification, AutoImageProcessor
31
 
32
+ url = 'https://cdn.grid.id/crop/0x0:0x0/700x465/photo/grid/original/127308_kaleng-bekas.jpg'
33
+ image = Image.open(requests.get(url, stream=True).raw)
34
+
35
  model_name = "tribber93/my-trash-classification"
36
  model = AutoModelForImageClassification.from_pretrained(model_name)
37
+ processor = AutoImageProcessor.from_pretrained(model_name)
38
+ inputs = processor(image, return_tensors="pt")
 
 
 
 
 
 
 
 
 
39
 
40
+ outputs = model(**inputs)
41
  predictions = torch.argmax(outputs.logits, dim=-1)
42
  print("Predicted class:", model.config.id2label[predictions.item()])
43
  ```