Spaces:
Build error
Build error
Commit
·
d647f3e
1
Parent(s):
07b1d72
Added the YOLO Model
Browse files
app.py
CHANGED
@@ -9,7 +9,7 @@ from bulk_bulge_generation import definitions, smooth
|
|
9 |
import fastai
|
10 |
from fastcore.all import *
|
11 |
from fastai.vision.all import *
|
12 |
-
from ultralytics import YOLO
|
13 |
import cv2
|
14 |
|
15 |
def apply_vector_field_transform(image, func, radius, center=(0.5, 0.5), strength=1, edge_smoothness=0.1, center_smoothness=0.20):
|
@@ -277,6 +277,23 @@ learn_fresh = load_learner('model_fresh.pkl')
|
|
277 |
# Loads the YOLO Model
|
278 |
model = YOLO("bulge_yolo_model.pt")
|
279 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
280 |
def transform_image(image, func_choice, randomization_check, radius, center_x, center_y, strength, reverse_gradient=True, spiral_frequency=1):
|
281 |
I = np.asarray(Image.open(image))
|
282 |
|
@@ -414,7 +431,9 @@ def transform_image(image, func_choice, randomization_check, radius, center_x, c
|
|
414 |
|
415 |
result_localization = model.predict(transformed, save=True)
|
416 |
|
417 |
-
|
|
|
|
|
418 |
|
419 |
|
420 |
demo = gr.Interface(
|
@@ -439,6 +458,7 @@ demo = gr.Interface(
|
|
439 |
],
|
440 |
outputs=[
|
441 |
gr.Image(label="Transformed Image"),
|
|
|
442 |
gr.Label(),
|
443 |
gr.Label(),
|
444 |
gr.Image(label="Gradient Vector Field"),
|
|
|
9 |
import fastai
|
10 |
from fastcore.all import *
|
11 |
from fastai.vision.all import *
|
12 |
+
from ultralytics import ASSETS, YOLO
|
13 |
import cv2
|
14 |
|
15 |
def apply_vector_field_transform(image, func, radius, center=(0.5, 0.5), strength=1, edge_smoothness=0.1, center_smoothness=0.20):
|
|
|
277 |
# Loads the YOLO Model
|
278 |
model = YOLO("bulge_yolo_model.pt")
|
279 |
|
280 |
+
def predict_image(img, conf_threshold, iou_threshold):
|
281 |
+
"""Predicts objects in an image using a YOLOv8 model with adjustable confidence and IOU thresholds."""
|
282 |
+
results = model.predict(
|
283 |
+
source=img,
|
284 |
+
conf=conf_threshold,
|
285 |
+
iou=iou_threshold,
|
286 |
+
show_labels=True,
|
287 |
+
show_conf=True,
|
288 |
+
imgsz=640,
|
289 |
+
)
|
290 |
+
|
291 |
+
for r in results:
|
292 |
+
im_array = r.plot()
|
293 |
+
im = Image.fromarray(im_array[..., ::-1])
|
294 |
+
|
295 |
+
return im
|
296 |
+
|
297 |
def transform_image(image, func_choice, randomization_check, radius, center_x, center_y, strength, reverse_gradient=True, spiral_frequency=1):
|
298 |
I = np.asarray(Image.open(image))
|
299 |
|
|
|
431 |
|
432 |
result_localization = model.predict(transformed, save=True)
|
433 |
|
434 |
+
YOLO_image = predict_image(transformed, 0.5, 0.5)
|
435 |
+
|
436 |
+
return transformed, YOLO_image, result_bias_final, result_fresh_final, vector_field, inverse_transformed, inverted_vector_field
|
437 |
|
438 |
|
439 |
demo = gr.Interface(
|
|
|
458 |
],
|
459 |
outputs=[
|
460 |
gr.Image(label="Transformed Image"),
|
461 |
+
gr.Image(label="YOLO Classification"),
|
462 |
gr.Label(),
|
463 |
gr.Label(),
|
464 |
gr.Image(label="Gradient Vector Field"),
|