Enhance clarity in results.to_ function examples. (#18957)
This commit is contained in:
parent
616fd57ea6
commit
df6572a58b
1 changed files with 25 additions and 20 deletions
|
|
@ -494,8 +494,8 @@ class Results(SimpleClass):
|
||||||
Examples:
|
Examples:
|
||||||
>>> results = model("image.jpg")
|
>>> results = model("image.jpg")
|
||||||
>>> for result in results:
|
>>> for result in results:
|
||||||
... im = result.plot()
|
>>> im = result.plot()
|
||||||
... im.show()
|
>>> im.show()
|
||||||
"""
|
"""
|
||||||
assert color_mode in {"instance", "class"}, f"Expected color_mode='instance' or 'class', not {color_mode}."
|
assert color_mode in {"instance", "class"}, f"Expected color_mode='instance' or 'class', not {color_mode}."
|
||||||
if img is None and isinstance(self.orig_img, torch.Tensor):
|
if img is None and isinstance(self.orig_img, torch.Tensor):
|
||||||
|
|
@ -600,7 +600,7 @@ class Results(SimpleClass):
|
||||||
>>> results = model("path/to/image.jpg")
|
>>> results = model("path/to/image.jpg")
|
||||||
>>> results[0].show() # Display the first result
|
>>> results[0].show() # Display the first result
|
||||||
>>> for result in results:
|
>>> for result in results:
|
||||||
... result.show() # Display all results
|
>>> result.show() # Display all results
|
||||||
"""
|
"""
|
||||||
self.plot(show=True, *args, **kwargs)
|
self.plot(show=True, *args, **kwargs)
|
||||||
|
|
||||||
|
|
@ -620,10 +620,10 @@ class Results(SimpleClass):
|
||||||
Examples:
|
Examples:
|
||||||
>>> results = model("path/to/image.jpg")
|
>>> results = model("path/to/image.jpg")
|
||||||
>>> for result in results:
|
>>> for result in results:
|
||||||
... result.save("annotated_image.jpg")
|
>>> result.save("annotated_image.jpg")
|
||||||
>>> # Or with custom plot arguments
|
>>> # Or with custom plot arguments
|
||||||
>>> for result in results:
|
>>> for result in results:
|
||||||
... result.save("annotated_image.jpg", conf=False, line_width=2)
|
>>> result.save("annotated_image.jpg", conf=False, line_width=2)
|
||||||
"""
|
"""
|
||||||
if not filename:
|
if not filename:
|
||||||
filename = f"results_{Path(self.path).name}"
|
filename = f"results_{Path(self.path).name}"
|
||||||
|
|
@ -644,7 +644,7 @@ class Results(SimpleClass):
|
||||||
Examples:
|
Examples:
|
||||||
>>> results = model("path/to/image.jpg")
|
>>> results = model("path/to/image.jpg")
|
||||||
>>> for result in results:
|
>>> for result in results:
|
||||||
... print(result.verbose())
|
>>> print(result.verbose())
|
||||||
2 persons, 1 car, 3 traffic lights,
|
2 persons, 1 car, 3 traffic lights,
|
||||||
dog 0.92, cat 0.78, horse 0.64,
|
dog 0.92, cat 0.78, horse 0.64,
|
||||||
|
|
||||||
|
|
@ -681,7 +681,7 @@ class Results(SimpleClass):
|
||||||
>>> model = YOLO("yolo11n.pt")
|
>>> model = YOLO("yolo11n.pt")
|
||||||
>>> results = model("path/to/image.jpg")
|
>>> results = model("path/to/image.jpg")
|
||||||
>>> for result in results:
|
>>> for result in results:
|
||||||
... result.save_txt("output.txt")
|
>>> result.save_txt("output.txt")
|
||||||
|
|
||||||
Notes:
|
Notes:
|
||||||
- The file will contain one line per detection or classification with the following structure:
|
- The file will contain one line per detection or classification with the following structure:
|
||||||
|
|
@ -740,7 +740,7 @@ class Results(SimpleClass):
|
||||||
Examples:
|
Examples:
|
||||||
>>> results = model("path/to/image.jpg")
|
>>> results = model("path/to/image.jpg")
|
||||||
>>> for result in results:
|
>>> for result in results:
|
||||||
... result.save_crop(save_dir="path/to/crops", file_name="detection")
|
>>> result.save_crop(save_dir="path/to/crops", file_name="detection")
|
||||||
"""
|
"""
|
||||||
if self.probs is not None:
|
if self.probs is not None:
|
||||||
LOGGER.warning("WARNING ⚠️ Classify task do not support `save_crop`.")
|
LOGGER.warning("WARNING ⚠️ Classify task do not support `save_crop`.")
|
||||||
|
|
@ -776,8 +776,9 @@ class Results(SimpleClass):
|
||||||
|
|
||||||
Examples:
|
Examples:
|
||||||
>>> results = model("image.jpg")
|
>>> results = model("image.jpg")
|
||||||
>>> summary = results[0].summary()
|
>>> for result in results:
|
||||||
>>> print(summary)
|
>>> summary = result.summary()
|
||||||
|
>>> print(summary)
|
||||||
"""
|
"""
|
||||||
# Create list of detection dictionaries
|
# Create list of detection dictionaries
|
||||||
results = []
|
results = []
|
||||||
|
|
@ -839,8 +840,9 @@ class Results(SimpleClass):
|
||||||
|
|
||||||
Examples:
|
Examples:
|
||||||
>>> results = model("path/to/image.jpg")
|
>>> results = model("path/to/image.jpg")
|
||||||
>>> df_result = results[0].to_df()
|
>>> for result in results:
|
||||||
>>> print(df_result)
|
>>> df_result = result.to_df()
|
||||||
|
>>> print(df_result)
|
||||||
"""
|
"""
|
||||||
import pandas as pd # scope for faster 'import ultralytics'
|
import pandas as pd # scope for faster 'import ultralytics'
|
||||||
|
|
||||||
|
|
@ -867,8 +869,9 @@ class Results(SimpleClass):
|
||||||
|
|
||||||
Examples:
|
Examples:
|
||||||
>>> results = model("path/to/image.jpg")
|
>>> results = model("path/to/image.jpg")
|
||||||
>>> csv_result = results[0].to_csv()
|
>>> for result in results:
|
||||||
>>> print(csv_result)
|
>>> csv_result = result.to_csv()
|
||||||
|
>>> print(csv_result)
|
||||||
"""
|
"""
|
||||||
return self.to_df(normalize=normalize, decimals=decimals).to_csv(*args, **kwargs)
|
return self.to_df(normalize=normalize, decimals=decimals).to_csv(*args, **kwargs)
|
||||||
|
|
||||||
|
|
@ -892,8 +895,9 @@ class Results(SimpleClass):
|
||||||
|
|
||||||
Examples:
|
Examples:
|
||||||
>>> results = model("path/to/image.jpg")
|
>>> results = model("path/to/image.jpg")
|
||||||
>>> xml_result = results[0].to_xml()
|
>>> for result in results:
|
||||||
>>> print(xml_result)
|
>>> xml_result = result.to_xml()
|
||||||
|
>>> print(xml_result)
|
||||||
"""
|
"""
|
||||||
check_requirements("lxml")
|
check_requirements("lxml")
|
||||||
df = self.to_df(normalize=normalize, decimals=decimals)
|
df = self.to_df(normalize=normalize, decimals=decimals)
|
||||||
|
|
@ -922,8 +926,9 @@ class Results(SimpleClass):
|
||||||
|
|
||||||
Examples:
|
Examples:
|
||||||
>>> results = model("path/to/image.jpg")
|
>>> results = model("path/to/image.jpg")
|
||||||
>>> json_result = results[0].to_json()
|
>>> for result in results:
|
||||||
>>> print(json_result)
|
>>> json_result = result.to_json()
|
||||||
|
>>> print(json_result)
|
||||||
|
|
||||||
Notes:
|
Notes:
|
||||||
- For classification tasks, the JSON will contain class probabilities instead of bounding boxes.
|
- For classification tasks, the JSON will contain class probabilities instead of bounding boxes.
|
||||||
|
|
@ -954,8 +959,8 @@ class Results(SimpleClass):
|
||||||
|
|
||||||
Examples:
|
Examples:
|
||||||
>>> results = model("path/to/image.jpg")
|
>>> results = model("path/to/image.jpg")
|
||||||
>>> results[0].to_sql()
|
>>> for result in results:
|
||||||
>>> print("SQL data written successfully.")
|
>>> result.to_sql()
|
||||||
"""
|
"""
|
||||||
import json
|
import json
|
||||||
import sqlite3
|
import sqlite3
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue