Spaces:
Runtime error
Runtime error
City
commited on
Commit
·
f7c012d
1
Parent(s):
ea0c985
Add compression detection model
Browse files- demo_class_gradio.py +1 -0
- inference.py +5 -4
demo_class_gradio.py
CHANGED
@@ -8,6 +8,7 @@ TOKEN = os.environ.get("HFS_TOKEN")
|
|
8 |
HFREPO = "City96/AnimeClassifiers"
|
9 |
MODELS = [
|
10 |
"CCAnime-ChromaticAberration-v1.16",
|
|
|
11 |
]
|
12 |
article = """\
|
13 |
# About
|
|
|
8 |
HFREPO = "City96/AnimeClassifiers"
|
9 |
MODELS = [
|
10 |
"CCAnime-ChromaticAberration-v1.16",
|
11 |
+
"CCAnime-Compression-v1.5",
|
12 |
]
|
13 |
article = """\
|
14 |
# About
|
inference.py
CHANGED
@@ -15,7 +15,7 @@ class CityAestheticsPipeline:
|
|
15 |
Resulting object can be called directly with a PIL image as the input
|
16 |
Returns a single float value with the predicted score [0.0;1.0].
|
17 |
"""
|
18 |
-
clip_ver = "openai/clip-vit-large-patch14"
|
19 |
def __init__(self, model_path, device="cpu", clip_dtype=torch.float32):
|
20 |
self.device = device
|
21 |
self.clip_dtype = clip_dtype
|
@@ -90,7 +90,7 @@ class CityClassifierPipeline:
|
|
90 |
Resulting object can be called directly with a PIL image as the input
|
91 |
Returns a single float value with the predicted score [0.0;1.0].
|
92 |
"""
|
93 |
-
clip_ver = "openai/clip-vit-large-patch14"
|
94 |
def __init__(self, model_path, config_path=None, device="cpu", clip_dtype=torch.float32):
|
95 |
self.device = device
|
96 |
self.clip_dtype = clip_dtype
|
@@ -134,10 +134,10 @@ class CityClassifierPipeline:
|
|
134 |
return [pred[:, x] for x in range(pred.shape[1])] # split
|
135 |
|
136 |
def get_clip_emb(self, raw, tiling=False):
|
137 |
-
if tiling and min(raw.size)>
|
138 |
if max(raw.size)>1536:
|
139 |
raw = TF.functional.resize(raw, 1536)
|
140 |
-
raw = TF.functional.five_crop(raw,
|
141 |
img = self.proc(
|
142 |
images = raw,
|
143 |
return_tensors = "pt"
|
@@ -148,6 +148,7 @@ class CityClassifierPipeline:
|
|
148 |
|
149 |
def _init_clip(self):
|
150 |
self.proc = CLIPImageProcessor.from_pretrained(self.clip_ver)
|
|
|
151 |
self.clip = CLIPVisionModelWithProjection.from_pretrained(
|
152 |
self.clip_ver,
|
153 |
device_map = self.device,
|
|
|
15 |
Resulting object can be called directly with a PIL image as the input
|
16 |
Returns a single float value with the predicted score [0.0;1.0].
|
17 |
"""
|
18 |
+
clip_ver = "openai/clip-vit-large-patch14-336"
|
19 |
def __init__(self, model_path, device="cpu", clip_dtype=torch.float32):
|
20 |
self.device = device
|
21 |
self.clip_dtype = clip_dtype
|
|
|
90 |
Resulting object can be called directly with a PIL image as the input
|
91 |
Returns a single float value with the predicted score [0.0;1.0].
|
92 |
"""
|
93 |
+
clip_ver = "openai/clip-vit-large-patch14-336"
|
94 |
def __init__(self, model_path, config_path=None, device="cpu", clip_dtype=torch.float32):
|
95 |
self.device = device
|
96 |
self.clip_dtype = clip_dtype
|
|
|
134 |
return [pred[:, x] for x in range(pred.shape[1])] # split
|
135 |
|
136 |
def get_clip_emb(self, raw, tiling=False):
|
137 |
+
if tiling and min(raw.size) > self.size*2:
|
138 |
if max(raw.size)>1536:
|
139 |
raw = TF.functional.resize(raw, 1536)
|
140 |
+
raw = TF.functional.five_crop(raw, self.size*2)
|
141 |
img = self.proc(
|
142 |
images = raw,
|
143 |
return_tensors = "pt"
|
|
|
148 |
|
149 |
def _init_clip(self):
|
150 |
self.proc = CLIPImageProcessor.from_pretrained(self.clip_ver)
|
151 |
+
self.size = self.proc.size.get("shortest_edge", 256)
|
152 |
self.clip = CLIPVisionModelWithProjection.from_pretrained(
|
153 |
self.clip_ver,
|
154 |
device_map = self.device,
|