ShihTing commited on
Commit
8d1a112
1 Parent(s): f501b04

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +51 -0
README.md ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # PanJu offset detect by image
2
+ Use fintune from google/vit-base-patch16-224(https://huggingface.co/google/vit-base-patch16-224)
3
+
4
+ ## Dataset
5
+ ```python
6
+ DatasetDict({
7
+ train: Dataset({
8
+ features: ['image', 'label'],
9
+ num_rows: 329
10
+ })
11
+ validation: Dataset({
12
+ features: ['image', 'label'],
13
+ num_rows: 56
14
+ })
15
+ })
16
+
17
+ ```
18
+ 36 Break and 293 Normal in train
19
+ 5 Break and 51 Normal in validation
20
+
21
+
22
+ ## Intended uses
23
+
24
+ ### How to use
25
+
26
+ Here is how to use this model to classify an image of the COCO 2017 dataset into one of the 1,000 ImageNet classes:
27
+
28
+ ```python
29
+ # Load image
30
+ import torch
31
+ from transformers import ViTFeatureExtractor, ViTForImageClassification,AutoModel
32
+ from PIL import Image
33
+ import requests
34
+ url='https://datasets-server.huggingface.co/assets/ShihTing/IsCausewayOffset/--/ShihTing--IsCausewayOffset/validation/0/image/image.jpg'
35
+ image = Image.open(requests.get(url, stream=True).raw)
36
+ # Load model
37
+ from transformers import AutoFeatureExtractor, AutoModelForImageClassification
38
+ device = torch.device('cpu')
39
+ extractor = AutoFeatureExtractor.from_pretrained('ShihTing/PanJuOffset_TwoClass')
40
+ model = AutoModelForImageClassification.from_pretrained('ShihTing/PanJuOffset_TwoClass')
41
+ # Predict
42
+ inputs = extractor(images=image, return_tensors="pt")
43
+ outputs = model(**inputs)
44
+ logits = outputs.logits
45
+ Prob = outputs.logits.softmax(dim=-1).tolist()
46
+ print(Prob)
47
+ # model predicts one of the 1000 ImageNet classes
48
+ predicted_class_idx = logits.argmax(-1).item()
49
+ print("Predicted class:", model.config.id2label[predicted_class_idx])
50
+ ```
51
+