Spaces:
Sleeping
Sleeping
Commit
·
aa96f98
1
Parent(s):
af6c368
Update model.py
Browse files
model.py
CHANGED
@@ -35,21 +35,17 @@ def generate_download_signed_url_v4(blob_name):
|
|
35 |
# Allow GET requests using this URL.
|
36 |
method="GET",
|
37 |
)
|
38 |
-
|
39 |
-
# print("Generated GET signed URL:")
|
40 |
-
# print(url)
|
41 |
-
print("You can use this URL with any user agent, for example:")
|
42 |
-
print(f"curl '{url}'")
|
43 |
return url
|
44 |
|
45 |
|
46 |
class Model(LabelStudioMLBase):
|
47 |
-
|
48 |
-
image_processor = AutoImageProcessor.from_pretrained("diegokauer/conditional-detr-coe-int")
|
49 |
-
model = AutoModelForObjectDetection.from_pretrained("diegokauer/conditional-detr-coe-int")
|
50 |
-
# pass
|
51 |
os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = get_credentials()
|
52 |
-
|
|
|
|
|
|
|
|
|
53 |
|
54 |
def predict(self, tasks, **kwargs):
|
55 |
""" This is where inference happens: model returns
|
@@ -68,10 +64,10 @@ class Model(LabelStudioMLBase):
|
|
68 |
original_width, original_height = image.size
|
69 |
with torch.no_grad():
|
70 |
|
71 |
-
inputs = image_processor(images=image, return_tensors="pt")
|
72 |
-
outputs = model(**inputs)
|
73 |
target_sizes = torch.tensor([image.size[::-1]])
|
74 |
-
results = image_processor.post_process_object_detection(outputs, threshold=0.5, target_sizes=target_sizes)[0]
|
75 |
|
76 |
result_list = []
|
77 |
for score, label, box in zip(results['scores'], results['labels'], results['boxes']):
|
|
|
35 |
# Allow GET requests using this URL.
|
36 |
method="GET",
|
37 |
)
|
|
|
|
|
|
|
|
|
|
|
38 |
return url
|
39 |
|
40 |
|
41 |
class Model(LabelStudioMLBase):
|
42 |
+
|
|
|
|
|
|
|
43 |
os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = get_credentials()
|
44 |
+
|
45 |
+
def __init__(self):
|
46 |
+
|
47 |
+
self.image_processor = AutoImageProcessor.from_pretrained("diegokauer/conditional-detr-coe-int")
|
48 |
+
self.model = AutoModelForObjectDetection.from_pretrained("diegokauer/conditional-detr-coe-int")
|
49 |
|
50 |
def predict(self, tasks, **kwargs):
|
51 |
""" This is where inference happens: model returns
|
|
|
64 |
original_width, original_height = image.size
|
65 |
with torch.no_grad():
|
66 |
|
67 |
+
inputs = self.image_processor(images=image, return_tensors="pt")
|
68 |
+
outputs = self.model(**inputs)
|
69 |
target_sizes = torch.tensor([image.size[::-1]])
|
70 |
+
results = self.image_processor.post_process_object_detection(outputs, threshold=0.5, target_sizes=target_sizes)[0]
|
71 |
|
72 |
result_list = []
|
73 |
for score, label, box in zip(results['scores'], results['labels'], results['boxes']):
|