Spaces:
Running
Running
Gabolozano
commited on
Commit
•
246f207
1
Parent(s):
d4c3acc
Update app.py
Browse files
app.py
CHANGED
@@ -1,7 +1,6 @@
|
|
1 |
import os
|
2 |
import gradio as gr
|
3 |
-
from transformers import pipeline
|
4 |
-
from transformers import DetrForObjectDetection, DetrConfig
|
5 |
|
6 |
# Initialize the configuration for DetrForObjectDetection
|
7 |
config = DetrConfig.from_pretrained("facebook/detr-resnet-50")
|
@@ -9,8 +8,11 @@ config = DetrConfig.from_pretrained("facebook/detr-resnet-50")
|
|
9 |
# Create the model for object detection using the specified configuration
|
10 |
model = DetrForObjectDetection.from_pretrained("facebook/detr-resnet-50", config=config)
|
11 |
|
12 |
-
# Initialize the
|
13 |
-
|
|
|
|
|
|
|
14 |
|
15 |
def get_pipeline_prediction(pil_image):
|
16 |
# Run the object detection pipeline on the input image
|
@@ -18,7 +20,7 @@ def get_pipeline_prediction(pil_image):
|
|
18 |
|
19 |
# You might need to implement or adjust the rendering function based on the `pipeline_output`
|
20 |
# The `render_results_in_image` function is assumed here to draw bounding boxes and labels on the input image,
|
21 |
-
# but you'll need to define it according to your specific needs.
|
22 |
# For now, the output is directly returned since the question doesn't define `render_results_in_image`.
|
23 |
return pipeline_output
|
24 |
|
|
|
1 |
import os
|
2 |
import gradio as gr
|
3 |
+
from transformers import pipeline, DetrForObjectDetection, DetrConfig, DetrImageProcessor
|
|
|
4 |
|
5 |
# Initialize the configuration for DetrForObjectDetection
|
6 |
config = DetrConfig.from_pretrained("facebook/detr-resnet-50")
|
|
|
8 |
# Create the model for object detection using the specified configuration
|
9 |
model = DetrForObjectDetection.from_pretrained("facebook/detr-resnet-50", config=config)
|
10 |
|
11 |
+
# Initialize the image processor for DETR
|
12 |
+
image_processor = DetrImageProcessor.from_pretrained("facebook/detr-resnet-50")
|
13 |
+
|
14 |
+
# Initialize the object detection pipeline with the model and image processor
|
15 |
+
od_pipe = pipeline(task='object-detection', model=model, image_processor=image_processor)
|
16 |
|
17 |
def get_pipeline_prediction(pil_image):
|
18 |
# Run the object detection pipeline on the input image
|
|
|
20 |
|
21 |
# You might need to implement or adjust the rendering function based on the `pipeline_output`
|
22 |
# The `render_results_in_image` function is assumed here to draw bounding boxes and labels on the input image,
|
23 |
+
# but you'll need to define it according to your specific needs.
|
24 |
# For now, the output is directly returned since the question doesn't define `render_results_in_image`.
|
25 |
return pipeline_output
|
26 |
|