Open lizgzil opened 12 months ago
Great way to include this :)
I could have a look at fp.plot()
to see if the datatype needs conversion or something else. I hope it won't be too confusing having a similarly named function (yolo_to_segments as opposed to yolo_2_segments). I'll get back to this after I've written up docs for v1 interpreter API. Thanks for tagging me in!
new version of the code, note that:
output List[Dict[str, Any]]
with the load_image(image_url)
and overlay_boundaries_plot(visual_image, labels, show=False, plot_label=plot_label)
functions in FloorplanPredictor.plot() and I get the same result with yolo_2_segments. No conversion from pt.Tensor to float needed.List[str]
or List[Image]
. For the case of adapting to the FloorplanPredictor, it just means that the results_obj
value to pass into the below function is results[0]
.from ultralytics.engine.results import Results
from typing import Any, Dict, List
def yolo_Results_to_segments(
results_obj: Results,
) -> List[Dict[str, Any]]:
# Extract the useful properties from Results
xyxy, names, cls, conf = (
results_obj.boxes.xyxy, # Tensor([ i , [xmin, ymin, xmax, ymax] ]) where each 'i' array/ 1D tensor is a result bbox in xyxy format
results_obj.names,
results_obj.boxes.cls,
results_obj.boxes.conf,
)
# Create the output list using list comprehension, each i'th is an array in xyxy format
segments = [
{
"label": names[label.item()],
"points": [
[xyxy[i, 0], xyxy[i, 1]], # xmin, ymin [Tensor, Tensor]
[xyxy[i, 2], xyxy[i, 1]], # xmax, ymin [Tensor, Tensor]
[xyxy[i, 2], xyxy[i, 3]], # xmax, ymax [Tensor, Tensor]
[xyxy[i, 0], xyxy[i, 3]] # xmin, ymax [Tensor, Tensor]
],
"type": "polygon",
"confidence": conf[i],
}
for i, label in enumerate(cls)
]
return segments
For the API @sqr00t found a computational improvement to the
yolo_2_segments
function inmodel_utils.py
by doingrather than:
For the time being changing the code to this lead to an error:
I expect the output needed for the api use case might be slightly different than for the visualising use case. I imagine it's quickly fixed, but since there are still changes happening (and
yolo_2_segments
as it currently stands is also in a currently draft PR #2 ) I will keep this as an issue for now. Also that speed in this area isn't a problem for the time being anyway.