DenisNovac
commited on
Commit
•
d19449b
1
Parent(s):
a1307a9
TorchScript converted model with synset
Browse files- convert.py +18 -0
- converted-to-torchscript.pt +3 -0
- synset.txt +2 -0
convert.py
ADDED
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from transformers import AutoImageProcessor, AutoModelForImageClassification
|
2 |
+
import torch
|
3 |
+
from PIL import Image
|
4 |
+
from transformers import AutoTokenizer
|
5 |
+
|
6 |
+
model_name = "DenisNovac/nsfw_image_detection"
|
7 |
+
|
8 |
+
model = AutoModelForImageClassification.from_pretrained(model_name, torchscript=True, return_dict=False)
|
9 |
+
|
10 |
+
processor = AutoImageProcessor.from_pretrained(model_name)
|
11 |
+
|
12 |
+
image = Image.open("images/hentai.jpg")
|
13 |
+
image_inputs = processor(images=image, return_tensors="pt")
|
14 |
+
|
15 |
+
config = {'forward': [image_inputs['pixel_values']]}
|
16 |
+
converted = torch.jit.trace_module(model, config)
|
17 |
+
|
18 |
+
torch.jit.save(converted, "converted-to-torchscript.pt")
|
converted-to-torchscript.pt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:4f80aebd382cedcb4213eda71479edd851d54ae7f8d5ddf96adc213689dcc412
|
3 |
+
size 343559956
|
synset.txt
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
normal
|
2 |
+
nsfw
|