Create README.md
Browse files
    	
        README.md
    ADDED
    
    | @@ -0,0 +1,19 @@ | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | 
|  | |
| 1 | 
            +
            ### How to use
         | 
| 2 | 
            +
            Here is how to use this model in PyTorch:
         | 
| 3 | 
            +
            ```python
         | 
| 4 | 
            +
            from transformers import PerceiverFeatureExtractor, PerceiverForImageClassificationLearned
         | 
| 5 | 
            +
            import requests
         | 
| 6 | 
            +
            from PIL import Image
         | 
| 7 | 
            +
            feature_extractor = PerceiverFeatureExtractor.from_pretrained("addy88/perceiver_image_classifier")
         | 
| 8 | 
            +
            model = PerceiverForImageClassificationLearned.from_pretrained("addy88/perceiver_image_classifier")
         | 
| 9 | 
            +
            url = "http://images.cocodataset.org/val2017/000000039769.jpg"
         | 
| 10 | 
            +
            image = Image.open(requests.get(url, stream=True).raw)
         | 
| 11 | 
            +
            # prepare input
         | 
| 12 | 
            +
            encoding = feature_extractor(image, return_tensors="pt")
         | 
| 13 | 
            +
            inputs = encoding.pixel_values
         | 
| 14 | 
            +
            # forward pass
         | 
| 15 | 
            +
            outputs = model(inputs)
         | 
| 16 | 
            +
            logits = outputs.logits
         | 
| 17 | 
            +
            print("Predicted class:", model.config.id2label[logits.argmax(-1).item()])
         | 
| 18 | 
            +
            >>> should print Predicted class: tabby, tabby cat
         | 
| 19 | 
            +
            ```
         | 
