RishiDarkDevil commited on
Commit
9ecb0be
1 Parent(s): e44be29

Add Model Usage

Browse files
Files changed (1) hide show
  1. README.md +43 -0
README.md CHANGED
@@ -1,3 +1,46 @@
1
  ---
2
  license: mit
 
 
 
 
 
 
 
 
 
3
  ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
  license: mit
3
+ datasets:
4
+ - competitions/aiornot
5
+ language:
6
+ - en
7
+ metrics:
8
+ - accuracy
9
+ tags:
10
+ - classification
11
+ - computer vision
12
  ---
13
+
14
+ ## Usage:
15
+ Follow the following code example to use this model.
16
+ ```
17
+ # import libraries
18
+ from transformers import AutoModel, AutoModelForImageClassification
19
+ import torch
20
+ from datasets import load_dataset
21
+
22
+ # load dataset
23
+ dataset = load_dataset("competitions/aiornot")
24
+
25
+ # list of images
26
+ images = dataset["test"][10:20]["image"]
27
+
28
+ # load models
29
+ feature_extractor = AutoModel.from_pretrained(
30
+ "RishiDarkDevil/ai-image-det-resnet152", trust_remote_code=True).to('cuda')
31
+ classifier = AutoModelForImageClassification.from_pretrained(
32
+ "RishiDarkDevil/ai-image-det-resnet152", trust_remote_code=True).to('cuda')
33
+
34
+ # extract features from images
35
+ inputs = feature_extractor(images)
36
+
37
+ # classification using extracted features
38
+ with torch.no_grad():
39
+ logits = classifier(inputs)['logits']
40
+
41
+ # model predicts one of the 2 classes
42
+ predicted_label = logits.argmax(-1)
43
+
44
+ # predictions
45
+ print(predicted_label) # 0 is Not AI, 1 is AI
46
+ ```